Signal | DB-9 | DB-25 | Dir | Description |
---|---|---|---|---|
CD | 1 | 8 | IN | Carrier detect |
RD | 2 | 3 | IN | Read Data |
TD | 3 | 2 | OUT | Transmit Data |
DTR | 4 | 20 | OUT | Data Terminal Ready |
DSR | 6 | 6 | IN | Dataset Ready |
RTS | 7 | 4 | OUT | Request to Send |
CTS | 8 | 5 | IN | Clear to Send |
RI | 9 | 22 | IN | Ring indicator |
GND | 5 | 7 | --- | Ground |
Coming maybe later - but I think you figure the basics out for yourself
Yes, this also works for USB-to-RS232 converters! (At least with those that implement the control lines...)
#include <stdio.h>
#include <fcntl.h> /* open(), O_RDWR */
#include <sys/ioctl.h> /* ioctl(), TIOCMGET, TIOCM_CD, ... */
#define DEVICE "/dev/usb/tts/0"
/* according to EIA-232, RX and TX uses negative logic, i.e.
0 is represented by +3 .. +12V and 1 is represented by -3 .. -12V
the control lines use positive logic, so +3 .. +12V means "active"
and -3 .. -12V means "inactive" */
int read_status_pins(int fd)
{
int i;
ioctl(fd, TIOCMGET, &i);
if ((i & TIOCM_CD) == TIOCM_CD) { /* Pin DCD */
printf("DCD = high (3..12V)\n");
} else {
printf("DCD = low (0..-12V)\n");
}
/*
if ((i & TIOCM_DSR) == TIOCM_DSR) // Pin DSR
if ((i & TIOCM_CTS) == TIOCM_CTS) // Pin CTS
if ((i & TIOCM_RI ) == TIOCM_RI) // Pin RI
*/
return 0;
}
int write_status_pins(int fd)
{
int i = 0;
i |= TIOCM_RTS; // Pin RTS wird aktiviert (12V)
i |= TIOCM_DTR; // Pin DTR wird aktiviert (12V)
ioctl(fd, TIOCMBIS, &i);
i |= TIOCM_RTS; // Pin RTS wird deaktiviert (-12V)
i |= TIOCM_DTR; // Pin DTR wird deaktiviert (-12V)
ioctl(fd, TIOCMBIC, &i);
return 0;
}
int set_tx_pin(int fd)
{
return ioctl(fd, TIOCSBRK, NULL);
}
int clear_tx_pin(int fd)
{
return ioctl(fd, TIOCCBRK, NULL);
}
int main(int argc, char **argv)
{
int fd;
if ((fd = open(DEVICE, O_RDWR)) <= 0) {
printf("couldn't open serial device %s\n", DEVICE);
return 10;
}
/* put example testing code here */
close(fd);
return 0;
}