C
collinm
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?
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?