registering
06-06-2003, 03:27 PM
Hi all,
I am trying to put my modem into raw mode, so it manipulates no data sent thru it, however it seems to be echoing. I can't be certain, because there's a device on the other end I don't know enough about. I've looked through the cfmakeraw settings, and my code is below. I know it's a lot to look at, but maybe someone knows any tricks for Linux? This is 2.4.18-4. Thanks for any help.
/************************************************** ****************************
Procedure: open_client_serial_port(...)
Purpose: Attempts to open the serial port passed-in as parameter 'port'
Returns: int: 1 if the serial device could not be opened
Notes: This might also 'exit' and not just 'return' if we could not open our
serial device!
************************************************** ****************************/
int open_client_serial_port(comm_data_t* port,
const comm_connection_t* environment,
FILE* logfile)
{
int retval = 0; /* our return value */
port->fd = open(port->dev, O_RDWR | O_NOCTTY | O_NDELAY);
if (port->fd < 0)
{
logger(logfile, "ERROR -- 2 Could not open our serial device");
perror(port->dev);
retval = 1;
port->comm_status = COMM_DOWN;
}
else
{
/* we could open our serial port */
logger(logfile," -- Debug: 2 Successfully opened our serial device");
tcgetattr(port->fd,&port->ser_oldtio); // save the current modem setting so we can restore them
tcgetattr(port->fd,&port->ser_newtio); // save the current modem settings to the new settings structure
cfmakeraw(&port->ser_newtio); // set struct for new term settings to raw. See man 'cfmakeraw'
port->ser_newtio.c_cflag &= ~CRTSCTS; // make sure rts/cts flow control is turned off
port->ser_newtio.c_cflag |= (CLOCAL | CREAD); // make sure receiver is enabled and port owner not changed
port->ser_newtio.c_iflag &= ~(IXON | IXOFF | IXANY);// make sure software flow control is off
cfsetispeed(&port->ser_newtio, port->ser_speed); // set the input baudrate for new terminal settings
cfsetospeed(&port->ser_newtio, port->ser_speed); // set the output baudrate for new terminal settings
tcflush(port->fd, TCIOFLUSH); // clear the input and output port buffers
tcsetattr(port->fd,TCSANOW,&port->ser_newtio); // set the new attributes for the serial port immediately
tcgetattr(1,&port->ser_old_stdout_tio); // we gotta do this - there is a Linux bug
tcsetattr(1,TCSANOW,&port->ser_newtio); // make stdout settings like modem settings
tcgetattr(0,&port->ser_oldstdtio); // get stdin settings for restoration ...
tcgetattr(0,&port->ser_newstdtio); // ... and use them as a basis for changes
port->ser_newstdtio.c_lflag &= ~(ICANON | ECHO); // make them raw
tcsetattr(0,TCSANOW,&port->ser_newstdtio); // set the new attributes immediately
port->comm_status = COMM_OK; //we really need some error checing on all of the above calls ...
}
if (port->fd < 0)
{
logger(logfile, "ERROR -- 2b Could not open our serial device");
perror(port->dev);
exit(-1);
}
//set the serial port to return immediately after a read
fcntl(port->fd, F_SETFL, O_NONBLOCK);
//if we are using an RF95A the RTS line must be disabled (low)
if (environment->RF_MODEM_95A == 1)
{
ioctl(port->fd, TIOCMGET, &port->modem_line);
port->modem_line &= ~TIOCM_RTS;
ioctl(port->fd, TIOCMSET, &port->modem_line);
} /* end if */
return(retval);
} /* end open_client_serial_port */
I am trying to put my modem into raw mode, so it manipulates no data sent thru it, however it seems to be echoing. I can't be certain, because there's a device on the other end I don't know enough about. I've looked through the cfmakeraw settings, and my code is below. I know it's a lot to look at, but maybe someone knows any tricks for Linux? This is 2.4.18-4. Thanks for any help.
/************************************************** ****************************
Procedure: open_client_serial_port(...)
Purpose: Attempts to open the serial port passed-in as parameter 'port'
Returns: int: 1 if the serial device could not be opened
Notes: This might also 'exit' and not just 'return' if we could not open our
serial device!
************************************************** ****************************/
int open_client_serial_port(comm_data_t* port,
const comm_connection_t* environment,
FILE* logfile)
{
int retval = 0; /* our return value */
port->fd = open(port->dev, O_RDWR | O_NOCTTY | O_NDELAY);
if (port->fd < 0)
{
logger(logfile, "ERROR -- 2 Could not open our serial device");
perror(port->dev);
retval = 1;
port->comm_status = COMM_DOWN;
}
else
{
/* we could open our serial port */
logger(logfile," -- Debug: 2 Successfully opened our serial device");
tcgetattr(port->fd,&port->ser_oldtio); // save the current modem setting so we can restore them
tcgetattr(port->fd,&port->ser_newtio); // save the current modem settings to the new settings structure
cfmakeraw(&port->ser_newtio); // set struct for new term settings to raw. See man 'cfmakeraw'
port->ser_newtio.c_cflag &= ~CRTSCTS; // make sure rts/cts flow control is turned off
port->ser_newtio.c_cflag |= (CLOCAL | CREAD); // make sure receiver is enabled and port owner not changed
port->ser_newtio.c_iflag &= ~(IXON | IXOFF | IXANY);// make sure software flow control is off
cfsetispeed(&port->ser_newtio, port->ser_speed); // set the input baudrate for new terminal settings
cfsetospeed(&port->ser_newtio, port->ser_speed); // set the output baudrate for new terminal settings
tcflush(port->fd, TCIOFLUSH); // clear the input and output port buffers
tcsetattr(port->fd,TCSANOW,&port->ser_newtio); // set the new attributes for the serial port immediately
tcgetattr(1,&port->ser_old_stdout_tio); // we gotta do this - there is a Linux bug
tcsetattr(1,TCSANOW,&port->ser_newtio); // make stdout settings like modem settings
tcgetattr(0,&port->ser_oldstdtio); // get stdin settings for restoration ...
tcgetattr(0,&port->ser_newstdtio); // ... and use them as a basis for changes
port->ser_newstdtio.c_lflag &= ~(ICANON | ECHO); // make them raw
tcsetattr(0,TCSANOW,&port->ser_newstdtio); // set the new attributes immediately
port->comm_status = COMM_OK; //we really need some error checing on all of the above calls ...
}
if (port->fd < 0)
{
logger(logfile, "ERROR -- 2b Could not open our serial device");
perror(port->dev);
exit(-1);
}
//set the serial port to return immediately after a read
fcntl(port->fd, F_SETFL, O_NONBLOCK);
//if we are using an RF95A the RTS line must be disabled (low)
if (environment->RF_MODEM_95A == 1)
{
ioctl(port->fd, TIOCMGET, &port->modem_line);
port->modem_line &= ~TIOCM_RTS;
ioctl(port->fd, TIOCMSET, &port->modem_line);
} /* end if */
return(retval);
} /* end open_client_serial_port */