manio / skymax-demo

https://skyboo.net/2017/03/monitoring-voltronic-power-axpert-mex-inverter-under-linux/
GNU General Public License v2.0
51 stars 29 forks source link

inverter.cpp: avoid mess with simultaneous read/write operations #15

Closed dilyanpalauzov closed 2 years ago

dilyanpalauzov commented 2 years ago

When many inverter_poller at the same time send commands, the result is undefined.

This locks exclusively the configuration file, while the process is running, so that simultaneous instances have to wait until the file is released.

For some reason locking the device /dev/hidraw0 does not work for me, I get sometimes the output from previous runs. I suspect that when cInverter::query() does exceed the 2s timeout, it quits, and leaves the response of its commands on the wire. For fd = /dev/hidraw0: tcflush(fd, TCOFLUSH); has no effect.

As a matter of fact, on my system I have increased the timeout in cInverter::query() to 15s and now it does always work correctly.

Also the program, when called with -1, could exit, while the thread is receiving data, this leaves the next invocation with some ready-data, which it is not expecting.