dear all, i tried this sample program in C to receive a string from ttySAC1
(con2). but if i want to receive a string (for example) "123456789", i just
got:
12345678
9
how to solve my problem so i can get full string:
123456789
thanks
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
int main()
{
int fd;
struct termios options;
int n;
char buff[255],recvline[255];
/* Open Port */
fd = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NDELAY); /* <--- YOUR
PORT */
if(fd == -1) {
printf("ERROR Open Serial Port!");
}
/* Serial Configuration */
tcgetattr(fd, &options); // Get Current Config
cfsetispeed(&options, B4800); // 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, TCSANOW, &options);
/* Flush the input (read) buffer */
tcflush(fd,TCIOFLUSH);
do{
n = read(fd,buff,255); // Read Data From Serial Port
buff[n] = '\0';
if(n>0)
{
printf("%s\n",buff); // Print Out
}
}while(strncmp(buff,"bye",3)); // If user say bye then Exit
close(fd); // Close Port
return 0; // End Program
}

