FilipDominec/rp2daq

Rewrite port handler to support software-controlled disconnect & reconnect

FilipDominec opened this issue · 0 comments

Double initialization of one device must be blocked.

The 2nd call somehow manages to connect to already connected device, but the identify callback
gets redirected to the first Rp2daq object:

In [2]: rp2daq.Rp2daq()                                                                                                                                       
2024-04-06 11:54:19,091 (MainThread) connected to rp2daq device with manufacturer ID = E66138935F6F8E28
Out[2]: <rp2daq.Rp2daq at 0x7f8dfee52c70>

In [3]: rp2daq.Rp2daq()                                                                                                                                       
2024-04-06 11:54:23,229 (Thread-273) Warning: Got callback that was not asked for
		Debug info: {'report_code': 0, '_data_count': 30, '_data_bitwidth': 8, 'data': b'rp2daq_231005_E66138935F6F8E28'}
2024-04-06 11:54:23,373 (MainThread)    port open, but device does not identify itself as rp2daq: b''
2024-04-06 11:54:23,374 (MainThread) Error: could not find any matching rp2daq device

So on line "[3]" we should have detected the device was not available, and reported an error instead.

Related to this: the port handler process must stop once we have sw-disconnect, then don't report hw disconnect and allow for clear reconnect.

In [4]: rp.quit()                                                                                                                                             
 In [5]: 2024-04-05 11:16:13,790 (MainThread) Device disconnected, check your cabling or possible short-circuits  

Also related: rp.quit() should release COM port on Win10, so that one can run it again.

And if there is a long command (like synchronous stepper_move) when the device gets physically disconnected, it hangs forever - because it ignores the disconnect event, and waits for the report over USB which never comes.

And when a device is still actively reporting some data (infinite ADC, gpio edge events etc.) and a script is re-started, it randomly won't initialize, because initialize immediately expects a specific short report. Maybe the device should be somehow reserved to stop any other reports (?), then port flushed, then called the init.