简体   繁体   English

串口通讯

[英]Serial-port communication

I'm developing a software that lets you manage the serial-port communication in an easier way, through a C++ wrapper class. 我正在开发一个软件,通过C ++包装器类,您可以通过一种更轻松的方式来管理串行端口通信。 But I've run into some doubts; 但是我遇到了一些疑问。 for example, I wanna show a simple message on the other screen: 例如,我想在另一个屏幕上显示一条简单的消息:

1)There is the need of a "listening server" (and then set it up)? 1)是否需要“监听服务器”(然后进行设置)? Or it gets written directly, like this example: 或者直接将其写入,例如以下示例:

#include <fcntl.h>
#include <unistd.h>
int main()
{
  int fd = open("/dev/tty2", O_RDWR);
  write(fd, "Hello World", sizeof("Hello World"));
  return 0;
}

(just to show the behavior) (只是为了显示行为)
2) I run the program on the sender computer. 2)我在发送方计算机上运行该程序。 On the second one, what I've to do? 关于第二个,我该怎么做? The two machines run Linux both. 两台机器都运行Linux。 Please give me as much information as you can, I've never treated this (old) communication style. 请给我尽可能多的信息,我从来没有对待过这种(旧的)沟通方式。

Edit: In every program I've found so far, both the read and write are in the same program. 编辑: 到目前为止,在我发现的每个程序中,读取和写入都在同一个程序中。 I'd know why. 我知道为什么

Personally tested, yes, you've to set a listener and a writer program. 是的,经过个人测试,您必须设置一个侦听器和一个编写器程序。 Kind of client-server, I'd say. 我会说一种客户端服务器。

Often sending and receiving are implemented in one program. 通常,发送和接收是在一个程序中实现的。 So you have the same program on both machines even if you send always from the same machine and receive on the other. 因此,即使您始终从同一台计算机发送并在另一台计算机上接收,您在两台计算机上都具有相同的程序。 If you want to communicate both ways you need sending and receiving in the same application. 如果您想以两种方式进行通信,则需要在同一应用程序中进行发送和接收。 But then you need a synchronization mechanism. 但是,那么您需要一个同步机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM