![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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);
}
For more detail refer to the source I found here |