Skip to content

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

Open
dilyanpalauzov wants to merge 1 commit intoned-kelly:masterfrom
dilyanpalauzov:multithreading_locks
Open

inverter.cpp: avoid mess with simultaneous read/write operations#77
dilyanpalauzov wants to merge 1 commit intoned-kelly:masterfrom
dilyanpalauzov:multithreading_locks

Conversation

@dilyanpalauzov
Copy link
Copy Markdown
Contributor

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.

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.
dilyanpalauzov added a commit to dilyanpalauzov/docker-voltronic-homeassistant that referenced this pull request Apr 9, 2022
ned-kelly#77

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.
@ned-kelly
Copy link
Copy Markdown
Owner

HI @dilyanpalauzov is there any chance you could add all your fixes and improvements as one PR and i'll approve it.

Unfortunately I don't have an inverter to test on anymore (Am getting another one soon - the last one died (again)) so if anyone else is also able to test that would be appreciated.

Cheers,

dilyanpalauzov added a commit to dilyanpalauzov/docker-voltronic-homeassistant that referenced this pull request Aug 25, 2022
ned-kelly#77

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.
@dilyanpalauzov dilyanpalauzov mentioned this pull request Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants