/************* includes *****************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <assert.h>
#include <termios.h>
#define SERIAL_DEVFILE "/dev/ttySAC2"
void config_serial(int fd_serial);
int main()
{
char rx_buff[100] = {0};
int fd_serial = 0;
int ret=0;
// initialize serial connection
printf("\nrecver: initialize serial file descriptor\n");
fd_serial = open(SERIAL_DEVFILE, O_RDONLY);
assert(fd_serial > 0);
printf("recv(): fd_serial = %d\n",fd_serial);
config_serial(fd_serial);
while (strcmp("q",rx_buff))
{
// zeroes rx buffer
memset(rx_buff, 0, sizeof(rx_buff));
// reads data from rs232
ret = read(fd_serial, rx_buff, 12);
//sleep(1);
printf("\n\n\nrecver: %d\n", ret);
// if successfully got data, print it and copy to shared memory
if (strlen(rx_buff))
{
printf("recver: got %s\n", rx_buff);
}
}
}
void config_serial(int fd_serial)
{
struct termios options;
tcgetattr(fd_serial, &options); // Get Current Config
cfsetispeed(&options, B9600); // Set Baud Rate
cfsetospeed(&options, B9600);
options.c_cflag = (options.c_cflag & ~CSIZE) | CS8;
options.c_iflag = IGNBRK;
options.c_lflag = 0;
options.c_oflag = 0;
options.c_cflag |= CLOCAL | CREAD;
options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 5;
options.c_iflag &= ~(IXON|IXOFF|IXANY);
options.c_cflag &= ~(PARENB | PARODD);
/* Save The Configure */
tcsetattr(fd_serial, TCSANOW, &options);
/* Flush the input (read) buffer */
tcflush(fd_serial,TCIOFLUSH);
}
uart.rar_back
版权申诉
125 浏览量
2022-09-23
00:59:03
上传
评论
收藏 2KB RAR 举报
alvarocfc
- 粉丝: 111
- 资源: 1万+
最新资源
- com.Gaggle.fun.GooseGooseDuck.apk
- FastBrowser 基于CefSharp浏览器 Chromium内核 C#、WPF界面绘制, mp3、mp4播放
- apache-tomcat-8.5.100.tar.gz
- namehfyz1234
- 14727758_202405291911557049.csv.zip
- hfyzname1234
- 基于Java ME无线网络移动端的俄罗斯方块游戏的实现(源码+使用文档)
- 第九届上海市大学生网络安全大赛暨“磐石行动”2024第二届全国高校网络安全攻防活动 MISC wifi密码
- B07-GA503-2补充.zip
- 基于Java蚁群算法路由选择可视化(源码+使用文档)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0