The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
CRC Code namrata5 High Level Programming 3 10-08-2007 07:01 AM
how i prepare a c++ code(c code) for implementing my own protocol format amitpansuria High Level Programming 1 09-06-2007 08:09 PM
SSH key code versus server key code Texan Security 1 04-12-2006 08:57 AM
Return code from PL/SQL Code Shaz UNIX for Advanced & Expert Users 7 06-03-2003 07:56 AM
code help bb00y High Level Programming 3 10-12-2002 05:45 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-13-2006
Registered User
 

Join Date: Jul 2006
Posts: 1
How to set the DSR pin using a C Code

Hi,
I am a newbie using linux. I want to use the 9 pins of the COM port for data transmission. I am trying to write a code to toggle the DTR pin in /dev/ttyS0.

Can any one help by giving a sample code or links that will help me pick up fast

Regards
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-14-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Good question. It's very hard to know where to look to find this out.
Code:
#include <sys/ioctl.h>
#include <termios.h>
#include <linux/serial.h> 
#include <fcntl.h>
#include <stdio.h>

int setdtr (int fd, int on)
{
  int controlbits = TIOCM_DTR;
  if(on)
    return(ioctl(tty_fd, TIOCMBIC, &controlbits));
  else
    return(ioctl(tty_fd, TIOCMBIS, &controlbits));
} 

int main()
{
  const char *dev="/dev/ttyS0";
  int fd=open(dev,O_RDWR);
  if(fd<0)
  {
    fprintf(stderr,"Couldn't open %s\n",dev);
    return(1);
  }

  fprintf(stderr,"Setting DTR\n");
  setdtr(fd,1);

  // Pause for three seconds
  sleep(3);

  fprintf(stderr,"Clearing DTR\n");
  setdtr(fd,0);

  close(fd);
  return(0);
}
No special libraries should be needed.

For more detail refer to the source I found here
Reply With Quote
  #3 (permalink)  
Old 07-16-2006
Registered User
 

Join Date: May 2006
Posts: 95
man 4 tty_ioctl

the example at the end of the page handles dtr (linux man pages)
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0