Desperate S
Desperate S

Reputation: 31

Device will not recognize commands or respond when communicating using PySerial

I am trying to communicate with an Omega CNi16D temperature controller using the PySerial module. Using the basic communication software provided by the manufacturer, I was able to write some settings to the controller, which ensures that I did the hardware configuration and settings correctly. However, I am having problems when I try to do this in Python 3.4 using PySerial. My suspicion is that I am not sending the byte code in an appropriate form. Here is what I tried:

import serial
ser = serial.Serial('COM3', 9600, bytesize = 7, stopbits=1, timeout=0.1,\
       parity=serial.PARITY_ODD) #these are the settings on my controller
print(ser.isOpen())
ser.write(b'*01W01A003E8')

I get a True return from isOpen(), but nothing happens with the command. *01W01A003E8 is one of the example commands given in the manual, where * is the recognition character, 01 is the slave address that I set on the controller side (I am using RS485), and W01A003E8 is a hex-ASCII command to set the setpoint to -100.

Here are a few other things I tried with no success: tried giving some sleep time before ser.write(); tried different commands that are supposed to return reading values from the controller, but I always get an empty byte object (ser.read() after whatever command returns b''.); tried switching to RS232 mode, which doesn't require a slave address in the command; tried ser.write('*01W01A003E8'.encode('ascii')) and also with 'utf-8'.

I have a feeling that I am sending the wrong byte object to the controller. In the manual(http://www.omega.com/Manuals/manualpdf/M3397.pdf part.5), it sounds like I can just send in ASCII code in the specified format to make this work.

Upvotes: 2

Views: 2341

Answers (1)

Desperate S
Desperate S

Reputation: 31

After contemplating on the comment from "dsgdfg," I figured out the problem. It was a very simple thing. I was missing two things.

First, I should append the carriage return on the command. I somehow assumed that this would be implemented in the write() method, but I was wrong.

Second, it turns out that in order to get a response from the controller, I need to allow about 0.1 sec for the device to digest and respond back. In other words, time.sleep(0.1) before the read() command is requried.

Thanks for the helpful comment! As I was suspecting the wrong thing, I think I should change the title of the post.

Upvotes: 1

Related Questions