[python-win32] Python - connexion to serial port
Schoeni, Yann
Yann.Schoeni at moutier.ch
Fri Jan 12 05:00:02 EST 2018
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.schoeni at moutier.ch
-----Message d'origine-----
De : python-win32 [mailto:python-win32-bounces+yann.schoeni=moutier.ch at python.org] De la part de Dennis Lee Bieber
Envoyé : jeudi, 11 janvier 2018 17:37
À : python-win32 at python.org
Objet : Re: [python-win32] Python - connexion to serial port
On Thu, 11 Jan 2018 15:12:33 +0000, "Schoeni, Yann"
<Yann.Schoeni at moutier.ch> 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
wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/
_______________________________________________
python-win32 mailing list
python-win32 at python.org
https://mail.python.org/mailman/listinfo/python-win32
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20180112/d3304c7b/attachment.html>
More information about the python-win32
mailing list