LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2005, 01:22 PM   #1
ttumelty
LQ Newbie
 
Registered: Apr 2004
Distribution: Slackware & Gentoo & Ubuntu
Posts: 22

Rep: Reputation: 15
Serial Port : How do I raise DTR


How do i raise DTR for a serial port application?

I think I am confused about using and's, or's .



The Posix Serial Port How-To shows how to lower DTR :

#include <unisdt.h>
#include <termios.h>

int fd
int status;


ioctl(fd, TIOCMGET,&status );

status &= ~TIOCM_DTR;

ioctl( fd, TIOCMSET, &status );



I woud really appreciate it if anyone could help with this.


thanks in advance,
Tom
 
Old 08-25-2005, 04:08 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Code:
/* Parameter "level" should be zero or non-zero for
 * setting to low or high resp.
 * Assumes fd is a global open filedescriptor
 * variable to a serial device.
 */
int setDTR(unsigned short level)
{
    int status;

    if (ioctl(fd, TIOCMGET, &status) == -1) {
        perror("setDTR()");
        return 0;
    }
    if (level) {
        status |= TIOCM_DTR;
    } else {
        status &= ~TIOCM_DTR;
    }
    if (ioctl(fd, TIOCMSET, &status) == -1) {
        perror("setDTR");
        return 0;
    }
    return 1;
}

Last edited by Hko; 08-25-2005 at 04:12 PM.
 
Old 08-25-2005, 05:54 PM   #3
ttumelty
LQ Newbie
 
Registered: Apr 2004
Distribution: Slackware & Gentoo & Ubuntu
Posts: 22

Original Poster
Rep: Reputation: 15
Thank You!!


So it looks like I can assume to lower a value (x) always use something like :

x &= ~y


and to raise a value (x) use :
x |= Y
 
Old 08-26-2005, 04:17 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally posted by ttumelty
So it looks like I can assume to lower a value (x) always use something like :

x &= ~y

and to raise a value (x) use :
x |= Y
Well yes, sort of. Keep in mind though that this is about the bits, zeroes and ones. If y == 7, there will be 3 bits set to '1' (high). So x |= y will set 3 bits in 'x' to high. The included header that #defines TIOCM_DTR is a bit-mask, with 1 bit set to '1'.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux serial port to router console port connection? frankie_fix Linux - General 3 02-26-2007 09:32 PM
Using serial port card(PCMCIA) with IPAQ running Linux, can't find ttyS0 port d2army Linux - Laptop and Netbook 0 11-12-2005 08:07 PM
Using an USB port as a standard DB9 Serial Port Lsteele Linux - Newbie 1 10-22-2005 09:48 AM
DTR on async port iftiuk Linux - Software 0 05-19-2004 02:15 PM
Serial Port Help puma Linux - Hardware 9 09-04-2003 07:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration