COM port and Serial issues

Gateway version 8.1.14

So I have a situation where I’ve tried a lot and gotten no where with any of it. We have a winder system that currently uses a “home brew” program that communicates to a Mitsubishi “A2AScpu” through a “A1sj71uc24-r2” (serial card documentation). Originally I thought it would be as simple as splitting the COM port, listening to the data, and interpreting it to build a replacement vision application. My first issue came with splitting the COM port using this splitter program I found online. Even after installing and going through the steps of virtually splitting the COM port, I kept getting a “unable to open COM port” error. So backing up from there, I closed the application bound to my COM port, and rewrote ignition to bind to it. Voila, I know longer got that error, however I started getting a timeout error for the COM port being able to read any data. It’s probably something simple like writing a AT command and listening for data to come back, but serial communications is something pretty far out of my wheel house. Most of my experience with RS232 has been converting it over to be ethernet in some form or another. My python code is as follows. I have went through different iterations on the “with” statement, even going so far as to define every setting to be identical with what the homebrew program is using, but I’d still get the timeout error.

with system.serial.port(port = "COM1") as port:
    txt=port.readBytes(10)
event.source.parent.getComponent('Text Area').text=str(txt)

IIRC, every time you open the port like that, there’s 100ms delay in the underlying library. This is the kind of task that really needs a long-lived background thread, with all of the life cycle miseries that induces.

I think I remember coming across a thread where they recommended not using with but if I also remember that was on like a 7.8 gateway. I may have wrongly assumed that it was fixed since it still shows as the example in the system.serial documentation.

The system.serial.port function that acts as a context manager (hence possible to use with) was only introduced in 8.0.something… but Python 2.5 doesn’t have context managers anyways, iirc.

It is true that system.serial.port was unfortunately broken when first introduced, but it was fixed pretty promptly, and wouldn’t be the issue here - it would immediately throw an error, I’m pretty sure.