By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Linux Serial port setting for turning DTR off

100+
P: 158
Hello Bytes,

I am writing a program in Linux Debian x86 to control a module.

My only problem is that the module needs to have the DTR setting and all flow control off. I have been unable to figure out how to do this.

This is how ive configured my port settings thus far:

Any ideas??

Expand|Select|Wrap|Line Numbers
  1.  
  2.      fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
  3.  
  4.     if ( fd == -1) // if open is unsucessful
  5.     {
  6.         perror("open_port: Unable to open /dev/ttyUSB0 - ");
  7.     } else {
  8.         fcntl( fd, F_SETFL, 0);
  9.     }
  10.  
  11.     struct termios port_settings; // structure to store the port settings in
  12.  
  13.     cfsetispeed(&port_settings, B57600); // set baud rates
  14.     cfsetospeed(&port_settings, B57600);
  15.  
  16.     port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
  17.     port_settings.c_cflag &= ~CSTOPB;
  18.     port_settings.c_cflag &= ~CSIZE;
  19.     port_settings.c_cflag |= CS8;
  20.  
  21.     tcsetattr( fd, TCSANOW, &port_settings); // apply the settings to the port
  22.  
  23.  
Aug 31 '10 #1
Share this Question
Share on Google+
3 Replies


Oralloy
Expert 100+
P: 983
I think you want the function ioctl().
Aug 31 '10 #2

100+
P: 158
This is what ive come up with.

After I do my port setting i use ioctl():

Expand|Select|Wrap|Line Numbers
  1.     //status &= ~TIOCM_DTR;
  2.     //status &= ~TIOCM_CTS;
  3.  
  4.     status |= TIOCM_DTR;
  5.     status |= TIOCM_CTS;
  6.  
  7.     ioctl(fd, TIOCMSET, &status);
  8.  
  9.  

Neither low or high bit status for TIOCM_DTR seems to work though?

Is this the right way?
Sep 1 '10 #3

Oralloy
Expert 100+
P: 983
@kardon33,

You might need to look on the Debian site. Here are three good references for ioctl:

http://linux.die.net/man/2/ioctl

http://linux.die.net/man/2/ioctl_list

And here is the ioctl tty driver reference from the same site:

http://linux.die.net/man/4/tty_ioctl

I'm pretty sure the last one is what you need.
Sep 1 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.