Ignition Serial Port Not Reading Sensor

I am having trouble reading a Omega PX409 serial usb sensor. I have used PuTTY to read the sensor and it returns the PSI immediately. I want to read this PSI in Ignition for a testing application. I have tried a couple ways of writing the script and both have been unsuccessful.

Preformatted text# Same idea as example one, but uses all available parameters.
with system.serial.port(
port = "COM6",
bitRate = system.serial.BIT_RATE_115200,
dataBits = system.serial.DATA_BITS_8,
handshake = system.serial.HANDSHAKE_NONE,
hardwareFlowControl = False,
parity = system.serial.PARITY_NONE,
stopBits = system.serial.STOP_BITS_1) as port:

line = port.readLine(60000)

this only returns empty.

port_name = "COM6"

#Configure the serial port
system.serial.configureSerialPort(
   port=port_name,
   bitRate=system.serial.BIT_RATE_115200,
   dataBits=system.serial.DATA_BITS_8,
   handshake=system.serial.HANDSHAKE_NONE,
   hardwareFlowControl=False,
   parity=system.serial.PARITY_NONE,
   stopBits=system.serial.STOP_BITS_1
)
# Try to communicate with the sensor
try:
   # Open the serial port
   system.serial.openSerialPort(port_name)
 # Write the command to the port
   system.serial.write(port_name, "P")
 # Read the response from the port
   read = system.serial.readLine(port_name, 60000, "ASCII")
# Print or handle the read value here
   print(read)
except Exception as e:
   print("Error in communication with %s: %s" % (port_name, str(e)))
finally:
   # Ensure the serial port is closed
   system.serial.closeSerialPort(port_name)

this script will give me errors on a unknown source and port time outs. I have tried increasing the time and still nothing is returned.

my PuTTY configurations are here and work perfect.
Capture3
Capture4

Please format your code. Use triple backtick blocks or highlight your code and click the </> button in the editing bar.

2 Likes

Well, anyways...

This probably needs to be:

system.serial.write(port_name, "P\r\n")