返回当前程序中已打开且仍可见的设备句柄列表。
它不是系统设备列表;扫描系统串口请使用 device.scan('serial')。
device.list()
无。
Array:已打开设备数组。没有已打开设备时返回空数组 []。
每个设备对象字段:
| 字段 | 类型 | 说明 |
|---|---|---|
| type | string | 设备类型,当前为 serial |
| port | string | 串口名称,例如 COM3 或 /dev/ttyUSB0 |
| baudRate | int | 打开时使用的波特率 |
| closed | bool | 设备句柄是否已经关闭 |
println(device.list()) serial = device.open({ type:'serial', port:'COM3', baudRate:9600 }) println(device.list()) serial.close() println(device.list())
device.list() 可以看到它;对象释放后,列表会自动清理不可见句柄。
serial.close() 后,如果变量仍然保存该对象,列表中会显示 closed:true。