How to read the CTS and DSR of RS232 in Unix using C language? | Unix Linux Forums | Programming

  Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

How to read the CTS and DSR of RS232 in Unix using C language?

Programming


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-04-2003
Swing5 Swing5 is offline
Registered User
 
Join Date: Dec 2003
Last Activity: 15 January 2004, 1:15 PM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How to read the CTS and DSR of RS232 in Unix using C language?

Hello to all Gurus out there,
Could you show me a source code in Unix platform using C language. I want to read the status or voltage level of the DSR and CTS.

Thanks a lot,

Swing5
Sponsored Links
    #2  
Old 12-05-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 20 August 2014, 3:57 PM EDT
Location: Ashburn, Virginia
Posts: 9,919
Thanks: 59
Thanked 427 Times in 255 Posts
Please click on the rules link at the bottom of the page. I have deleted your other thread.

You're not going to be able to do what you want. Use the command "man termios" to see what is available from the terminal driver. Use our search function to searc this forum to see some examples of termios in use.

In you have the hardware, you can use modem control signals, but the driver does it on your behalf. For an incoming line, a open() call raises DTR which signals the modem that it may auto-answer a call. When it does, it will raise DSR which causes the open to complete. If DSR drops, a hup signal is generated. A very clever program might be able to use all of this to "read" the state of the DSR signal. But open() is an expensive system call and the bandwidth would be low.

Some unix systems (maybe most? or all?) you can use CTS for hardware flow control of output, and RTS for hardware flow control of input. There is no hope for RTS, but a clever program might be able to determine the state of CTS by seeing if a non-blocking write() succeeds. But DSR would need to be high.

You might be able to have a simple switch send a break character. Anyone who uses a Sun with a terminal console knows how easy that is. You can arrange for a break character to send an INT signal to the program.
Sponsored Links
    #3  
Old 04-01-2009
nomist nomist is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 1 April 2009, 12:46 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Something like the following will probably do the trick:

Code:
bool getCTS(int fd)
{
    int s;
    /* Read terminal status line: Clear To Send */
    ioctl(fd, TIOCMGET, &s);
    return (s & TIOCM_CTS) != 0;
}
bool getDSR(int fd)
{
    int s;
    /* Read terminal status line: Data Set Ready */
    ioctl(fd, TIOCMGET, &s);
    return (s & TIOCM_DSR) != 0;
}

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help to filter read through reference file by using c language cpp_beginner Programming 14 07-28-2011 12:14 PM
Can A File Be Copied to an RS232 Port on Unix? alivebyscience UNIX for Dummies Questions & Answers 2 09-01-2009 07:05 PM
rs232 pci-card pressy Solaris 1 11-06-2004 10:02 PM
VNC via Rs232 joerg UNIX for Advanced & Expert Users 2 08-14-2002 05:22 AM
RS232 communication optimisation ManishSaxena Programming 1 04-04-2002 08:25 AM



All times are GMT -4. The time now is 12:20 AM.