我是使用C在Linux中进行串行编程的新手.我已经找到了一小段代码来在串口上写入数据,我在这里分享.运行此代码后,我可能会认为数据已写入特定端口.现在我想打开另一个终端并使用单独的代码想要读取写在该特定端口上的数据 - 我该怎么做?
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
/*
* 'open_port()' - Open serial port 1.
*
* Returns the file descriptor on success or -1 on error.
*/
int
open_port(void)
{
int fd; /* File descriptor for the port */ …Run Code Online (Sandbox Code Playgroud)