recv serial data


i try to recv data from an Modbus I/O module, which is connected to the serial port of an X4.
Via commandline or realport i can send commands and recv the response. But how can I realize in a python prog?
If anybody has an idea please support me.


We expose the serial ports as device files that you can open and provide a subset of the termios() API to allow configuration. Full details of port naming and supported APIs are available in the Digi Python Programmer’s Guide, on the CD or available from our support pages at

However, a quick summary:

  • The serial port is named ‘/com/0’.
  • Devices are managed through the os file routines, not the Python file objects

So, you would start by opening the port:

import os
serialfd =‘/com/0’, os.RDWR)
data =, 512)

If you have configured the serial port correctly from the Digi UIs, you can immediately perform reads, writes, and selects with the fd. Otherwise, you can use the termios API to configure the port before data transfer.

The Problem is , that I have to sent a request as a String ( $016) and get back a response.

the programmpart is:
serialport =‘/com/0’
serialfd =, os.O_RDWR)

test = os.write(serialfd,‘$016’)
print ‘Test ist raus’
print test
rtest =,512)
print rtest
print ‘Rtest ist drin’

The write commands will be executed but then the Program waits for data to read.

The next step in debugging serial issues such as this is, I believe, as below:

Assuming the open succeeds and the write returns “4” in this case, my next suggestion would be to verify the state of flow control on the serial port, as well as examine the serial statistics for the port.

In essence, some amount of serial debugging is required to verify that the data actually hit the wire, and whether any response data was detected on the line. The system (for efficiency) is capable of buffering some data in the serial driver while waiting for conditions (such as flow control) to be cleared.

If the system believes that it can write to the serial port, and the serial statistics have been updated to indicate that the driver believes that the correct number of bytes have been transmitted out of the serial port, the next step (traditionally) is to examine the wire. One method to do so would be for you to mimic the device by connecting the Digi device directly to a PC COM port with a crossover cable.

I hope this information helps.

If I want to use the rs485 mode on the serialport, which pins do I have to use for Data+ and Data- on the sub-d?

the problem of missing response is solved!
the request needed a carriage return ('$016\r).
So it works well!!

The current version of the adapters manual, which contains the DIP settings and adapter pinout, can be found here:

Information relevant specifically to the 485 adapter can be found beginning page 14 of that manual.