Problem to read on a serial port
From: collinm (collinm_at_laboiteaprog.com)
Date: 03/30/05
- Previous message: jdunphy: "looking for AIX cmd"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Mar 2005 08:02:14 -0800
hi
i need to read from a serial port (c programming)
we use a sixnet Mini-VersaTRAK mIPm
http://www.sixnetio.com/html_files/products_and_groups/mipm_vt.htm
under bash:
~ # stty -a </dev/ttyS2
speed 9600 baud; rows 0; columns 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; flush = ^U; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon
-ixoff -iuclc -ixany -imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0
vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop
-echoprt echoctl echoke
i send a command via serial port to a led display (alpha sign
communications)
void ledDisplayExist()
{
char msg[]={'\0', '\0', '\0', '\0', '\0', '\1', 'Z', '0', '0',
'\2', 'H', 'A', '\4' };
int length = sizeof(msg);
writeopen(msg, length);
readopen();
}
i write msg with this function:
int writeopen(char msg[], int size)
{
printf("write\n");
int fd1;
int wr;
fd1 = open(ledisplay, O_RDWR | O_NOCTTY | O_NDELAY );
if (fd1 == -1)
fprintf(stderr, " %s open_port: Unable to open %s\n",
strerror(errno), ledisplay);
else
{
fcntl(fd1, F_SETFL, 0);
wr=write(fd1, msg, size);
if (wr < 0)
fputs("write() of n bytes failed!\n", stderr);
close(fd1);
}
return (fd1);
}
i try to read with this function:
int readopen()
{
printf("read\n");
int fd1;
int rd;
char buff[255];
fd1 = open(ledisplay, O_RDWR | O_NOCTTY | FNDELAY );
if (fd1 == -1)
fprintf(stderr, "%s open_port: Unable to open %s\n",
strerror(errno), ledisplay);
else
{
fcntl(fd1, F_SETFL, FNDELAY);
printf(" Port 1 has been sucessfully opened and %d is the file
descriptor\n",fd1);
rd=read(fd1, buff, 20);
printf(" Bytes recieved are %d \n",rd);
close(fd1);
}
return (fd1);
}
that return always return me: Bytes recieved are -1 (i write without
problem, the problem is the read)
any idea?
thanks
- Previous message: jdunphy: "looking for AIX cmd"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|