Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

T3PS16081P /30051P Programmable Linea DC Power Supplies

Solved!
Go to solution

Hi, I am new to communicating to device through LAN.

I am using the T3PS16081P / 30051P programmable Linear DC Power Supplies and I need to write some code in Python in orfder to comunicate with hardware.

 

I have setup the LAN  interfaces because I need remotely control.  I used the network where the computer is located and I am able to ping the IP.

 

 I see into display of the power supplies the following values :

IP Address 10.130.6.56

Subnet Mask 255.255.254.0

 

I am using the Socket comunication and I using the script of example in python I had found into manual:

*********************************************************************************************************************

 #!/usr/bin/env python
#-*- coding:utf-8–*
#-----------------------------------------------------------------------------------------------
# Access the control device via Socket, send a command, read and print
# the return #value.
#-----------------------------------------------------------------------------------------------
import socket # for sockets
import sys # for exit
import time # for sleep
#-----------------------------------------------------------------------------------------------
remote_ip = "10.130.6.56"
port = 5025

count = 0
def SocketConnect():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print ('Failed to create socket.')
sys.exit();
try:
s.connect((remote_ip , port))
except socket.error:
print ('failed to connect to ip ' + remote_ip)
return s

def SocketQuery(Sock, cmd):
try :
Sock.sendall(cmd)
time.sleep(1)
except socket.error:
print ('Send failed')
sys.exit()
reply = Sock.recv(4096)
return reply
def SocketClose(Sock):
Sock.close()
time.sleep(.300)

def main():
global remote_ip
global port
global count
s = SocketConnect()
for i in range(10):
qStr = SocketQuery(s, b'*IDN?\n')
print (str(count) + ":: " + str(qStr))
count = count + 1
SocketClose(s)
input('Press "Enter" to exit')
if __name__ == '__main__':
proc = main()

*********************************************************************************************************************

 

I get the following error:

Traceback (most recent call last):
File "C:\Users\agsuser\Desktop\Automation Testing\python\Exemple\pythonProjectT3PS16081P\main.py", line 52, in <module>
proc = main()
File "C:\Users\agsuser\Desktop\Automation Testing\python\Exemple\pythonProjectT3PS16081P\main.py", line 46, in main
qStr = SocketQuery(s, b'*IDN?\n')
File "C:\Users\agsuser\Desktop\Automation Testing\python\Exemple\pythonProjectT3PS16081P\main.py", line 29, in SocketQuery
Sock.sendall(cmd)
AttributeError: 'NoneType' object has no attribute 'sendall'

 

thanks in advance.

 

0 Kudos
Message 1 of 3
(149 Views)
Solution
Accepted by topic author AndyCapp80

Based on the provided code, it seems the issue lies within the SocketQuery function. In this function, you attempt to send a command and receive a response, but the return reply statement is placed outside the except block. This causes the function to return a response even if sending the command fails, potentially returning None without receiving a proper response, which explains the error you encountered.

To address this issue, you should move the return reply statement inside the try block. This ensures that if sending the command fails, None won't be returned.

Here's the modified code snippet:

 

def SocketQuery(Sock, cmd):
try:
Sock.sendall(cmd)
time.sleep(1)
reply = Sock.recv(4096)
return reply
except socket.error:
print('Send failed')
sys.exit()

Message 2 of 3
(119 Views)

perfect!!! it is working!!  Thanks

0 Kudos
Message 3 of 3
(106 Views)