Serial Protocol Dilemma
David Thomson, Original Code Consulting, September, 2019
I had to talk to a fairly simple instrument called a Joule Meter, which measures the energy in each shot of a pulsed laser. The joule meter communicated over a standard RS232 serial port, but their protocol had a feature I have never seen before. The device had two modes of communication: Query/Response and Streaming. When turned on, it came up in Q/R, and one could easily set parameters and read values. To set in in streaming mode, one sent a command in Q/R mode, after which every energy value it measured would be sent to the computer with no querying, as soon as it was available. Now the clever part of their protocol was that in order to allow one to "easily" distinguish between Q/R and Streaming data traffic, the joule meter would assert the 8th bit (value 128) of every character when in streaming mode. That's not the end of the world, but because their protocol used a <LF> termination character, the most convenient way to read the variable-length data from the joule meter was to enable the termination character when the serial port was opened in LabVIEW. But after setting the unit to Streaming, one then had to close the serial port and re-open it with the termination character d138, 0x8A, instead of 0x0A ( e.g. <LF>), since even the termination characters in the streaming data had their high bit set!