
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/
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)