通过串行终端二进制数据 [英] Binary data over serial terminal

查看:139
本文介绍了通过串行终端二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能用我的嵌入式设备的通信方式是串行端口。默认情况下,嵌入式Linux使用此端口作为终端。如何禁用该终端,并使用串行链路来传输二进制数据?我听说像RX和TX的命令,但我无法找到他们。

My only way of communication with my embedded device is a serial port. By default, embedded Linux uses this port as a terminal. How do I disable this terminal and use the serial link to transfer binary data? I heard of commands like rx and tx but i cannot find them.

我想我可以只读取()和write()的东西到/ dev / tty的,但我想,以确保没有任何乱用我的数据流中的错误信息或

I think I can just read() from and write() stuff to /dev/tty but I want to make sure no error messages or whatever mess with my data stream.

推荐答案

您可以使用应用程序像XMODEM超过任何终端传输文件。是你讲了一个终端的串口,或者是它也内核控制台。

You can use an application like xmodem to transfer file over any terminal. Is the serial port you speak off a terminal, or is it also the kernel console.

如果你的内核不吵,那么你可以使用当前的连接,使XMODEM传输一样。在主机端,可以使用克米特,这是很好的和可编写脚本。

If you're kernel is not noisy, then you can use your current connection to make xmodem like transfer. On the host side, you can use kermit, which is nice AND scriptable.

如果你想使你的串行端口生,你有文件描述符ttyfd打开,
这里是做到这一点的一种方法:

If you want to make your serial port raw, and you have file descriptor ttyfd opened, here is one way to do it :

struct termios tty, orig_tty;

...

if(tcgetattr(ttyfd, &tty) < 0)
{
    // error checking
}
// backup tty, make it raw and apply changes
orig_tty = tty;
cfmakeraw(&tty);
if(tcsetattr(ttyfd, TCSAFLUSH, &tty) < 0)
{
    // error checking
}

...
//end of program or error path :
tcsetattr(ttyfd, TCSAFLUSH, &orig_tty)

不要忘了在你程序的最后恢复的设置,如果你还是想好了乖终端。

Don't forget to restore the setting at the end of your program if you still want a good behaved terminal.

这篇关于通过串行终端二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆