How to set the DSR pin using a C Code


 
Thread Tools Search this Thread
Top Forums Programming How to set the DSR pin using a C Code
# 1  
Old 07-13-2006
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
# 2  
Old 07-14-2006
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
# 3  
Old 07-16-2006
man 4 tty_ioctl

the example at the end of the page handles dtr (linux man pages)
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pin code counter

hello i wanted to see if anyone can analyze the following code and see where the error lies. it is supposed to echo the current date and start counting from 0000-9999 and show the approximate range that it is at. here is a pic of what the output should look like:... (3 Replies)
Discussion started by: Kooftness
3 Replies

2. IP Networking

Source IP address field in RREP on DSR routing

Hello I have a question about routing in MANET using Dynamic Source Routing protocol. IN RFC4728 (DSR) in section "IP fields" of RREP (Route Reply) packet we have this: ok. I read in several books and also in rfc4728 that: when a source node (node that initiate route discovery process)... (1 Reply)
Discussion started by: acu281
1 Replies

3. IP Networking

How to configure RHEL6 to support Aleton 4408 in DSR mode?

Dears How to configure RHEL6 to support Aleton 4408 in DSR(Direct Server Return) mode We have config Aleton 4408 + Windows 2008R2 then Windows set loopback interface with VIP. the exec the following command in CMD netsh interface ipv4 set interface "net" weakhostreceive=enabled netsh... (0 Replies)
Discussion started by: nnnnnnine
0 Replies

4. Homework & Coursework Questions

regarding adding fields to DSR protocol in ns2.34

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: want to add field to route cache and packet of DSR routing protocol in ns2.34, add field, DSR package in ns2.34... (2 Replies)
Discussion started by: khubalkar
2 Replies

5. Programming

regarding adding fields to DSR protocol in ns2.34

hi i am student doing project in ns2.34. i hav to add field in route cache and packet of DSR routing protocol. which files hv to be changed...pl help me (1 Reply)
Discussion started by: khubalkar
1 Replies

6. Programming

Need pin generation code

Hi Can any one tell me from where can i get the code/library(c/c++(Sun)) for PIN generation. Actually i need to generate a new PIN for the user in case sombody reset his PIN. Thanks in Advance. (1 Reply)
Discussion started by: unisuraj
1 Replies

7. Programming

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 (2 Replies)
Discussion started by: Swing5
2 Replies

8. UNIX Desktop Questions & Answers

Pin to desktop

Hello everybody! I need some help. Is there a way to pin a window to the desktop in Linux? I have a list of tasks in Calc. And I want the window of Calc to be always before my eyes, so that it sort of reminds me of my tasks. The window must be «stuck» to the desktop, and when I click the... (0 Replies)
Discussion started by: alex777
0 Replies
Login or Register to Ask a Question