Periodic serial port acquisition
Brought to you by:
cliechti
Hello,
I did not find any forum to discuss this great module, so let's try here.
I am using this module to monitor my electricity production and consumption.
I capture data coming from my meter every 10 minutes.
What is the best practice:
- open, read then close every 10 minutes ?
- open at the beginning of my daemon then simply read and let the port open ?
For the moment, I put my code in a scheduler task that open, read then close.
Thanks for your advices and congratulation for this module!
Fabrice
that's tricky. there are drivers on some OS that may get into trouble after a number of open/close operations while others may work better by opening and closing the port...
generally, leaving the port open should work well. In case you want to handle cases where the serial port may fail (e.g. USB-serial adapters that get un- and re-plugged), reopening the port after an SerialException may be a good solution.
Apart from the port handling itself you may need to make the same considerations also for the application layer. Do you need to initialize the device? is such an initialization needed every time the port open/closes or also after a timeout? maybe it's only needed after a power outage?