device hardware device library

device hardware device library

device hardware device library

Function

device provides device scanning, opening, listing, existence check and serial port reading and writing capabilities. The device type implemented by the current source code is serial.

API List

APIDescription
device.openOpen device connection. The current implementation supports serial serial devices.
device.scanScan system devices. The current implementation supports serial serial port scanning.
device.listReturns the list of open devices that are still visible to the current program.
device.existsDetermine whether the specified serial port exists in the system.
serial.readRead data from the opened serial port, compatible with returning String or byte array.
serial.read_bytesRead raw Bytes from the opened serial port.
serial.read_textRead UTF-8 text from the opened serial port, return null if illegal UTF-8.
serial.writeWrite a string, byte array or Bytes to the opened serial port.
serial.flushFlushes the output buffer of the opened serial port.
serial.closeClose the open serial port.

Examples

Notes

  • device is the standard library construction entry and also supports shorthand calls such as device.scan().
  • Serial communication depends on system equipment and permissions, COM3 in the example needs to be replaced with the actual port.
  • The binary protocol preferentially uses read_bytes() and bytes() to avoid implicitly treating device messages as strings.