Hi everyone,
Does anyone has been able to send UDP commands to a TENMA 72-13210 Power Load using a python 3.0 script ?
When I send an UDP command (*IDN? for example), I am unable to retrieve data from the UDP socket.
Best regards,
import os, sys import re, string import socket import time import logging # Register logs from the module to the # root logs logs = logging.getLogger(__name__) """ Power load class """ class Load(): """ Initialize everything @param context instrument context (ie. ip and port) @param timeout instrument timeout @return none """ def __init__(self, context, timeout = .5): # Open a pyvisa ethernet link to control the # power load try: self.ip = context['ip'] self.port = context['port'] logs.info("Open load (ip: %s, port: %d)" % (context['ip'], context['port'])) except: logs.error("Unable to open load (ip: %s, port: %d)" % (context['ip'], context['port'])) # Configure power load by reading it's identifier # and resetting the device self.timeout = timeout print(self.query('*IDN?')) try: self.query('*REBOOT') time.sleep(1) except: logs.error("Unable to retrieve load identifier") logs.error("Ensure that load is VISA capable !") """ Write function @param self object pointer @param data data command @return none """ def write(self, data): self.dev.sendto(data.encode(), (self.ip, self.port)) logs.debug("Send data: %s" % data) """ Read function @param self object pointer @return data command """ def read(self): try: data = self.dev.recv(64) print(data, server) logs.debug("Receive data: %s" % data) return data except: pass """ Query function @param self object pointer @param data data command @return data command """ def query(self, data): self.dev = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.dev.connect((self.ip, self.port)) self.dev.settimeout(self.timeout) self.write(data + '\n') return self.read() if __name__ == "__main__": load = Load(context = { 'ip' : "172.16.169.70", 'port' : 18190 })