📄 debug.c
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <termios.h>#include <errno.h>#include <pthread.h>int main(void){ int fd; char rxBuffer[1024]; int len = 1024; int rxByte; struct termios opt; fd = open("/dev/ttyS1",O_RDWR);//|O_NOCTTY|O_NDELAY); if(fd==-1) { perror("error"); } //set bps tcgetattr(fd,&opt); tcflush(fd,TCIOFLUSH); cfsetispeed(&opt,B9600); cfsetospeed(&opt,B9600); //tcflush(fd,TCIOFLUSH); tcsetattr(fd,TCSANOW,&opt); //set raw input and output 8O1 tcgetattr(fd,&opt); opt.c_cflag &= ~PARENB; opt.c_iflag &= ~INPCK; opt.c_cflag &= ~CSTOPB; //opt.c_cflag &= ~CSIZE; opt.c_cflag |= CS8; //opt.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG); //opt.c_iflag |= (ISTRIP); //opt.c_oflag &= ~OPOST; opt.c_cc[VMIN] = 0; opt.c_cc[VTIME] = 150; tcflush(fd,TCIOFLUSH); tcsetattr(fd,TCSANOW,&opt); //print tips printf("Please enter any data to the COM1, Enter key to confirm\n"); write(fd,"READY!\n",7); //receive bytes and send back //read(fd,rxBuffer,len); while(1) { rxByte = 0; rxByte = read(fd,rxBuffer,len); if(rxByte>0) { if(rxBuffer[0]=='#') break; rxBuffer[rxByte]='\0'; write(fd,"RE:",3); write(fd,rxBuffer,rxByte); write(fd,"\n",1); printf("%s\n",rxBuffer); } } close(fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -