📄 serial.c
字号:
#include "stdio.h"
#include <sys/ioctl.h>
#include <termios.h>
#include <stdlib.h>
#include <fcntl.h>
struct termios tio; /* the serial for LCD */
int fd;
void main()
{
if((fd = open("/dev/ttyS0",O_RDWR | O_NDELAY |O_NOCTTY)) < 0) //串口实例,通过minicom改ttys0
{
printf("Couldn't open\n");
exit(1);
}
else
{
printf("comm open success! \n");
}
tio.c_cflag = B115200 |CS8 |CREAD |CLOCAL;
tio.c_cflag &= ~HUPCL;
tio.c_lflag = 0;
tio.c_iflag = IGNPAR;
tio.c_oflag = 0;
tio.c_cc[VTIME] = 0;
tio.c_cc[VMIN] = 0;
tcflush(fd,TCIFLUSH);
tcsetattr(fd,TCSANOW,&tio);
fcntl(fd,F_SETFL,FNDELAY);
write(fd,"$R4C10$",7);
sleep(1);
close(fd);
}
fd = OpenDev(dev);
set_speed(fd, 19200);
if (set_Parity(fd, 8, 1, 'N') == FALSE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -