Re: [python-win32] Python - connexion to serial port
Schoeni, Yann wrote: > > > « is the Python script persistent (is it running continuously in the > background) or launched for each transaction? » > > > > - Currently, the script is launched for each transaction. As I > understand your proposition, when the web page is open, > > an ajax request should call a python script which open a thread > between the machine and the serial peripheral, right ? > I'm still not clear what problems you are seeing with the open/send/close paradigm. What leads you to make a change? The open/send/close model is usually easier to handle, because the process starts with a clean slate every time. Once you go to a long-running process, you have more things to keep track of. Dennis is not necessarily proposing a new thread. Consider, for example, a server application using one of the frameworks, like Flask or CherryPy or Django. Such an application gets launched once, and sits idle waiting for to send it things to do. When it gets a request (either from a socket or routed from Apache), it reads input, takes action, sends output, then waits for more things to do. Dennis' proposal is the same. Have a Python script running continuously. When an Ajax request comes in (either from a socket or from Apache), you communicate with the serial port and send your response. The serial port can remain open, because the application does not close. But I'm not convinced that complexity is needed. The open/send/close model should work just fine. > - Even if I find a way to open a thread with the serial port or > to keep it open with a loop, is it possible to send it orders ? Why wouldn't it? -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Python - connexion to serial port
> On Jan 11, 2018, at 11:36 AM, Dennis Lee Bieberwrote: > > On Thu, 11 Jan 2018 15:12:33 +, "Schoeni, Yann" > declaimed the following: > >> I've a web application which needs to send data to a serial port. The >> webserver uses ajax to send data to a python script. >> >> The Python script uses the serial module to open, send data, and close the >> serial port. >> >> Is there a way to keep the serial port open ? >> >> Because for now, I open/close it between each transaction and I need to be >> 100% sure the data package will be send .. which is not the case with my >> actual python script. I'd add one observation: while you can be reasonably sure that data is sent if you ask the serial port to send it, that does NOT mean it will be received. I suspect what is actually needed is a guarantee that the data is received. A serial port does not offer that guarantee. If the hardware is clean, it only offers a high probability. If you want guarantees, you need a data checking and acknowledgement protocol, like DDCMP or TCP or DECnet. paul ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Python - connexion to serial port
Hey, « is the Python script persistent (is it running continuously in the background) or launched for each transaction? » - Currently, the script is launched for each transaction. As I understand your proposition, when the web page is open, an ajax request should call a python script which open a thread between the machine and the serial peripheral, right ? - is it hard to code this kind of mechanism ? To be honest I've never worked with thread. - Even if I find a way to open a thread with the serial port or to keep it open with a loop, is it possible to send it orders ? - Is there someone who has already experience that kind of situation ? Thank you for your answer. Best wishes Yann Schoeni Municipalité de Moutier Apprenti informaticien Tél. +41 (0)32 494 11 69 Mob. +41 (0)79 827 30 86 E-mail yann.scho...@moutier.ch -Message d'origine- De : python-win32 [mailto:python-win32-bounces+yann.schoeni=moutier...@python.org] De la part de Dennis Lee Bieber Envoyé : jeudi, 11 janvier 2018 17:37 À : python-win32@python.org Objet : Re: [python-win32] Python - connexion to serial port On Thu, 11 Jan 2018 15:12:33 +, "Schoeni, Yann"declaimed the following: >I've a web application which needs to send data to a serial port. The >webserver uses ajax to send data to a python script. > >The Python script uses the serial module to open, send data, and close the >serial port. > >Is there a way to keep the serial port open ? > >Because for now, I open/close it between each transaction and I need to be >100% sure the data package will be send .. which is not the case with my >actual python script. > First question: is the Python script persistent (is it running continuously in the background) or launched for each transaction? For the former (continuous background) why can't you just open the port at the start of the process and leave it open; looping around just the transaction processing. If the latter -- not really, as even if you didn't close the port, the script shutdown will. You would have to create a separate long-term process (not thread, as the thread would have to exit to let the Python script terminate in this scenario). Your Python script would have to transfer the data to be written to the long-term process and let it do the serial port handling. I'm not certain how you'd handle the transfer... All the IPC examples in the multiprocessing library are predicated upon one Python script starting the other process(es) and passing identifiers for the IPC channels (queue, pipes) to the subprocess. Perhaps by having the long-term process create a multiprocessing.manager instance configured for "remote connection" (even if the connection is localhost for both ends), and which the transaction script then attaches. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32