in reply to Writing to serial port with a delay between each character

It looks like you are using Device::SerialPort as your serial port management module. Please correct me if that's wrong. That kind of information can really be helpful in diagnosing your problem.

Does the device to which you're sending data handle rts/cts signals? If so, get it to send you a clear-to-send and send a character only once that's received. Lowering your baud rate to something that guarantees your characters don't go faster may help, too.

  • Comment on Re: Writing to serial port with a delay between each character

Replies are listed 'Best First'.
Re^2: Writing to serial port with a delay between each character
by sidthakur (Initiate) on Apr 21, 2009 at 18:55 UTC
    Thanks for the response. To answer your questions

    1. Yes I am using Device::SerialPort. Should have mentioned that before.
    2. The device does not do any flow control RTS/CTS. So that option is out
    3. I could lower the baud rate, but its a significant task on the system, since it is not entirely in my control.
    Thanks
      You can get a count of how many characters (under Linux at least) with the TIOCOUTQ function. Search the module's docs for that. You may be able to keep from flooding the device by keeping your own buffer (which it seems you already do) and only writing when the Device::SerialPort buffer is empty.

      You might also want to look into setting the mode to 'raw', but I'm not sure if that actually bypasses buffers or not. You could also look into the write_drain method which seems to go ahead and flush the transmit buffer. You could try calling that after every character you write.

      I've only done rudimentary work with the module, and I've never had to deal with such a limited device on the other end. YMMV, but I hope some of this babbling helps.