Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Reading data from the Serial Port

by BrowserUk (Patriarch)
on Aug 01, 2002 at 00:43 UTC ( [id://186648] : note . print w/replies, xml ) Need Help??


in reply to Reading data from the Serial Port

There are a lot of assumptions (on my behalf) inferred from the information you have given us.

14 bytes sounds like the default FIFO buffer size for COMn: ports (under win32 anyway).

That you get the first 14 bytes and no more suggests that some form of handshaking is involved. That it isn't being reset automatically means that it (the comm port) is probably set up for software (Xon/Xoff) handshaking.

If you are on a win32 system, the easiest way to verify this would be to open a CMD window and issue the command:

C:\test>mode com1 /STATUS Status for device COM1: ----------------------- Baud: 1200 Parity: Even Data Bits: 7 Stop Bits: 1 Timeout: OFF XON/XOFF: OFF CTS handshaking: OFF DSR handshaking: OFF DSR sensitivity: OFF DTR circuit: ON RTS circuit: ON C:\test>

That was from the (currently inactive) com1 on my NT system.

If you are simply reading from the port and want to 'slurp' as much as possible, you could use the control-panel->ports (or the mode command (see help mode) to switch the handshaking off.

This isn't going to help much if the device attached to the other end needs the hadshaking though. If the device is waiting for you to empty the buffer, and has recieved an Xoff (ascii 14?) ... it will be waiting for an Xon (ascii 15?). Maybe just writing the appropriate one will restart the flow. There is probably a module that will take care of this nastiness for you on CPAN.

Of course, if your not using win32, ignore me and wait for one of the "real programmers" to supply similar info for *nix systems:)

Replies are listed 'Best First'.
XON/XOFF values
by talexb (Chancellor) on Aug 01, 2002 at 03:11 UTC
    XON is ^Q, XOFF is ^S -- I just remember that they are S and Q, with the S standing for Stop and the Q for Qontinue. ^A has a hex value of 1 (0x01), so if you know that T is the twentieth letter in the alphabet, then you can figure out that ^S is 0x13 and ^Q is 0x11. SOme ASCII charts have them as DC3 and DC1, respectively -- the DC part stands for Device Control.

    --t. alex

    "Mud, mud, glorious mud. Nothing quite like it for cooling the blood!"
    --Michael Flanders and Donald Swann

      ++. I couldn't remember, its been a long time since I played with comm ports. 14 & 15 are of course ShiftIn and ShiftOut which are (or maybe have been) used for similar handshaking purposes under some protocols.