【发布时间】:2012-10-02 00:50:03
【问题描述】:
我有一个插入的 USB 串行设备插入我的 Windows 并使用 virtualbox 对其进行串行映射,例如 COM1 -> /dev/ttyS0..
现在我如何知道我的设备正在使用哪个串行端口。我现在知道我正在使用 /dev/ttyS0。但是如果我不知道怎么办?.. Linux Debian 在启动时创建这个永久串行端口设备 /dev/ttyS0-S3。
如何测试 /dev/ttyS0 是我在 c 中使用的真实端口。
这是我测试端口是否正确的方法。
devfd=open("/dev/ttyS0",O_WRONLY | O_NOCTTY | O_NDELAY);
if(s_fd<0) exit(1);
printf("open\n"); //It will always return true printing open because this device is created on boot time and is always available. so i made another check and that is to write to the port(Assuming i have set the permission to have full access to the serial port). if i can write to the port then it means it is really the port im using.
test=write(devfd,"ATZ",4);
if(test<0) printf("Can't write to port: Maybe not the serial port ur using\n");
printf("Device is avaialable\n"); // returns true because we can write to the port
如果有设备插入该串行端口,您能否向我展示如何检查串行端口的其他示例?
或者在 c 中测试以下串行端口 /dev/ttyS0 - /dev/ttyS3 如果以下已插入设备。
谢谢。
【问题讨论】:
-
如果只有这个串行端口正在主动发送(或接收)而所有其他端口都处于静止状态,那么该活动应该显示在 @987654322 中每个串行端口的“tx:”传输字节计数中@文件。
标签: c linux linux-kernel serial-port