Problem to read and write on a serial port

From: collinm (collinm_at_laboiteaprog.com)
Date: 03/29/05


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?



Relevant Pages

  • Re: how does this string look like
    ... >>code in visual basic to compose a string that is send to the serial port ... > int address; ...
    (alt.comp.lang.learn.c-cpp)
  • [PATCH 1/1] mxser, remove it
    ... -static int calloutmajor = MXSERCUMAJOR; ... * This routine is called whenever a serial port is opened. ... * enables interrupts for a serial port, linking in its async structure into ... * async structure from the interrupt chain if necessary, ...
    (Linux-Kernel)
  • RS232 Redirector Program in C using Linux
    ... developing linux aps as well as in the serial port), ... failed to get current settings ... the int handler ... nbytes = write; ...
    (comp.os.linux.development.apps)
  • Re: Class/structure/something else in class
    ... measurecurrent(channel as int) ... measureamp as this is just send a textstring to the serial port. ... Create a class for the Measure and ScanAdd properties, and make their constructors take either a reference to the serial port object or the parent object. ...
    (microsoft.public.dotnet.languages.vb)
  • [PATCH 5/6] Char: mxser_new, code upside down
    ... static int CheckIsMoxaMust ... * This routine is called to set the UART divisor registers to match ... * the specified baud rate for a serial port. ... * They enable or disable transmitter interrupts, ...
    (Linux-Kernel)