相关疑难解决方法(0)

如何使用C从Linux中的串口读取数据?

我是使用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)

c linux serial-port

11
推荐指数
2
解决办法
6万
查看次数

标签 统计

c ×1

linux ×1

serial-port ×1