Reputation: 105
I got project to make on my University two weeks ago. I had to read temperature from METEX device connected on COM port. I decided to use Python's pyserial. I found on Internet a few examples and in accordance with them I made something like this:
import serial
ser = serial.Serial(
port='\\.\COM1',
baudrate=1200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS,
timeout=5
)
if ser.isOpen():
ser.close()
ser.open()
ser.write('D')
s=ser.read(13)
print s
ser.close
and it doesn't work but it should do. Generally, this device send to your computer 13 bytes contain temperature when you send 'D' char to it. I couldn't fix this although I tried to change everything in code and in system configuration. My lecturer couldn't help me too beacuse he doesn't work in Python. He tried beacuse he show me his old program written in C but he has only exec file without code. Program worked on same computer which I executed my Python scripts, so I was sure that COM port, device and system work correctly.
Today, accidentally I add to code this:
import time
import serial
ser = serial.Serial(
port='\\.\COM1',
baudrate=1200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS,
timeout=5
)
ser.setRTS(False)
time.sleep(0.5)
ser.setRTS(True)
time.sleep(0.5)
ser.setRTS(False)
if ser.isOpen():
ser.close()
ser.open()
ser.write('D')
s=ser.read(13)
print s
ser.close
and now it works perfectly. Why??!! I must make report from this exercise and describe my code line by line. Please, help me.
Operating system: Windows XP.
Upvotes: 1
Views: 1000
Reputation: 6826
I would imagine the Metex device you are using expects RTS to either be 'False' or be pulsed false-true-false.
There is some info about the Metex 14-byte protocol here: http://sigrok.org/wiki/Multimeter_ICs#Metex_14-byte_ASCII
One very simple way to investigate would be to use a terminal program (one which allows you to control RTS) on your PC to manually coimmunicate with the Metex meter, and see what level the RTS has to be to get the Metex device to respond to D.
Upvotes: 1