immediate receiving of data from serial interfaces
From: Rüdiger Ranft (_rdi__at_web.de)
Date: 05/26/05
- Next message: Mathias Heier: "Removing 'CardServices' from wlan-driver"
- Previous message: saee: "Re: Error: Invalid Module format"
- Next in thread: Grant Edwards: "Re: immediate receiving of data from serial interfaces"
- Reply: Grant Edwards: "Re: immediate receiving of data from serial interfaces"
- Reply: Grant Edwards: "Re: immediate receiving of data from serial interfaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 May 2005 13:59:34 +0200
Hi *,
I want to connect to a microcontroller based device using the serial
interface. So I took the samples in the serial programming HowTo to get
started. My problem is that the controller sends continuously data
without some '\n' chars, but the program does only get the data when a
newline occured.
So what must I do to get notificated (a latancy <10ms is acceptable)
after the interface received some chars? Since minicom can do the things
I want there must be a way to get it work.
TIA
Rudi
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
stty -F /dev/ttyS5
speed 38400 baud; line = 0;
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof =
<undef>;
start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>;
werase = <undef>; lnext = <undef>; flush = <undef>; min = 1; time = 5;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
setserial /dev/ttyS5
/dev/ttyS5, UART: 16550, Port: 0x0288, IRQ: 5, Flags: Fourport
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#define BAUDRATE B38400
#define MODEMDEVICE "/dev/ttyS5"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
char buf[255];
int main()
{
int fd,c, res;
struct termios oldtio,newtio;
fd_set fds; /* Zu überwachende FDs */
int maxfd; /* Nummer des höchsten FDs */
fd = open(MODEMDEVICE, O_RDWR | O_NONBLOCK | O_NOCTTY );
if (fd <0) {
perror(MODEMDEVICE);
exit(-1);
}
maxfd = fd + 1;
tcgetattr(fd,&oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CS8 | /*CLOCAL |*/ CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 5;
newtio.c_cc[VMIN] = 1;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
while (STOP==FALSE)
{
FD_SET( 0, &fds ); /* stdin */
FD_SET( fd, &fds ); /* Handle der Schnittstelle*/
select( maxfd, &fds, NULL, NULL, NULL );
if ( FD_ISSET( fd, &fds ) )
{
/* loop for input */
res = read(fd,buf,255);
/*if (res > 0)*/
{
buf[res]=0;
printf("%s", buf );
}
}
if ( FD_ISSET( 0, &fds ) )
{
tcflush( 0, TCIFLUSH );
STOP=TRUE;
}
}
tcsetattr(fd,TCSANOW,&oldtio);
}
-- GPG encrypted mails preferred. GPG verschlüsselte Mails bevorzugt. ---> https://dsred.ccc.de/085/tkuev <----
- Next message: Mathias Heier: "Removing 'CardServices' from wlan-driver"
- Previous message: saee: "Re: Error: Invalid Module format"
- Next in thread: Grant Edwards: "Re: immediate receiving of data from serial interfaces"
- Reply: Grant Edwards: "Re: immediate receiving of data from serial interfaces"
- Reply: Grant Edwards: "Re: immediate receiving of data from serial interfaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|