I'm trying to get data from a temperature chamber consistently. My code:
import socket
import time
class TempChamber:
def __init__(self,name):
self.name = name
def creat_tcp_connection(self):
sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_tcp.connect(('192.168.17.141', 5025))
return sock_tcp
def sendCommand(self,command):
sock = self.creat_tcp_connection()
print(command)
sock.send(command)
time.sleep(2) # Needed to have commands fully send
packet = sock.recv(1024)
print("Received ", str(packet))
sock.close()
def id(self):
self.sendCommand(b':*IDN?')
If I run the test code in quick succession as seen below (five times) I'm returned 3 of the 5 requests generally. Sometimes, I get the full 5 back, sometimes I get four back.
from TempChamber import TempChamber
t = TempChamber("Test")
for x in range(5):
print(x)
t.id()
What I tried: (1) Introduced a time.sleep after the command is sent and before the data is received. I expected consistent data 10 seconds also produces inconsistent results.
(2) I tried the top ranked response from this stack overflow link but my DMM does not respond to the packed messages. Are there any alternatives to this method?
(3) I notice now this may be something to do with my Temperature Chamber(control product number: Watlow F4T), not exactly the code. I'm using the same code to retrieve data from my digital multimeter and I get 5 responses every time I run the dummy code. Considering I only need to send/receive data from the temp chamber periodically and not in rapid succession like the DMM, this (the stack overflow question) may be a moot point.