help with serial port I/O

Chip Piller piller at jlab.org
Wed Sep 8 14:51:23 EDT 1999


Hi,
I am running RedHat Linux 6.0.
I have an instrumentation amplifier that can be controlled by the serial
port.
I can successfully setup the serial line and read and write to the
device using the minicom serial communications program.

I want to write a simple program that will write a command to the
device, wait for one second, and then read the response from the device.

I tried the following code:
#!/usr/bin/python
udl = open('/dev/ttyS1','r+')
udl.write('sen 22\r')              #change instrument sensitivity
setting
udl.write('mag\r')                  #query instrument for signal
magnitude
val = udl.readline()
print 'magnitude readback = '
print val
udl.close()

Here is the output:
[root at piller1 python]# ./test3
magnitude readback =
sen 22

[root at piller1 python]#

The code does write the sen 22 command to the instrument and changes the
value, but not on the first try, I usually have to run the program
twice.
I have not had success with getting any readback from the device using
Python.
Help or suggestions please!
Chip









More information about the Python-list mailing list