in reply to Continusously reading from serial port

rustybar:

Have you verified that the sensor is still transmitting? I've seen cases where program startup logic can reset a sensor and start it, so put a serial line monitor2 on it and verify that the sensor is still transmitting when your program is hung.

For example, perhaps some code is making the loop slow (a cron job decides to thrash the heck out of RAM and I/O), so the serial buffer fills up. The serial driver might signal to the sensor that it should stop sending for a while1. But the sensor might not understand the signal convention used. It might interpret an XOFF as a power-down command. Or it might think that a command is coming in, and wait (forever) for the rest of the command before sending its next report, or something.

I've also seen cases where the driver uses XOFF to stop and XON to continue, but the device uses XOFF to stop and another XOFF to continue, so the device waits (forever) for an XOFF that's never going to arrive.

The sensor might have just gotten confused for some other reason and gave up the ghost.

NOTES:

1 There are too darned many different ways applications can tell each other to stop sending and then proceed. XOFF/XON is a commonly used character-based protocol, though there are others. But there are also hardware handshaking versions using the RTS/CTS and DTR/DSR lines on your serial port. The long and short of it is, be sure that both ends of the wire agree!

2 There's an entire range of serial line monitors. Some fancy protocol analyzers, eavesdroppers, etc. Often you can get away with a simple mini-tester, available (nearly everywhere) in both 9 pin and 25 pin versions. You can just watch the LEDs flicker to see which end of the cable is sending, and the current state of the hardware handshaking lines...

Finally, I don't know how much serial communications mojo you have, so please don't be offended if I'm telling you the obvious...

UPDATE: If you want something fancier, it's easy enough to put together a more advanced serial line monitor if you have a spare computer with a pair of serial ports. You just need an eavesdropping cable (details below) and a little software to monitor both ports. Print all characters from one port in one color, and the characters from the other port in a different color.

Cable Details: (Pin numbers rearranged to simplify drawing) To original To original Eavesdropper system cable end computer Port 1 Port 2 DB-9 DB-9 DB-9 DB-9 MALE FEMALE FEMALE FEMALE 9------------9 9 9 8------------8 8 8 7------------7 7 7 6------------6 6 6 5------------5------------5-----------5 4------------4 4 4 1------------1 1 1 2--------*---2 +----2 +----2 3-----*------3 | 3 | 3 | | | | | +-----------+ | +--------------------------+
...roboticus