device.scan

device.scan

device.scan

Function

Scans system devices. The current implementation supports serial-port scanning.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
typeStringNoserialDevice type. Currently only serial is supported.

Return value

TypeDescription
ArrayReturns an array of device information objects.

Serial port information field

Currently, device.scan() returns an array of serial-port information objects. Each object has the following fields:

FieldTypeMust existDescription
typeStringYesDevice type, currently fixed to serial.
portStringYesSystem serial port name. Common values for Windows are COM3; common values for Linux/macOS are /dev/ttyUSB0, /dev/tty.usbserial. Passed to device.open({port: ...}) when opening the serial port.
nameStringYesThe friendly name of the device. The USB serial port preferentially uses the product name or manufacturer name; if it cannot be recognized, it will equal port.
kindStringYesSerial port source type. Common values are usb, bluetooth, pci, unknown.
vidIntNoUSB Vendor ID. Only exists when the USB serial port can recognize the manufacturer ID.
pidIntNoUSB Product ID. Only exists when the USB serial port can recognize the product ID.
serial_numberStringYesUSB device serial number; empty string if not provided by the system.
manufacturerStringYesUSB device manufacturer name; empty string if not provided by the system.
productStringYesUSB device product name; empty string if not provided by the system.

Example

Notes

  • The current implementation only supports serial, and the serial port is scanned by default when type is not passed.
  • vid and pid are not available in all serial ports; when the field does not exist, the read result is Empty.