The Python side software was generating various errors where lengths didn't match, responses didn't make sense, or other logical issues. As I had discovered, most of the issues seemed to be caused by extraneous characters injected into the serial stream (usually a hexadecimal F0 but sometimes others). I hunted the cause by replacing everything that was suspect and adding in appropriate debugging output.
I swapped USB cables, Arduino Mega machines, even moved to an older Windows 7 pro laptop, reinstalled software . . . nothing made a difference.
DETERMINING WHICH SIDE HAD THE PROBLEM
I modified the code in the Arduino to simply echo back the exact message it received, nothing more. I could communicate flawlessly with the Arduino using the IDE Serial Monitor. That seemed to confirm that the USB ports, Arduino and other elements of the link were working properly. Secondarily I started the pyserial.tools.miniterm program which also proved that it was echoing correctly with no added characters.
I then tried to unwind everything that might be messing up writing from Python. The code used the SLIP library, a protocol to send packets over serial. It frames the start and end with the control character \xC0 and has various escape codes just in case the data inside the packet must be \xC0 or the escape code itself.
I wrote a state machine to read the stream with the SLIP protocol and to write directly to pyserial's serial stream, bypassing the sliplib entirely. No change. I varied every configuration parameter or sequence of code I could, without a change.
DRUNKS WALK OF CHANGES FINALLY SOLVES THE PROBLEM
Finally, I realized that this corruption seemed to be introduced by the initial reset command sent from laptop down to the Arduino. I modified the code to skip that function, and the issue went away. I still don't know why it malfunctions, but I have a suitable bypass. I can move on to more interesting tasks - interacting with the 3178 terminal.
It is late and dark out where the terminal is sitting, but I was able to interrogate the terminal ID, terminal status and to write some data on the screen. This is a great beginning.
No comments:
Post a Comment