def fixture_patch_comports(mocker): comport = "COM1" dummy_port_info = ListPortInfo("") dummy_port_info.vid = STM_VID dummy_port_info.name = comport dummy_port_info.description = f"Device ({comport})" mocked_comports = mocker.patch.object( mc_comm.list_ports, "comports", autospec=True, return_value=[dummy_port_info], ) yield comport, dummy_port_info.description, mocked_comports
def list_serial_ports(cls): plat = sys.platform.lower() if os.name == 'posix' and plat[:6] == 'darwin': from serial.tools.list_ports_osx import GetIOServicesByType, GetParentDeviceByType, get_string_property from mac_bt import get_bytes_property, IOBluetooth services = GetIOServicesByType('IOSerialBSDClient') ports = [] bt_devices = IOBluetooth.IOBluetoothDevice.pairedDevices() for service in services: tty = get_string_property(service, "IODialinDevice") bt_device = GetParentDeviceByType(service, "IOBluetoothSerialClient") dev_name = tty if bt_device is not None: address_bytes = get_bytes_property(bt_device, "BTAddress") if address_bytes is not None: address = '-'.join(list('%02.x' % b for b in address_bytes)) for dev in bt_devices: if not address.startswith(dev.addressString()): continue disp_name = dev.getDisplayName() name = dev.getName() if disp_name is not None: dev_name = '{0} - {1} ({2})'.format(disp_name, name, tty) else: dev_name = '{0} ({1})'.format(name, tty) print('Device:', tty, 'Address:', address) print('Name:', dev_name) info = ListPortInfo(tty) info.name = dev_name ports.append(info) break return ports else: return list_comports()