hi there,
I use Suse 9.3 and have a serial port communication problem in my own c++ program.
the necessary configuration for the device is:
Port Settings:
The host port runs at 9600 baud, 8 data bits, 1 stop bit, and no parity.
Flow Control:
The device negates the device RTS (output from device) line whenever the device is busy in a non-interruptible process.
The device ignores the Host CTS line. No software (Xon/Xoff) flow control is provided. It is the responsibility of the host to issue only a single command for which a response from the device Control is required until the response is received from the device Control. Inter and intra message timeout is defined as 1 second. (Typical response times and character pacing will be baud rate limited.)
With 'kpp' and the following standard configuration
Modem device: /dev/ttyS1
Flow control: Hardware [CRTSCTS]
Connection speed: 9600
I can perfectly communicate with my device by the use of the terminal program.
Than I found the
Serial Programming Guide for POSIX Operating Systems <
http://www.easysw.com/~mike/serial/serial.html>
and tried to find a appropriate configuration and failed.
fd_com2 = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd_com2 == -1) {perror("open_port: Unable to open /dev/ttyS1 - ");} // Could not open the port.
else fcntl(fd_com2, F_SETFL, 0);
struct termios options; // structure defined in terminos.h
tcgetattr(fd_com2, &options); // Get the current options for the port...
cfsetispeed(&options, B9600); // Set the baud rates to 19200...
cfsetospeed(&options, B9600); // Set the baud rates to 19200...
// setting control options
options.c_cflag |= (CLOCAL | CREAD); // Enable the receiver and set local mode...
options.c_cflag &= ~PARENB; // no parity bit
options.c_cflag &= ~CSTOPB; // (only) 1 stop bit
options.c_cflag &= ~CSIZE; // Mask the character size bits
options.c_cflag |= CS8; // Select 8 data bits
// flow control
// Some versions of UNIX support hardware flow control using the CTS (Clear To Send) and RTS (Request To Send) signal lines.
// If the CNEW_RTSCTS or CRTSCTS constants are defined on your system then hardware flow control is probably supported.
// Do the following to enable hardware flow control:
options.c_cflag |= CRTSCTS; //CNEW_RTSCTS;
// setting local options
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // Choosing Raw Input
// setting imput options
options.c_iflag &= ~(IXON | IXOFF | IXANY ); // Disable Software Flow Control
options.c_oflag |= (OPOST | ONLCR) ;
// options.c_iflag |= (ICRNL); // Map CR to NL
tcsetattr(fd_com2, TCSANOW, &options); // Set the new options for the port...
The problem might be the flow control.
If I send a command with
write(fd_com2, "/nR/r", 3)
the device is sometimes not ready to communicate and the command get lost.
If I read what I receive with
read(fd_com2, buffer, 20)
sometimes I read the return message twice, sometimes I receive messages from earlier commands sometimes the reading starts in between and sometimes I do not receive the complete receive messages.
So probably my choice of flag settings is somehow wrong.
the easiest would be to 'copy' the port configuration of kppp.
Therefore my post here.
does anybody have the kppp serial port configuration of kppp with the basic configuration profile shown above?
Thanks
Andre