如何查看linux下串口是否可用?串口名称等?

如何查看linux下串口是否可用?串口名称等?,第1张

1、查看串口是否可用,可以对串口发送数据比如对com1口,echo lyjie126 >/dev/ttyS0

2、查看串口名称使用  ls   -l  /dev/ttyS* 一般情况下串口的名称全部在dev下面,如果你没有外插串口卡的话默认是dev下的ttyS* ,一般ttyS0对应com1,ttyS1对应com2,当然也不一定是必然的;

3、查看串口驱动:cat /proc/tty/drivers/serial

4、查看串口设备:dmesg | grep ttyS*

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/


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7380769.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-05
下一篇2023-04-05

发表评论

登录后才能评论

评论列表(0条)

    保存