I am working on the library usbserial4a and there is an unpractical behaviour regarding the usb permission granting process.
I am using Pydroid3. Here is an excerpt of the code of the example usbserial4a_ui_example.py:
def on_btn_device_release(self, btn):
device_name = btn.text
if platform == 'android':
device = usb.get_usb_device(device_name)
if not device:
raise SerialException(
"Device {} not present!".format(device_name)
)
if not usb.has_usb_permission(device):
usb.request_usb_permission(device)
return
self.serial_port = serial4a.get_serial_port(
device_name,
9600,
8,
'N',
1,
timeout=1
)
else:
self.serial_port = Serial(
device_name,
9600,
8,
'N',
1,
timeout=1
)
if self.serial_port.is_open and not self.read_thread:
self.read_thread = threading.Thread(target = self.read_msg_thread)
self.read_thread.start()
self.uiDict['sm'].current = 'screen_test'
I have highlighted two lines relative to the permission granting.
The first time the application finds the serial port, it pops a box requesting the permission to access the usb. I click OK, and the box closes, but the return statement stops the operation.
I tried to remove the return, but then the application does not display the incoming serial traffic as it should do.
I must stop the application using the back arrow, then press the RUN arrow again, the app starts, does not ask for the permission, and correctly display the incoming traffic.
So my question is: why, once the permission is granted, is not the usb serial device ready for operation?