def scan(self): usb_device_list = usb.get_usb_device_list() res = [] self.usb_device_name_list = [device.getDeviceName() for device in usb_device_list] usb_device_dict = { device.getDeviceName():[ # Device name device.getVendorId(), # Vendor ID device.getManufacturerName(), # Manufacturer name device.getProductId(), # Product ID device.getProductName() # Product name ] for device in usb_device_list } res = self.usb_device_name_list print(res) self.scanned.set() return res
def list_arduino_ports(): """list serial ports where an arduino is connected""" arduino_list = [] if platform == 'android': usb_device_list = usb.get_usb_device_list() for device in usb_device_list: if device.getVendorId( ) == 9025: # 9025 is the vid of 'Arduino LLC' arduino_list.append((device.getDeviceName(), device)) if platform in ['win', 'linux']: l = list_ports.comports() for item in l: if item.vid == 9025: # 9025 is the vid of 'Arduino LLC' arduino_list.append(item.device) Logger.debug("Serial: Arduino found {}".format(str(arduino_list))) return 115200, '\n', arduino_list # return baudrate and list
def on_btn_scan_release(self): self.uiDict['box_list'].clear_widgets() self.device_name_list = [] if platform == 'android': usb_device_list = usb.get_usb_device_list() self.device_name_list = [ device.getDeviceName() for device in usb_device_list ] else: usb_device_list = list_ports.comports() self.device_name_list = [port.device for port in usb_device_list] for device_name in self.device_name_list: btnText = device_name button = Button(text=btnText, size_hint_y=None, height='100dp') button.bind(on_release=self.on_btn_device_release) self.uiDict['box_list'].add_widget(button)
def _find_device_port(self): """Look in the list of serial ports, one that corresponds to CH340 or XXX that Arduino boards typically use. :return: True when success. :rtype: bool """ if OS_ANDROID: ports = usb.get_usb_device_list() port = ports[0].getDeviceName() return port else: ports = serial.tools.list_ports.comports() for port in ports: if ("VID:PID=1A86:7523" in port.hwid) or ("VID:PID=2341:0043" in port.hwid): return port.device return ""
def scan_usb_devices(self, dt): self.ids.device_list.clearAll() device_node_list = [] r = lambda x: x if x is not None else '' if platform == 'android': usb_device_list = usb.get_usb_device_list() device_node_list = [(device.getDeviceName(), r(device.getProductName()) + "(vid=" + str(device.getVendorId()) + ",pid=" + str(device.getProductId()) + ")") for device in usb_device_list] else: usb_device_list = list_ports.comports() device_node_list = [ (device.device, r(device.product) + "(vid=" + str(device.vid) + ",pid=" + str(device.pid) + ")") for device in usb_device_list ] if len(device_node_list) > 0: for device in device_node_list: self.ids.device_list.append_item(device) Clock.schedule_once(self.set_first_item_as_default, 1 / 10)
# When this script is run for the first time, it might prompt you for # permission. Accept the permission and run this script again, then it should # send the data as expected. # Kivy is needed for pyjnius behind the scene. import kivy from usb4a import usb from usbserial4a import serial4a from pprint import pprint usb_device_list = usb.get_usb_device_list() usb_device_name_list = [device.getDeviceName() for device in usb_device_list] usb_device_dict = { device.getDeviceName(): [ # Device name device.getVendorId(), # Vendor ID device.getManufacturerName(), # Manufacturer name device.getProductId(), # Product ID device.getProductName() # Product name ] for device in usb_device_list } pprint(usb_device_dict) if usb_device_list: serial_port = serial4a.get_serial_port( usb_device_list[0].getDeviceName(), 9600, # Baudrate 8, # Number of data bits(5, 6, 7 or 8) 'N', # Parity('N', 'E', 'O', 'M' or 'S') 1) # Number of stop bits(1, 1.5 or 2) if serial_port and serial_port.is_open:
def get_serial_ports_list(): usb_device_list = usb.get_usb_device_list() return [device.getDeviceName() for device in usb_device_list]
def get_usb_devices(self): try: self.usb_device = usb.get_usb_device_list()[0] except NameError: print("Device not found!")
def get_usb_devices(self): self.usb_device = usb.get_usb_device_list()[0]