Problem to read and write on a serial port
From: collinm (collinm_at_laboiteaprog.com)
Date: 03/29/05
- Next message: Walter Roberson: "Re: How do I wait for the child process ?"
- Previous message: Default User: "Re: How to free this memory?"
- Next in thread: Walter Roberson: "Re: Problem to read and write on a serial port"
- Reply: Walter Roberson: "Re: Problem to read and write on a serial port"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read and write on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Mar 2005 12:15:36 -0800
hi
i send a command to a led display, the led display is suppose to return
me some character
i write a string on a serial port
void ledDisplayExist()
{
char msg[]={'\0', '\0', '\0', '\0', '\0', '\1', 'Z', '0', '0',
'\2', 'H', 'B', '\4' };
int length = sizeof(msg);
writeopen(msg, length);
readopen();
}
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);
}
after i read on the serial port:
int readopen()
{
printf("read\n");
int fd1;
int rd;
char *buff=NULL;
fd1 = open(ledisplay, O_RDONLY | 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);
printf(" Port 1 has been sucessfully opened and %d is the file
descriptor\n",fd1);
rd=read(fd1, buff, 30);
printf(" Bytes recieved are %d \n",rd);
close(fd1);
}
return (fd1);
}
the string returned by the led display is suppose to be something like:
<nul><nul><nul><nul><nul><soh>"000"<stx>"G234.3432"<etx>"0237<eot>
the lenght of the returned string is under 30 character...
when i run the prog, the prog display
port série utilisé: /dev/ttyS2
connection au led display
write
read
Port 1 has been sucessfully opened and 3 is the file descriptor
i wait a few second and nothing more is display.... i kill the program
any idea why i don't read correctly on the serial port?
- Next message: Walter Roberson: "Re: How do I wait for the child process ?"
- Previous message: Default User: "Re: How to free this memory?"
- Next in thread: Walter Roberson: "Re: Problem to read and write on a serial port"
- Reply: Walter Roberson: "Re: Problem to read and write on a serial port"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read and write on a serial port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|