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