请问程序中linux如何获取可用的串口列表

2025-04-13 10:53:06
推荐回答(3个)
回答1:

dmesg | grep tty

下面是一个例子,例子中采用的是USB转串口线(pl2303)。

插入线:
$ dmesg|grep tty
[ 0.000000] console [tty0] enabled
[ 1.248404] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 1.624590] 00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 12.618301] usb 5-2: pl2303 converter now attached to ttyUSB0

拔出线:
$ dmesg|grep tty
[ 0.000000] console [tty0] enabled
[ 1.248404] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 1.624590] 00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 12.618301] usb 5-2: pl2303 converter now attached to ttyUSB0
[ 375.392303] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0

这样程序中应该不难判断了吧。
【参考】http://www.cyberciti.biz/faq/find-out-linux-serial-ports-with-setserial/

回答2:

敲命令:lspci 回车所有的串口都有另:linux没有注册表

回答3:

什么版本linux ?你试试df,fdisk