Open baryluk opened 1 year ago
which multimeter it has?
@baryluk I am witnessing the same behaviour with a FNIRSI FNB58.
Could you explain how the data that is written to the device during setup and between readings works?
E.g., ep_out.write(b"\xaa\x81" + b"\x00" * 61 + b"\x8e")
Perhaps the device needs a specific sequence to exit cleanly?
@luismeruje Yes, I believe that one needs to send some sequence (at possibly a specific time), before stopping connection. My guess is that device otherwise will fill up some UART FIFOs and possibly enter infinite loop trying to send more data, but FIFO is full, and will not be smaller.
When I looked at USB packet captures few months ago, I was not able to figure it out quickly (I spent maybe 20 minutes on this), so just ignored. But it would be nice to fix it.
I have created a pull request which does some impromevements to code structure and also to the stability of the tool. I've added exception handling when a Keyboard Interrupt occurs, so that readings are exhausted before exiting. While this does not solve the problem entirely it seems to help a lot.
This is now mostly fixed. Big thanks to Luis.
It still sporadically locks, despite draining the descriptors and waiting for the timeout.
It appears that it now locks on initialization sometimes.
That is draining buffers out on exit look good, but something else is happening.
So keeping this issue open.
So it appears, that if I remove these two lines in the code:
dev.reset()
dev.set_configuration()
together with thew new draining code on Ctrl-C, it is quite reliable. Was not able to hang it yet.
All this reset
and set_configuration
was a guess work when I initially wrote this code, probably following some tutorials, so maybe it is not needed.
Also reset()
on FNB58 is quite annoying, because it causes some issues with the storage device that the power meter also exposes. So maybe there is actually no need to do it.
Once I am happy with this, I think what I will make it not do reset()
by default, and only do it if --reset
command line argument is passed.
Having the dev.reset()
and dev.set_configuration()
lines removed greatly improves the reliability, but it still not fully consistent. After a few runs (with ^C
in between them), on the 5th or 6th run, it freezes my FNB58
and I get the timeout error again. Nothing resolves this except a reboot of the FNB58
.
I just add time.sleep(0.08) in front of ep_in.read in while loop, FNB58 works well!
ex) while not stop: try: time.sleep(0.08) data = ep_in.read(size_or_buffer=64, timeout=5000)
Killing the logger, might leave the meter in a state, where it does not allow to restart the logger.
Sometimes, second or third run, also makes UI (screen and controls) on the meter freeze.
Below is in FNB58, firmware 0.40