Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am writing a small code to control the DTR and RTS lines of USB to Serial port Converter chip FT232 on Linux (Mint Linux 13 Maya,x86).

I have successfully wrote code to read and write data to the FT232 chip using termios. Now i want to control the DTR and RTS lines so i am using ioctl() call to set and clear the DTR and RTS lines.

here is the code

XML
#include <stdio.h>
    #include <fcntl.h>       /* File Control Definitions           */
    #include <termios.h>     /* POSIX Terminal Control Definitions */
    #include <unistd.h>      /* UNIX Standard Definitions          */
    #include <errno.h>       /* ERROR Number Definitions           */
    #include <sys/ioctl.h>   /* ioctl()                            */

    main(void)
    {
        int fd;     /*File Descriptor*/
        int status;

        fd = open("/dev/ttyUSB0",O_RDWR | O_NOCTTY ); //Opening the serial port

        ioctl(fd,TIOCMGET,&status); /* GET the State of MODEM bits in Status */
        status |= TIOCM_RTS;        // Set the RTS pin
        ioctl(fd, TIOCMSET, status);

        getchar(); //To view the change in status pins before closing the port

        close(fd);
     }


The code compiles successfully on gcc without any errors.I have connected two leds to RTS and DTR lines of FT232.Since the RTS and DTR lines are inverted,setting RTS would make the LED off. Led's connected to RTS and DTR are intially ON.

On running the code using "sudo ./serial"

both RTS and DTR Led's go off, instead of just RTS (as coded status |= TIOCM_RTS;) and switch on after getchar().

Why is DTR going LOW along With RTS line?
also
I am not able to change the other modem lines like RI,DCD,DCD,DTR etc by using TIOCM_CD ,TIOCM_DTR etc?
Posted
Comments
CPallini 29-Dec-14 5:50am    
You have to explicitly disable flow control.

It seems that your device is configured for hand shaking by default. You can (and should) use tcsetattr to configure your device. You may also try to use the TIOCMBIS ioctl command to set the DTR and RTS state.

You can only set the state of the output pins RTS and DTR. The state of the input pins DCD, DSR, RI, and CTS can only be read.

You should read the Linux Serial HOWTO[^] and the Linux Serial Programming HOWTO[^].
 
Share this answer
 
thanks,
using TIOCMBIS ioctl command to set the DTR and RTS state solved the issue
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900