Skip to content
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

How to connect more than two devices at the same time? #207

Open
lp1293714059 opened this issue Aug 31, 2022 · 3 comments
Open

How to connect more than two devices at the same time? #207

lp1293714059 opened this issue Aug 31, 2022 · 3 comments

Comments

@lp1293714059
Copy link

Creating two AdbDeviceUsb objects with different SNs will report an error:

from adb_shell.adb_device import AdbDeviceTcp, AdbDeviceUsb
from adb_shell.auth.sign_pythonrsa import PythonRSASigner

# Load the public and private keys
adbkey = 'adbkey'
with open(adbkey) as f:
    priv = f.read()
with open(adbkey + '.pub') as f:
     pub = f.read()
signer = PythonRSASigner(pub, priv)

# Connect via USB (package must be installed via `pip install adb-shell[usb])`
device2 = AdbDeviceUsb(serial="230YV16C83002B")
device2.connect(rsa_keys=[signer], auth_timeout_s=0.1)

device3 = AdbDeviceUsb(serial="230YT16C83002G")
device3.connect(rsa_keys=[signer], auth_timeout_s=0.1)
Traceback (most recent call last):
  File "testDUTS.py", line 16, in <module>
    device3 = AdbDeviceUsb(serial="230YT16C83002G")
  File "C:\python37\lib\site-packages\adb_shell\adb_device.py", line 1552, in __init__
    transport = UsbTransport.find_adb(serial, port_path, default_transport_timeout_s)
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 628, in find_adb
    default_transport_timeout_s=default_transport_timeout_s
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 512, in _find
    return cls._find_first(setting_matcher, device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s)
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 601, in _find_first
    return next(cls._find_devices(setting_matcher, device_matcher=device_matcher, usb_info=usb_info, default_transport_timeout_s=default_transport_timeout_s))
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 569, in _find_devices
    if device_matcher is None or device_matcher(transport):
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 475, in <lambda>
    return lambda device: device.serial_number == serial
  File "C:\python37\lib\site-packages\adb_shell\transport\usb_transport.py", line 415, in serial_number
    return self._device.getSerialNumber()
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 2019, in getSerialNumber
    return self.open().getSerialNumber()
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 2055, in open
    mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 127, in mayRaiseUSBError
    __raiseUSBError(value)
  File "C:\python37\lib\site-packages\usb1\__init__.py", line 119, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]
@lp1293714059
Copy link
Author

lp1293714059 commented Aug 31, 2022

I found that there is no error with this code order, Is it okay to execute code in a certain order?:

device3 = AdbDeviceUsb(serial="230YT16C83002G")  # COM3
device3.connect(rsa_keys=[signer], auth_timeout_s=0.1)

device2 = AdbDeviceUsb(serial="230YV16C83002B")  # COM5
device2.connect(rsa_keys=[signer], auth_timeout_s=0.1)

I tried to connect three android devices at the same time, I found that it can only be executed in the following code sequence without error:

device3 = AdbDeviceUsb(serial="230YT16C83002G")  # COM3
device3.connect(rsa_keys=[signer], auth_timeout_s=0.1)

device4 = AdbDeviceUsb(serial="230YV41D4W001J")  # COM17
device4.connect(rsa_keys=[signer], auth_timeout_s=0.1)

device2 = AdbDeviceUsb(serial="230YV16C83002B")  # COM5
device2.connect(rsa_keys=[signer], auth_timeout_s=0.1)

From the above phenomenon, it seems that there is no correlation with the order of COM ports. I am very confused. @JeffLIrion Could you help me solve this problem?o(╥﹏╥)o

@X123465
Copy link

X123465 commented Feb 9, 2023

Bro, have you solved this problem?

@lp1293714059
Copy link
Author

Bro, have you solved this problem?

I havent solved it. But I found that the code can run normally like this:

device3 = AdbDeviceUsb(serial="230YT16C83002G")  # COM3
device4 = AdbDeviceUsb(serial="230YV41D4W001J")  # COM17
device2 = AdbDeviceUsb(serial="230YV16C83002B")  # COM5

device3.connect(rsa_keys=[signer], auth_timeout_s=0.1)
device4.connect(rsa_keys=[signer], auth_timeout_s=0.1)
device2.connect(rsa_keys=[signer], auth_timeout_s=0.1)

It seems that all AdbDeviceUsb objects need to be created first, and then connect them, so that no error will be reported.

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

No branches or pull requests

2 participants