是否可以在C中保持编程端口TX线高或低C?

发布于 2025-01-24 02:50:55 字数 411 浏览 4 评论 0原文

这是我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒绊 2025-01-31 02:50:55

是的。不发送任何数据时,串行线的默认状态为“标记”(高,对于单端线)。要发送一个空间(低),请设置休息位。清除休息位以恢复空闲状态。

正如评论中指出的那样,可以使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文