Linux Serial port setting for turning DTR off

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kardon33
    New Member
    • May 2007
    • 158

    Linux Serial port setting for turning DTR off

    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??

    Code:
         fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
    
        if ( fd == -1) // if open is unsucessful
        {
            perror("open_port: Unable to open /dev/ttyUSB0 - ");
        } else {
            fcntl( fd, F_SETFL, 0);
        }
    
        struct termios port_settings; // structure to store the port settings in
    
        cfsetispeed(&port_settings, B57600); // set baud rates
        cfsetospeed(&port_settings, B57600);
    
        port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
        port_settings.c_cflag &= ~CSTOPB;
        port_settings.c_cflag &= ~CSIZE;
        port_settings.c_cflag |= CS8;
    
        tcsetattr( fd, TCSANOW, &port_settings); // apply the settings to the port
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    I think you want the function ioctl().

    Comment

    • kardon33
      New Member
      • May 2007
      • 158

      #3
      This is what ive come up with.

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

      Code:
          //status &= ~TIOCM_DTR;
          //status &= ~TIOCM_CTS;
      
          status |= TIOCM_DTR;
          status |= TIOCM_CTS;
      
          ioctl(fd, TIOCMSET, &status);

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

      Is this the right way?

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        @kardon33,

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





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



        I'm pretty sure the last one is what you need.

        Comment

        Working...