[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
him ([email protected])

thanks,
Ferg


--- Forwarded mail from [email protected]

From: [email protected]
To: [email protected]
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.

Regards,
Dan Wu


Hello, Peter,

     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
directly.
There's bi-directional data transfer between the modem and the PC. The max
speed
for the modem is 14.4kbps, the modem sends out the data (to another
device)
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
PC to
the modem to go through correctly. The flow control does work, and the
data
transfer from PC to modem direction has no problem, however it looks when
flow
control kicks in, the data transfer from modem to PC direction is affected
and
around 200 bytes of data will get lost. If I do one-way transfer only,
modem to
PC direction won't have any problem. It didn't have any problem either
before I
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
receive
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
reply.

Sincerely,
Dan Wu

             // Setup serial connection with all devices.
        for( i = 0; i < num_devs; i++ )
        {
                // Assemble device path from dev parameter and open
device.
                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 );
                }
                else
                {
                        // Configure serial port using termios struct.
                        termios_buf.c_lflag &= ~(ECHO | ICANON | IEXTEN |
ISIG);
                        termios_buf.c_iflag &= ~(ECHO | ICANON | IEXTEN |
ISIG);

                        termios_buf.c_oflag &= ~(ECHO | ICANON | IEXTEN |
ISIG);

                        termios_buf.c_cflag &= ~(ICANON );
                        termios_buf.c_iflag &= ~(BRKINT | ICRNL |IGNCR|
INPCK
|ISTRIP | IXON);
                        termios_buf.c_cflag &= ~(CSIZE | PARENB );
                        termios_buf.c_cflag |= CS8;
                //      termios_buf.c_lflag |= NOFLSH;
                        termios_buf.c_cflag |= CRTSCTS;  /* enable
hardware flow
 control */

                        termios_buf.c_cflag &= ~(HUPCL);
                        termios_buf.c_oflag &= ~(OPOST);        /* add
ONLCR */
                        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",
dev_path
);
                                return;
                        }
                        if( cfsetospeed( &termios_buf, B57600 ) < 0 )
                        {
                                pError( "Cannot set ospeed for %s\n",
dev_path
);
                                return;
                        }
                        if( tcsetattr( fd, TCSAFLUSH, &termios_buf ) < 0 )
                        {
                                pError( "Cannot set termios structure for
%s\n",
 dev_path );
                                return;
                        }
                        if( tcflush( fd, TCIOFLUSH ) < 0 )
                        //if( tcdrain( fd ) < 0 )
                        {
                                pError( "Error flushing I/O buffers,
errno=%d\n", errno );
                                return;
                        }

                        // If this far, serial connection is established.

                        //  Write modem configuration string to port.
                        char at_string[50];
                        // &f1 sets modem to factory defaults with
hardware flow
 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
to
DTE.
                        // *v2=3 forces modem to always make an analog
outgoingcall.
                        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
        }//for


---End of forwarded mail from [email protected]


--  
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]