1

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.

3
  • your port name looks wrong, on windows you can just use "COM1" ... often times you need to add a delay after opening the port, due to device com port initialization ... having to set the Ready to Send flag is very weird as 99.9999% of devices dont care about this ... it also looks like all your init are just the default values (ie you could just do serial.Serial("COM1",1200,timeout=5) Commented Oct 26, 2015 at 17:03
  • is this an SDI-12 communication device? sdi-12 is not standard serial ... Commented Oct 26, 2015 at 17:05
  • I don't know if this device use sdi-12 but it isn't important. Script with these few lines with rts WORKS and I don't know why. Any other ideas? Commented Oct 26, 2015 at 17:12

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.