def __asyc_detect_new_device_handle(self, device_name): self.info.has_firmware = False self.info.board_id = None self.info.board_name = device_name available_ports = QSerialPortInfo.availablePorts() def match(pvid, ids): for valid in ids: if pvid == valid: self.info.board_id = str(valid) return True return False for port in available_ports: pvid = ( port.vendorIdentifier(), port.productIdentifier() ) if match(pvid, self.info.board_normal): self.invoke.in_bootload_mode = False print('detect a normal mode borad') break if match(pvid, self.info.board_boot): self.invoke.in_bootload_mode = True print('detect a bootload mode borad') break self.invoke.detected = True
def _serial_scan_btn(self): info_list = QSerialPortInfo() serial_list = info_list.availablePorts() self._serial_ports = [port.portName() for port in serial_list] #print(self._serial_ports[0]) self._widget.comboBox.clear() self._widget.comboBox.addItems(self._serial_ports)
def main(): import sys app = QApplication(sys.argv) layout = QVBoxLayout() infos = QSerialPortInfo.availablePorts() for info in infos: s = ( f"Port: {info.portName()}", f"Location: {info.systemLocation()}", f"Description: {info.description()}", f"Manufacturer: {info.manufacturer()}", f"Serial number: {info.serialNumber()}", "Vendor Identifier: " + f"{info.vendorIdentifier():x}" if info.hasVendorIdentifier() else "", "Product Identifier: " + f"{info.productIdentifier():x}" if info.hasProductIdentifier() else "", ) label = QLabel("\n".join(s)) layout.addWidget(label) workPage = QWidget() workPage.setLayout(layout) area = QScrollArea() area.setWindowTitle("Info about all available serial ports.") area.setWidget(workPage) area.show() sys.exit(app.exec_())
def __init__(self, parent=None): super(SelectSerialportDialog, self).__init__(parent) self.setWindowModality(QtCore.Qt.ApplicationModal) self.setWindowTitle("Select a Port") self.resize(800, 200) self.portsList = QtWidgets.QTreeWidget() openButton = QtWidgets.QPushButton("Open") openButton.clicked.connect(self.openPort) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.portsList) layout.addWidget(openButton) self.setLayout(layout) tableHeader = ["Name", "Alias", "Description", "Mfg", "Serial#", "Location", "VendorID", "ProductID"] self.portsList.setHeaderLabels(tableHeader) for info in QSerialPortInfo.availablePorts(): list = [] description = info.description() manufacturer = info.manufacturer() serialNumber = info.serialNumber() list.append(info.portName()) list.append(self.serialPortAlias(info)) list.append(self.naIfEmpty(description)) list.append(self.naIfEmpty(manufacturer)) list.append(self.naIfEmpty(serialNumber)) list.append(info.systemLocation()) list.append(self.naIfEmptyHex(info.vendorIdentifier())) list.append(self.naIfEmptyHex(info.productIdentifier())) self.portsList.addTopLevelItem(QtWidgets.QTreeWidgetItem(None, list)) for i in range(0, len(tableHeader)): self.portsList.resizeColumnToContents(i)
def on_respiration_monitor_button_pressed(self): arduino = self.dependencies.arduino # DEBUG FFT # self.fft_timer = QTimer() # self.fft_timer.timeout.connect(self.debug_fft) # self.random_time = 0 # self.fft_timer.start(50) if arduino.is_open(): arduino.close() self.arduino_status_label.setText("Arduino Off") arduino.newDataReceived.disconnect(self.temp_func) arduino.stop() else: ports = QSerialPortInfo.availablePorts() for port in ports: if "Arduino" in port.description(): self.respiration_widget.reset() arduino.port = port.portName() arduino.open() self.arduino_status_label.setText("Arduino On ({})".format(port.portName())) self.dependencies.arduino.newDataReceived.connect(self.temp_func) self.dependencies.arduino.start() break
def find_device(self, with_logging=True): """ Returns the port and serial number for the first MicroPython-ish device found connected to the host computer. If no device is found, returns the tuple (None, None). """ available_ports = QSerialPortInfo.availablePorts() for port in available_ports: pid = port.productIdentifier() vid = port.vendorIdentifier() # Look for the port VID & PID in the list of know board IDs if (vid, pid) in self.valid_boards or \ (vid, None) in self.valid_boards: port_name = port.portName() serial_number = port.serialNumber() if with_logging: logger.info('Found device on port: {}'.format(port_name)) logger.info('Serial number: {}'.format(serial_number)) return (self.port_path(port_name), serial_number) if with_logging: logger.warning('Could not find device.') logger.debug('Available ports:') logger.debug([ 'PID:0x{:04x} VID:0x{:04x} PORT:{}'.format( p.productIdentifier(), p.vendorIdentifier(), p.portName()) for p in available_ports ]) return (None, None)
def find_devices(self, with_logging=True): """ Returns the port and serial number, and name for the first MicroPython-ish device found connected to the host computer. If no device is found, returns the tuple (None, None, None). """ available_ports = QSerialPortInfo.availablePorts() devices = [] for port in available_ports: device = self.compatible_board(port) if device: # On OS X devices show up with two different port # numbers (/dev/tty.usbserial-xxx and # /dev/cu.usbserial-xxx) we only want to display the # ones on ports names /dev/cu.usbserial-xxx to users if sys.platform == "darwin" and device.port[:7] != "/dev/cu": continue if with_logging: logger.info("Found device on port: {}".format(device.port)) logger.info("Serial number: {}".format( device.serial_number)) if device.board_name: logger.info("Board type: {}".format(device.board_name)) devices.append(device) if not devices and with_logging: logger.warning("Could not find device.") logger.debug("Available ports:") logger.debug([ "PID:0x{:04x} VID:0x{:04x} PORT:{}".format( p.productIdentifier(), p.vendorIdentifier(), p.portName(), ) for p in available_ports ]) return devices
def findPorts(self): port_list = QSerialPortInfo.availablePorts() port_list_names = [] self.PortSelector.clear() for port in port_list: port_list_names.append(port.portName()) self.PortSelector.addItems(port_list_names)
def main(): import sys app = QCoreApplication(sys.argv) f = QFile() f.open(sys.stdout.fileno(), QIODevice.WriteOnly) out = QTextStream(f) serialPortInfos = QSerialPortInfo.availablePorts() out << "Total number of ports available: " << len(serialPortInfos) << "\n" blankString = "N/A" description = "" manufacturer = "" serialNumber = "" for serialPortInfo in serialPortInfos: description = serialPortInfo.description() manufacturer = serialPortInfo.manufacturer() serialNumber = serialPortInfo.serialNumber() out << "\nPort: " << serialPortInfo.portName( ) << "\nLocation: " << serialPortInfo.systemLocation( ) << "\nDescription: " << ( description if description else blankString) << "\nManufacturer: " << ( manufacturer if manufacturer else blankString ) << "\nSerial number: " << ( serialNumber if serialNumber else blankString ) << "\nVendor Identifier: " << ( QByteArray.number(serialPortInfo.vendorIdentifier(), 16) if serialPortInfo.hasVendorIdentifier() else blankString ) << "\nProduct Identifier: " << ( QByteArray.number(serialPortInfo.productIdentifier(), 16) if serialPortInfo.hasProductIdentifier() else blankString) << "\n"
def portInit(self): for info in QSerialPortInfo.availablePorts(): serialPort = QSerialPort() serialPort.setPort(info) if(serialPort.open(QIODevice.ReadWrite)): self.portNameBox.addItem(info.portName()) serialPort.close()
def __init__(self, parent=None): super().__init__(parent) self.__data = QByteArray() self.__serial = QSerialPort() self.__timer = QTimer(self) for info in QSerialPortInfo.availablePorts(): if info.description() == "USB-SERIAL CH340": self.__serial = QSerialPort(info) print(self.__serial.portName()) break self.__serial.readyRead.connect(self.__read_data) self.__timer.timeout.connect(self.__timer_update_com) self.__temperature = 0 self.__humidity = 0 self.__co2 = 0 self.__tvoc = 0 self.__pm25 = 0 self.__pm10 = 0 self.__o2 = 0 if self.__serial.open(QIODevice.ReadWrite): print("open success") else: print("open fail") self.__auto_save_thread = AutoSave(self) self.__auto_save_thread.start()
def setComboBox(self): modes = ['TCP', 'RTU'] for mode in modes: self.ui.mode_comboBox.insertItem(0, mode) self.ui.mode_comboBox.setCurrentIndex(0) port_list = QSerialPortInfo.availablePorts() for port in port_list: self.ui.port_comboBox.insertItem(0, port.portName()) baudrates = ['300', '1200', '2400', '9600', '19200', '115200'] for baudrate in baudrates: self.ui.baudrate_comboBox.insertItem(0, baudrate) self.ui.baudrate_comboBox.setCurrentIndex(2) data_bits = ['5', '6', '7', '8'] for bit in data_bits: self.ui.dataBits_comboBox.insertItem(0, bit) self.ui.dataBits_comboBox.setCurrentIndex(0) stop_bits = ['1', '1.5', '2'] for bit in stop_bits: self.ui.stopBits_comboBox.insertItem(0, bit) self.ui.stopBits_comboBox.setCurrentIndex(0) paritys = ['N', 'EVEN', 'ODD', 'MARK', 'SPACE'] for parity in paritys: self.ui.parity_comboBox.insertItem(0, parity) self.ui.parity_comboBox.setCurrentIndex(4) slave_id = ['1', '2', '3'] for id in slave_id: self.ui.slaveID_comboBox.insertItem(0, id) self.ui.slaveID_comboBox.setCurrentIndex(2)
def getFoundDevices(): """ Function to check the serial ports for supported MicroPython devices. @return set of tuples with the board type, a description and the serial port it is connected at @rtype set of tuples of (str, str, str) """ from PyQt5.QtSerialPort import QSerialPortInfo foundDevices = [] availablePorts = QSerialPortInfo.availablePorts() for port in availablePorts: vid = port.vendorIdentifier() pid = port.productIdentifier() for board in SupportedBoards: if ((vid, pid) in SupportedBoards[board]["ids"] or (vid, None) in SupportedBoards[board]["ids"]): foundDevices.append( (board, SupportedBoards[board]["description"], port.portName())) break else: logging.debug("Unknown device: (0x%04x:0x%04x)", vid, pid) return foundDevices
def __init__(self, parent=None): super(PyClockSetup, self).__init__() self.serial = QSerialPort(self) uic.loadUi('pyclocksetup.ui', self) self.show() self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateTime) self.timer.start(1000) self.serial = QSerialPort(self) self.cp.colorChanged.connect(self.changeColor) self.connectButton.clicked.connect(self.serialConnect) self.setClockButton.clicked.connect(self.setClock) self.blinkingDots.toggled.connect(self.setBlinkingDots) self.leadingZero.toggled.connect(self.setLeadingZero) self.autoBrightness.toggled.connect(self.setAutoBrightness) self.segmentTest.toggled.connect(self.setSegmentTest) self.brightnessSlider.valueChanged.connect(self.changeBrightness) self.colorLabel.setStyleSheet('QLabel {background-color: #ffffff; }') availablePorts = QSerialPortInfo.availablePorts() for port in availablePorts: self.serialPorts.addItem(port.portName())
def __init__(self): super(SerialProtoParser, self).__init__() # Serial port self.__serialPort = QSerialPort() # Setup Serialport # We are using USB serial driver, so the baud rate doesn't matter self.__serialPort.setBaudRate(QSerialPort.Baud115200, QSerialPort.Input) self.destroyed.connect(self.close) # Get the list of all available serial ports portsList = QSerialPortInfo.availablePorts() # Only connect to Chibios port chibiOsPort = None for port in portsList: if ("ChibiOS" in port.description()): chibiOsPort = port if (chibiOsPort is None): print("Cannot find chibios based device") else: # Set the serial port self.__serialPort.setPort(chibiOsPort) self.__serialPort.setDataBits(QSerialPort.Data8) self.__serialPort.setFlowControl(QSerialPort.NoFlowControl) self.__serialPort.setParity(QSerialPort.NoParity) self.__serialPort.setStopBits(QSerialPort.OneStop) # Connect signals and slots self.__serialPort.readyRead.connect(self.__onSerialPortReadyRead) # Open the device self.__serialPort.open(QIODevice.ReadOnly)
def __init__(self, _value="", description="", key=""): super(Ports, self).__init__("") Ports.value = _value Ports.description = description Ports.key = key self.available_ports = QSerialPortInfo.availablePorts() for port in self.available_ports: Ports.ports.append(port)
def run(self): while True: ports = QSerialPortInfo.availablePorts() if not ports: self.portScanSig.emit([]) else: self.portScanSig.emit(ports) time.sleep(2)
def on_refreshCom(self): self.comNameCombo.clear() com = QSerialPort() for info in QSerialPortInfo.availablePorts(): com.setPort(info) if com.open(QSerialPort.ReadWrite): self.comNameCombo.addItem(info.portName()) com.close()
def find_serial_port(self): for port in QSerialPortInfo.availablePorts(): if port.portName() == self.port_name: the_port = port break else: raise GpsdoError(self.port_name + " not found!") return the_port
def get_available_ports_systemLocations_and_manufacturers(): available_ports = QSerialPortInfo.availablePorts() ports_info = [] for port in available_ports: ports_info.append((port.systemLocation(), port.manufacturer())) return ports_info
def refreshPorts(self): self.cbxPort.clear() ports = reversed( sorted(port.portName() for port in QSerialPortInfo.availablePorts())) for p in ports: port = QSerialPortInfo(p) self.cbxPort.addItem(port.portName(), port.systemLocation())
def searchComPort(self): self.comboBox_Com.clear() com = QSerialPort() comList = QSerialPortInfo.availablePorts() for comInfo in comList: com.setPort(comInfo) if com.open(QSerialPort.ReadWrite): self.comboBox_Com.addItem(comInfo.portName()) com.close()
def getAvailablePorts(self): # 获取可用的串口 self._ports = {} # 用于保存串口的信息 infos = QSerialPortInfo.availablePorts() infos.reverse() # 逆序 for info in infos: # 通过串口名字-->关联串口变量 self._ports[info.portName()] = info self.comboBoxPort.addItem(info.portName())
def serialPortInfo(self): port_list = QSerialPortInfo.availablePorts() baudrates = ['300', '1200', '2400', '9600', '19200', '57600', '115200'] for port in port_list: self.ui.portNamComboBox.insertItem(0, port.portName()) for br in baudrates: self.ui.baudrateNamComboBox.insertItem(0, br)
def getSerialPortList(): """ 当前所连接的串口列表 :return: list-of-QSerialPortInfo """ portlist = list( map(lambda port: port.portName(), QSerialPortInfo.availablePorts())) return portlist
def Com_Refresh_Button_Clicked(self): self.Com_Name_Combo.clear() com = QSerialPort() com_list = QSerialPortInfo.availablePorts() for info in com_list: com.setPort(info) if com.open(QSerialPort.ReadWrite): self.Com_Name_Combo.addItem(info.portName()) com.close()
def pushButton_comRefresh_clicked(self): self.comboBox_comPort.clear() com = QSerialPort() comlist = QSerialPortInfo.availablePorts() for info in comlist: com.setPort(info) if com.open(QSerialPort.ReadWrite): self.comboBox_comPort.addItem(info.portName()) com.close()
def get_available_ports(self): self.serial_combobox.clear() # 获取可用的串口 self.ports = {} # 用于保存串口的信息 infos = QSerialPortInfo.availablePorts() infos.reverse() # 逆序 for info in infos: # 通过串口名字-->关联串口变量 self.ports[info.portName()] = info self.serial_combobox.addItem(info.portName())
def __init__(self): super(RPMPlotter, self).__init__() # Setupui self.setupUi(self) # Create a serial port self.__serialPort = QSerialPort() # Setup Serialport # We are using USB serial driver, so the baud rate doesn't matter self.__serialPort.setBaudRate(QSerialPort.Baud115200, QSerialPort.Input) # Get the list of all available serial ports portsList = QSerialPortInfo.availablePorts() # Only connect to Chibios port chibiOsPort = None self.setWindowTitle("Experiment Data Collector") for port in portsList: if ("ChibiOS" in port.description()): chibiOsPort = port print(chibiOsPort.description()) # Check of the device is connected. if (chibiOsPort is None): # We didn't find anything statusString = "Cannot find Chibios based device." print(statusString) else: # Set the serial port self.__serialPort.setPort(chibiOsPort) self.__serialPort.setDataBits(QSerialPort.Data8) self.__serialPort.setFlowControl(QSerialPort.NoFlowControl) self.__serialPort.setParity(QSerialPort.NoParity) self.__serialPort.setStopBits(QSerialPort.OneStop) # Connect signals and slots self.__serialPort.readyRead.connect(self.__onSerialPortReadyRead) self.startButton.clicked.connect(self.onStartButtonClicked) self.lineEdit.returnPressed.connect(self.onReferenceValueChanged) # Open the device self.__serialPort.open(QIODevice.ReadWrite) # Initialize variables # We track the reference and draw it as a line. self.__referenceArray = [] # Timestamp in seconds self.__timeStampArray = [] # RPM value self.__rpmArray = [] # Voltage provided to the motor self.__voltageValue = [] ## Curves self.__rpmCurve = pg.PlotCurveItem() self.__rpmCurve.setPen(pg.mkPen(color=(3, 39, 28), width=1.2)) self.__referenceCurve = pg.PlotCurveItem() self.__referenceCurve.setPen( pg.mkPen(color=(214, 118, 17), width=1.2, style=Qt.DashDotLine)) self.graphicsView.addItem(self.__rpmCurve) self.graphicsView.addItem(self.__referenceCurve)
def on_devChange_directoryChanged(self, path): ports = QSerialPortInfo.availablePorts() text = self.serialPort.currentText() self.serialPort.clear() for i in ports: n = i.portName() self.serialPort.addItem(n) self.sPortList[n] = i if text in self.sPortList: self.serialPort.setCurrentText(text) print("Directory changed: ", path)
def find_microbit(): """ Returns the port for the first microbit it finds connected to the host computer. If no microbit is found, returns None. """ available_ports = QSerialPortInfo.availablePorts() for port in available_ports: pid = port.productIdentifier() vid = port.vendorIdentifier() if pid == MICROBIT_PID and vid == MICROBIT_VID: return port.portName() return None
def find_microbit(): """ Returns the port for the first microbit it finds connected to the host computer. If no microbit is found, returns None. """ available_ports = QSerialPortInfo.availablePorts() for port in available_ports: pid = port.productIdentifier() vid = port.vendorIdentifier() if pid == MICROBIT_PID and vid == MICROBIT_VID: port_name = port.portName() logger.info('Found micro:bit with portName: {}'.format(port_name)) return port_name logger.warning('Could not find micro:bit.') logger.debug('Available ports:') logger.debug(['PID:{} VID:{} PORT:{}'.format(p.productIdentifier(), p.vendorIdentifier(), p.portName()) for p in available_ports]) return None
def find_microbit(): """ Returns the port for the first microbit it finds connected to the host computer. If no microbit is found, returns None. """ available_ports = QSerialPortInfo.availablePorts() for port in available_ports: pid = port.productIdentifier() vid = port.vendorIdentifier() # Look for the port VID & PID in the list of known board IDs. if (vid, pid) in BOARD_IDS: port_name = port.portName() logger.info('Found micro:bit with portName: {}'.format(port_name)) return port_name logger.warning('Could not find micro:bit.') logger.debug('Available ports:') logger.debug(['PID:{} VID:{} PORT:{}'.format(p.productIdentifier(), p.vendorIdentifier(), p.portName()) for p in available_ports]) return None
def find_device(self, with_logging=True): """ Returns the port and serial number for the first MicroPython-ish device found connected to the host computer. If no device is found, returns the tuple (None, None). """ available_ports = QSerialPortInfo.availablePorts() for port in available_ports: pid = port.productIdentifier() vid = port.vendorIdentifier() # Look for the port VID & PID in the list of know board IDs if (vid, pid) in self.valid_boards: port_name = port.portName() serial_number = port.serialNumber() if with_logging: logger.info('Found device on port: {}'.format(port_name)) logger.info('Serial number: {}'.format(serial_number)) return (self.port_path(port_name), serial_number) if with_logging: logger.warning('Could not find device.') logger.debug('Available ports:') logger.debug(['PID:{} VID:{} PORT:{}'.format(p.productIdentifier(), p.vendorIdentifier(), p.portName()) for p in available_ports]) return (None, None)
def get_serial_ports(): """ List les ports séries disponible et leurs noms :raise EnvironmentError: Plateforme inconnue :return: La list des ports serial dispo sur le système """ # if sys.platform.startswith('linux'): # serial_ports = glob.glob('/dev/athome*') # else: info_list = QSerialPortInfo() serial_list = info_list.availablePorts() serial_ports = [port.portName() for port in serial_list] return serial_ports