是否可以在C中保持编程端口TX线高或低C?
这是我的C程序的相关部分(在Linux中):
while (input != ' '){
write(serial_port, msg, sizeof(msg));
//1. here I would like to wait at least 100 us with the Tx line high
//2. followed by at least 8us with the Tx line low
//3. and then repeat the message
input = mygetch();
}
如您所见,每次通过串行端口发送MSG后,我想将TX线设置为100微秒的高位,然后以8微秒为单位。该消息直到用户按下空格。
我在Linux中使用C在串行端口上具有这种控制吗?
tia寻求帮助。
This is the relevant part of my C program (in Linux):
while (input != ' '){
write(serial_port, msg, sizeof(msg));
//1. here I would like to wait at least 100 us with the Tx line high
//2. followed by at least 8us with the Tx line low
//3. and then repeat the message
input = mygetch();
}
As you can see, after each send of msg through the serial port, I would like to set the Tx line high for 100 microseconds and then low for 8 microseconds and then repeat the message until the user presses the space-bar.
Do I have this kind of control on the serial port using C in Linux?
TIA for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。不发送任何数据时,串行线的默认状态为“标记”(高,对于单端线)。要发送一个空间(低),请设置休息位。清除休息位以恢复空闲状态。
正如评论中指出的那样,可以使用TTY设备IOCTLS TIOCSBRK和TIOCBBRK发送和清除断裂。
https://linux.die.net/man/4/tty_ioctl
Yes. The default state of a serial line when not sending any data is "mark" (high, for a single-ended line). To send a space (low), set the break bit. Clear the break bit to restore the idle state.
As pointed out in the comments, the tty device ioctls TIOCSBRK and TIOCCBRK may be used to send and clear break.
https://linux.die.net/man/4/tty_ioctl