connecting com2 (c++)
hi
i have to connect com2 to send,recive commands from a machine i have.
i success to send commands but not to listen to commands.
it run under linux(with c++).
the Parameters should be:
port :RS232
baud rate : 19200
data bits 8
parity none
stop bits 1
flow control none
the way i did it is :
fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd == -1) //Could not open the port.
return false;
fcntl(fd, F_SETFL, FASYNC);
struct termios options;
//Get the current options for the port...
tcgetattr(fd, &options);
//Set the baud rates to 19200...
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
//Enable the receiver and set local mode...
options.c_cflag |= (CLOCAL | CREAD);
//Set the new options for the port...
options.c_cflag &= ~CSIZE; /* Mask the character size bits */
options.c_cflag |= CS8; /* Select 8 data bits */
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CRTSCTS;
options.c_lflag |= (ICANON | ECHO | ECHOE);
options.c_iflag &= ~(IXON | IXOFF | IXANY);
tcsetattr(fd, TCSANOW, &options);
and to write something like
write(fd, "abcdefg\r", 8);
and it works
but to read i tried and cant do it
what the problem?
may be i gave wrong flags to the parameters i need ?
how should i read data.
thanks.
|