Problem to read on a serial port

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

  • Next message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"
    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


  • Next message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Problem to read on a serial port"

    Relevant Pages

    • [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)
    • Re: Serial port cominication problem in linux
      ... I am having problem comunication with serial port in linux. ... I'm not sure what "HSM" means... ... int main ... Or you can disable the timer entirely, ...
      (comp.os.linux.development.apps)