For a few days, the problem is wonderful.
But eventually it's settled, just the code.
#include <stdio.h>/*standard input and output definition*/#include<stdlib.h>/*standard function Library definition*/#include<unistd.h>/*UNIX standard function definition*/#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>/*file Control definition*/#include<termios.h>/*Ppsix Terminal Control definition*/#include<errno.h>/*Error Number Definition*/#include<string.h>#defineStty_dev "/dev/ttysac2"#defineBuff_size 512intMain () {intstty_fd, N; CharBuffer[buff_size]; structTermios opt; printf ("---->> input test 1!\n\n"); /*Open Serial Device*/STTY_FD= Open (Stty_dev, o_rdwr| o_noctty|o_ndelay); if(STTY_FD = =-1) {perror ("Open Device Error"); return 0; } fcntl (STTY_FD, F_SETFL,0); printf ("---->> Input test 2!\n\n"); //printf ("---->> input Test 3!\n\n"); /*set baud rate-19200*/Cfsetispeed (&opt, B19200); Cfsetospeed (&opt, B19200); //printf ("---->> input Test 4!\n\n"); /*Set Data bits-8 bit data bits*/Opt.c_cflag&= ~CSIZE; Opt.c_cflag|=CS8; Opt.c_cflag|=Cread; Opt.c_cflag|=clocal; /*set parity bit-no parity*/Opt.c_cflag&= ~Parenb; Opt.c_iflag&= ~INPCK; Opt.c_iflag&= ~HUPCL; /*set Stop bit-1-bit stop bit*/Opt.c_cflag&= ~CSTOPB; /*setting the time-out period*/Opt.c_cc[vtime]=0; Opt.c_cc[vmin]=0; /*setting up a write device*/Tcflush (STTY_FD, Tcioflush); if(0! = tcsetattr (STTY_FD, Tcsanow, &opt)) {Perror ("set BaudRate"); return 0; } memset (Buffer,0, buff_size); N= Write (STTY_FD,"Hello World", One); /*reads data until a ' quit ' string is received to exit*/ while(1) {n=Read (stty_fd, buffer, buff_size); if(N <0) {perror ("Read Data"); Break; } if(N >0) {Buffer[n]=' /'; printf ("%d\n", N); printf ("%s\n", buffer); if(0= = strncmp (buffer,"quit",4) {printf ("User Send quit!\n"); Break; }}}} close (STTY_FD);}
The problem is in the 30th line of the place, originally wrote a sentence tcgetattr (STTY_FD, &opt); this sentence is used to get the current serial port status of the parameters to be set to the parameters
Added this line on the board of the flight can not be used, may be the original default settings of the problem, in short, I wrote down just for the future reference
Forum Posts: http://bbs.witech.com.cn/forum.php?mod=viewthread&tid=58085&page=1#pid197007
I forgot my brother's 18 birthday ... I'm so sorry ...
The serial test procedure of the ok6410 of the Flying Ling