Subject: Serial Port Read/Write
To: None <netbsd-users@netbsd.org>
From: Alain Volmat <avolmat@ic.src.ricoh.co.jp>
List: netbsd-users
Date: 12/06/2000 17:05:30
Hi,
I'm trying to access the serial port from a very simple program. I'm using
NetBSD1.4.3 i386 and I would like the program return me the contents of the
serial port buffer / or 0 if there is no data.
I write this little program but every time the read function return -1.
I know that I use the correct port and also configuration is (I think
correct) because when I use write it works correctly.
Does anyone have an idea about that ??
Thanks in advance.
Alain Volmat
----------------------
#include<stdio.h>
#include<fcntl.h>
#include<errno.h>
#include<termios.h>
#include<malloc.h>
main()
{
int count;
int fd,i;
char *buff;
int buffsize = 255;
buff = (char*)malloc(255);
fd = open("/dev/tty00",O_RDWR | O_NOCTTY | O_NDELAY );
if( fd==-1)
perror("unable to open the port");
else
fcntl(fd, F_SETFL, FNDELAY);
count = read(fd,buff,(size_t)buffsize);
if(count < 0){
printf("read error!\n");
return 1;
}
for(i=0;i<count;i++)
printf("[read]%x %x\n",i,buff[i]);
close(fd);
}