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 http://ftp1.digi.com/support/documentation/90000833_b.pdf.
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 = os.open(‘/com/0’, os.RDWR)
data = os.read(serialfd, 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 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.