-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force restart device on serial error. #274
base: main
Are you sure you want to change the base?
Conversation
With this commit, when the devices stops read/write will clean the queue, reset the device with USB Command, and send "SIGTERM" signal to himself, to stop the daemon. In linux, with "Restart=always" in service file, will restart the service, fixing some read/write problem.
Hi @mathoudebine ! I replace your code in Read/Write, if some exceptions occours, calls "usb_reset" from usb.core, reset the device and stop the service. |
self.openSerial() | ||
self.lcd_serial.write(line) | ||
logger.warning("(WriteLine) error, reseting device.") | ||
self.reset_by_usb() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a shame to always reset USB and stop the program, when in some cases just the closeSerial/openSerial/write is enough to keep the program running (people have confirmed this in #269)
Maybe the closeSerial/openSerial/write can be kept, and then only on exception the USB is reset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good question... In case of desktop suspend/resume, only close and reopen the serial, don't work in 5 pol version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, the official app on windows, send reset USB in case of errors in serial. It's try to open serial 2 times, if don't work, it's send the reset. I checked this behavior with Wireshark in USB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 5 pol version its very strict to send images, updates, if the order is not following, it's doesn't work.
For me, the correct is to stop all threads, reset USB and start again, but it's a massive change to the code, stop the program has less work to do, because the systemd cares about restart it.
library/lcd/lcd_comm_rev_a.py
Outdated
@@ -41,6 +41,8 @@ def __init__(self, com_port: str = "AUTO", display_width: int = 320, display_hei | |||
update_queue: queue.Queue = None): | |||
LcdComm.__init__(self, com_port, display_width, display_height, update_queue) | |||
self.openSerial() | |||
self.idVendor = 0x1a86 | |||
self.idProduct = 0x5722 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idVendor and idProduct may vary, I have seen at least 2 different values for Turing smart screens. It would be better to read them directly from the device after opening serial (can be done in openSerial()
for all devices)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, ! Good point, there is a variable holding this values in serial ? In don't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not in Serial, but it can be retrieved from COM ports list:
from serial.tools.list_ports import comports
[...]
for com_port in comports():
if com_port.device == self.com_port:
self.idVendor = com_port.vid
self.idProduct = com_port.pid
break
It can be added in lcd_comm.openSerial() after COM port discovery
https://pyserial.readthedocs.io/en/latest/tools.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great ! I will replace that part.
Hi @mathoudebine , i Find some solution about suspend/resume, building a "sleep" entry service to systemd. About the "force reset", maybe we can change it to do after 2 or 3 times that the reconnect fails. Ah, i think its good to , add a "write_timeout" to Serial. What you think ? |
Add sleep service to hook suspend/resume and restart the service.
With this commit, when the devices stops read/write will clean the queue, reset the device with USB Command, and send "SIGTERM" signal to himself, to stop the daemon.
In linux, with "Restart=always" in service file, will restart the service, fixing some read/write problem.
Please, someone can check if in windows its work ? (i think its work !)