Re: 8ms Timer for serial port access
From: Jens Schumacher (jens.schumache_at_gmx.net)
Date: 10/31/03
- Next message: David Schwartz: "Re: 8ms Timer for serial port access"
- Previous message: Jens Schumacher: "Re: 8ms Timer for serial port access"
- In reply to: Floyd Davidson: "Re: 8ms Timer for serial port access"
- Next in thread: Floyd Davidson: "Re: 8ms Timer for serial port access"
- Reply: Floyd Davidson: "Re: 8ms Timer for serial port access"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Oct 2003 22:38:38 -0500
Am 30/10/03 19:38 Uhr schrieb "Floyd Davidson" unter <floyd@barrow.com> in
87brry1bss.fld@barrow.com:
> There are some very good examples of how that should be done
> available on the Internet, but there are even more really bad
> examples. The Linux Serial-Programming-HOWTO is one of the less
> than quality examples...
OK here comes my code...thought it is a good one because it is recommended a
lot.
int serial_open(char *portName)
{
int fd = 0; // file descriptor
/* Close file if already open */
if (fd > 0) {
close(fd);
}
/* open the specified serial port in for read and write O_RDWR */
/* NO_CTTY makes it a non-controlling TTY. */
fd = open(portName, O_RDWR | O_NOCTTY );
if (fd < 0) {
perror(portName);
return -1;
}
/* Get current port configuration */
tcgetattr(fd, &(oldtio));
cfsetispeed(&newtio, B38400);
cfsetospeed(&newtio, B38400);
/* We've got baudrate. Add other options. */
newtio.c_cflag |= CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 10;
/* try and configure the port appropriately... */
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
serial_flush (fd);
return fd;
}
Thanks, Jens
- Next message: David Schwartz: "Re: 8ms Timer for serial port access"
- Previous message: Jens Schumacher: "Re: 8ms Timer for serial port access"
- In reply to: Floyd Davidson: "Re: 8ms Timer for serial port access"
- Next in thread: Floyd Davidson: "Re: 8ms Timer for serial port access"
- Reply: Floyd Davidson: "Re: 8ms Timer for serial port access"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|