Accessing the CP X4 serial port using the Python os module

When trying to access the CP X4H serial port using the Python os module I get an error:

11 No more processes

I am attempting to send a ModBus message.

Using teh same ModBus message I can access the same serial port from my PC using Real Port.

The serial port is configured as ‘TCP Sockets’ profile 9600, 8N1. It seems to me I have a configuration error or my message in Python is not formatted correctly. The relevent Python code is:

mbMsg = [0x64, 0x03, 0x2a, 0xf8, 0x00, 0x6c, 0xc5, 0xfb]
wrtstat = os.write(srlprt, array.array(‘B’, mbMsg))
except Exception, e:
print 'ModBus write error: ', (e.errno, os.strerror(e.errno))
mbMsg =, max_bytes)
except OSError, e:
print 'ModBus read error: ', (e.errno, os.strerror(e.errno))

Any help will be much appreciated.

Could you provide a traceback of when the error occurs. If I had to guess, I would imagine that it occurs during the ‘read’ rather than the write. I would also guess that you have provided the O_NONBLOCK call for the open.

If those guesses are true, than the reason that you are seeing this is because there is no data to read. Read due to the O_NONBLOCK will return immediately with error number 11. This is the error that is symbolically EAGAIN, the string reported by strerror is unfortunately not very useful for that error. This return code means that there is no data ready to return, the call would block and that you should try again later.


Thanks for the replay. I am using O_NONBLOCK when opening the serial port:

srlprt =‘/com/1’, os.O_RDWR | os.O_NONBLOCK)

The ModBus RTU device connected to the serial port a status light blinks when I access it from my PC with Real Port but does not when I do it programmatically from Python.

I am starting to suspect the issue may be related to the serial port config (web interface - Configuration - Serial Port) of course I have the serial port profile set to RealPort.

My question is; To access this serial port from python do I have to change the serial config to Industrial Automation (IA) - Modbus RTU? By the way I tried this and still could not access it from Python.


If set to Industrial Automation, then Python will not work because the IA threads will hold the port open.

The serial port profile should be RealPort or TCP Sockets.

If you go to the "System Information > Serial > Port 1 > Serial Port Diagnostics, do you see the RTS and DTR circles green?

Some Modbus devices will NOT function if their incoming DSR is low - Most older Modicon PLC are like this. So you’ll need to assert the DTR and RTS outputs on the ConnectPort using the termios package.

You have seen this page, right?