?? serialclient.c
字號:
/*serial client on uclinux terminal */#include <stdio.h>#include <string.h>#include <malloc.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <termios.h>#include <errno.h>#include <stdlib.h>#include <unistd.h>int spfd;int main(){ char fname[16],*sbuf; int retv; struct termios oldtio; spfd = open("/dev/ttyS0",O_RDWR|O_NOCTTY); if(spfd<0) { perror("open/dev/ttyS0"); return -1; } printf("\n ready for sending data....\n"); tcgetattr(spfd,&oldtio); //保存串口的當前設置 cfmakeraw(&oldtio); cfsetispeed(&oldtio,B115200); cfsetospeed(&oldtio,B115200); tcsetattr(spfd,TCSANOW,&oldtio); //選擇新的設置,TCSANOW表示設置立即生效 fname[0] = '1'; fname[1] = '2'; fname[2] = '3'; fname[3] = '\0'; sbuf = (char *)malloc(4); strncpy(sbuf,fname,4); retv= write(spfd,sbuf,4); if(retv==-1) perror("read"); printf("the number of char sent is %d\n",retv); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -