[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(Fwd) question about serial port programming
Can someone assist Dan Wu? Please respond directly to
--- Forwarded mail from Dan_Wu@3com.com
Date: Mon, 13 Nov 2000 16:18:27 -0600
Subject: question about serial port programming
Dear Linux HOWTO coordinator,
The email below was sent to Peter Baumann who wrote the
serial-programming-howto posted on your web site, but it was
returned because the email address he put in the article is
not right. Can you find his correct address for me, or forward
this email to some other experts in serial port programming?
Thanks a lot.
I read your article posted on redhat web site about the serial port
programming. I wonder if you can answer my question if you have some time.
There're serial cables connecting the serial ports and modems
There's bi-directional data transfer between the modem and the PC. The max
for the modem is 14.4kbps, the modem sends out the data (to another
slowlier than it receives data from the PC. So I enable the hardware flow
control on the serial port and the modem, in order for the data flow from
the modem to go through correctly. The flow control does work, and the
transfer from PC to modem direction has no problem, however it looks when
control kicks in, the data transfer from modem to PC direction is affected
around 200 bytes of data will get lost. If I do one-way transfer only,
PC direction won't have any problem. It didn't have any problem either
enabled flow control on the serial port. My question is: How does the flow
control affect the data flow from modem to PC? Is the data in the PC's
buffer flushed when flow control kicks in? Below is my code, can you see
anything wrong? Or any flag missing?
I would appreciate your kind help very much. Look forward to your earliest
// Setup serial connection with all devices.
for( i = 0; i < num_devs; i++ )
// Assemble device path from dev parameter and open
sprintf( dev_path, "/dev/ttyD%d", i );
fd = open( dev_path, O_RDWR | O_NOCTTY );
if( fd < 0 )
pError( "Unable to open device %s\n", dev_path );
// Configure serial port using termios struct.
termios_buf.c_lflag &= ~(ECHO | ICANON | IEXTEN |
termios_buf.c_iflag &= ~(ECHO | ICANON | IEXTEN |
termios_buf.c_oflag &= ~(ECHO | ICANON | IEXTEN |
termios_buf.c_cflag &= ~(ICANON );
termios_buf.c_iflag &= ~(BRKINT | ICRNL |IGNCR|
|ISTRIP | IXON);
termios_buf.c_cflag &= ~(CSIZE | PARENB );
termios_buf.c_cflag |= CS8;
// termios_buf.c_lflag |= NOFLSH;
termios_buf.c_cflag |= CRTSCTS; /* enable
termios_buf.c_cflag &= ~(HUPCL);
termios_buf.c_oflag &= ~(OPOST); /* add
termios_buf.c_cc[VMIN] = 0;
termios_buf.c_cc[VTIME] = 20;
if( cfsetispeed( &termios_buf, B57600 ) < 0 )
pError( "Cannot set ispeed for %s\n",
if( cfsetospeed( &termios_buf, B57600 ) < 0 )
pError( "Cannot set ospeed for %s\n",
if( tcsetattr( fd, TCSAFLUSH, &termios_buf ) < 0 )
pError( "Cannot set termios structure for
if( tcflush( fd, TCIOFLUSH ) < 0 )
//if( tcdrain( fd ) < 0 )
pError( "Error flushing I/O buffers,
errno=%d\n", errno );
// If this far, serial connection is established.
// Write modem configuration string to port.
// &f1 sets modem to factory defaults with
control. Without hardware flow
// control, data will be corrupted.
// e0 turns modem command echo to DTE off.
// q0 forces modem to return command result codes
// *v2=3 forces modem to always make an analog
strcpy( at_string, "at&f1eq*v2=3\r\n" );
tprintf( "writing modem configuration string %s to
device %d\n", at_string, i );
write( fd, at_string, strlen( at_string ) );
}// else fd < 0
---End of forwarded mail from Dan_Wu@3com.com
To UNSUBSCRIBE, email to email@example.com
with a subject of "unsubscribe". Trouble? Contact firstname.lastname@example.org