Here's a code snippet that sets the serial port to 9600 baud and reads
one character at a time....
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
void setline(int fd, int flags, int speed)
{
struct termios t;
tcgetattr(fd, &t);
t.c_cflag = flags | CREAD | HUPCL | CLOCAL;
t.c_iflag = IGNBRK | IGNPAR;
t.c_oflag = 0;
t.c_lflag = 0;
t.c_cc[VMIN ] = 1;
t.c_cc[VTIME] = 0;
cfsetispeed(&t, speed);
cfsetospeed(&t, speed);
tcsetattr(fd, TCSANOW, &t);
}
int main(int argc, char **argv)
{
int fd;
char c;
if ((fd = open("/dev/ttySA0", O_RDWR | O_NOCTTY )) < 0) {
perror("unable to open serial device");
return 1;
}
setline(fd, CS8, B9600);
while (read(fd,&c,1)>0)
printf("%x\n",c);
close(fd);
return 0;
}
Andrew
======
andyc@handhelds.org
Kwan Hong Lee wrote:
>
> Hi,
>
> I am trying to read continuous text stream on the iPaq serial port.
> First
> of all, can I read data in any other rate than 115200 bps? Does anybody
> have a sample code that just reads data or do a text chat session
> between
> iPaq and desktop over the serial port? I have tried out the examples in
> serial howtos but wasn't able to get them working, so I am asking for
> some
> help from the experienced.
>
> Thank you very much in advance.
>
> -kwan
>
> _______________________________________________
> Handhelds mailing list
> Handhelds@handhelds.org
> http://handhelds.org/mailman/listinfo/handhelds
Received on Thu Apr 12 11:39:49 2001
This archive was generated by hypermail 2.1.8 : Tue May 04 2004 - 09:42:22 EDT