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
| API | Description |
|---|---|
| device.open | Open device connection. The current implementation supports serial serial devices. |
| device.scan | Scan system devices. The current implementation supports serial serial port scanning. |
| device.list | Returns the list of open devices that are still visible to the current program. |
| device.exists | Determine whether the specified serial port exists in the system. |
| serial.read | Read data from the opened serial port, compatible with returning String or byte array. |
| serial.read_bytes | Read raw Bytes from the opened serial port. |
| serial.read_text | Read UTF-8 text from the opened serial port, return null if illegal UTF-8. |
| serial.write | Write a string, byte array or Bytes to the opened serial port. |
| serial.flush | Flushes the output buffer of the opened serial port. |
| serial.close | Close the open serial port. |
Examples
ports = device.scan() result = type(ports) // Output: Array print result
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()andbytes()to avoid implicitly treating device messages as strings.