Hi Jerry,

yes I wrote a user space RS485 'driver' for a RS232/RS485 converter and a
single (!) RS485 device (Philips KS20). It is a very simple routine:


    fd=open(Device,O_RDWR|O_NOCTTY);    //open serial device
    tcgetattr(fd,&Oldtio); // save old attributes
    tcflush(fd,TCIOFLUSH); // empty 'trashbin'
    tcsetattr(fd,TCSANOW,&Newtio);
    aLSR=0; aMCR=TIOCM_RTS;
    if(ioctl(fd,TIOCMBIS,&aMCR)==-1) // Turn on RTS
        fprintf(stderr," (RTS=1 FEHLER)");

    res=write(fd,vString,KS20CommLength); // KS20 command length = 17

    while(1)      // wait for empty TSR
     { 
      ++u;
      if(ioctl(fd,TIOCSERGETLSR,&aLSR)==-1) {
        fprintf(stderr," (GETLSR FEHLER!)");
        break;
      }
      if(aLSR) break;       // TSR is empty
      usleep(3000UL);     // sleep for 3 ms (1/BAUDRATE*3)
     }

    if(ioctl(fd,TIOCMBIC,&aMCR)==-1) // Turn off RTS
     fprintf(stderr," (RTS=0 FEHLER)");

    res=read(fd,retString,100);

    tcsetattr(fd,TCSANOW,&Oldtio);
    close(fd);



This is cut'n'paste (partially) of my routine.
The KS20 answers after it gets a command with definit length. I experienced
a delay of 3 loops  = around 9 milliseconds. But perhaps you may tune the
while(1)-loop and the nice-level of the process. Beware that the
TIOCGETLSR does _not_ return the whole LSR, but a flag if the transmit shift
register (TSR) is empty.



hth,


    Michael


-
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to [EMAIL PROTECTED]

Reply via email to