[uClinux-dev] Controlling DTR

Tom Walsh tom at cyberiansoftware.com
Wed Nov 28 11:45:18 EST 2001

> Rob Norman wrote:
> Hi.
> I'm talking to a wireless modem that requires DTR and I'm  feeling a
> bit stuck being new to Linux and not familiar with serial
> control protocols.  I've got code that talks to the serial ports of my
> uCdimm but cannot figure out how to control the DTR  which is sitting
> at ground.  I've looked at code examples in minicom but can't
> decipher  what options are appropriate to my module.  I'm on a tight
> schedule and would appreciate some help here.
> I'm using system IO to talk to the modem --- open, read write.  Is
> there a better way to access my modem?

No, you should be ok with the standard file streams..  Did you look at
the termios functions?  These are used to set options within the device
and govern behavior of the driver code.  Try a 'man termios', that
documents the modem / serial control functions.  You need to do
something like this to manipulate the settings:

============================= begin ====================

#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <limits.h>
#include "timeclock.h"
extern char * SerialPortName;
static struct termios SerialOptions, OldSerialOptions;
static FILE * SerialPort;
static int  SerialPortNo;
static char Line [MAXLINE+1];
static int  LineIdx = 0;
int OpenSerialPort (void)
   if ((SerialPort = fopen (SerialPortName, "r+")) == NULL) {
      fprintf (stderr, "Failed to open %s\n", SerialPortName);
      return 0;
   SerialPortNo = fileno (SerialPort);
   tcgetattr (SerialPortNo, &OldSerialOptions);
   tcgetattr (SerialPortNo, &SerialOptions);
   memset (&SerialOptions, 0, sizeof (SerialOptions));
      /* set to 8n1 */
   SerialOptions.c_cflag |= (CS8 | CREAD | CLOCAL);
   SerialOptions.c_iflag |= (IGNPAR | IGNBRK | IGNCR);
   SerialOptions.c_oflag = 0;
      /* set baudrate. */
   SerialOptions.c_ispeed = B2400;
   SerialOptions.c_ospeed = B2400;
   cfsetispeed (&SerialOptions, B2400);
   cfsetospeed (&SerialOptions, B2400);
      /* turn off CANONICAL mode */
   SerialOptions.c_lflag = 0;
      /* access single char at a time */
   SerialOptions.c_cc[VTIME] = 0;
   SerialOptions.c_cc[VMIN] = 0;
   tcsetattr (SerialPortNo, TCSANOW, &SerialOptions);
      /* set the queue variables. */
   LineIdx = 0;
   return 1;
void CloseSerialPort (void)
   tcsetattr (SerialPortNo, TCSANOW, &OldSerialOptions);

======================= snip =================================

The above code should work on uClinux as well (or a reasonable
rewrite).  This is all contigient upon the serial driver code being able
to assert a DTR!  Check the source for the driver and see if it mentions
DCE / DTR anyplace.


> Thanks in advance
> Robert Norman
>  www.acpropulsion.com

Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/

More information about the uClinux-dev mailing list