Home/Support/Support Forum/recv serial data
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

recv serial data

0 votes
Hallo,

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.

arndt
asked Apr 22, 2008 in Python by arndt.rinne New to the Community (6 points)

Please log in or register to answer this question.

5 Answers

0 votes
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.
answered Apr 22, 2008 by DigiGuy42 Community Contributor (102 points)
0 votes
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.open(serialport, os.O_RDWR)

test = os.write(serialfd,'$016')
print 'Test ist raus'
print test
rtest = os.read(serialfd,512)
print rtest
print 'Rtest ist drin'
os.close(serialfd)

The write commands will be executed but then the Program waits for data to read.
answered Apr 22, 2008 by arndt.rinne New to the Community (6 points)
0 votes
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.
answered Apr 22, 2008 by 52637p Community Contributor (59 points)
0 votes
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!!
answered Apr 23, 2008 by arndt.rinne New to the Community (6 points)
0 votes
The current version of the adapters manual, which contains the DIP settings and adapter pinout, can be found here: http://ftp1.digi.com/support/documentation/90000891_B.pdf

Information relevant specifically to the 485 adapter can be found beginning page 14 of that manual.
answered Apr 23, 2008 by michaelt Veteran of the Digi Community (759 points)
...