2026a
# serialportlist
连接到系统的串口列表
函数库:TyInstrumentControl
# 语法
serialportlist()
serialportlist("all")
serialportlist("available")
serialportlist(__;nports_guess = n)
# 说明
serialportlist() 或 serialportlist("all") 返回系统上所有串行端口的列表。该列表显示您可以在计算机上访问并可用于串行端口通信的所有串行端口。
serialportlist("available") 仅返回系统上当前可用的串行端口的列表。
serialportlist(__;nports_guess = n) 输入为上述用法的任意参数组合,nports_guess 为 预估的串口数目,以整型形式输入,默认为 64。
# 示例
获取串行端口列表
使用 serialport 创建 InstSerialPort 对象,将其连接到 COM1 端口,然后使用 serialportlist 函数获取系统上的串行端口列表。
识别系统上的串行端口。
using TyInstrumentControl
ports = serialportlist()
2-element Vector{String}:
"COM1"
"COM2"
仅列出可用的端口。
freeports = serialportlist("available")
1-element Vector{String}:
"COM2"
提示
serialportlist 返回系统上的所有串行端口,无论连接是否存在。要获取现有 serialport 连接的列表,请改用 serialportfind。