11-17-2023 09:10 PM
Hello,
I am running a Python script to open a port to a TCP connection. However, in the second session, when trying to run the scrip again, I get an error that the TCP connection was refused.
In the python script, I open and close the TCP port like this:
11-17-2023 10:53 PM
Hello,
Could it be a conflict of resources?...as I am opening the instrument's TCPIP port:
instrument = rm.open_resource('TCPIP0::05.20.133.05::8856::SOCKET')
then opening the device port:
s, ubr = TCP_socket_conn()
then in the end, doing a:
s.close()
???
11-21-2023 03:01 AM
Not sure about the Python implementation of TCP-IP sockets but in the case of your pyVISA implementation I would definitely try to do a close of the instrument session too, before closing of the resource manager session.
import pyvisa
import time
t = 0.5
rm = pyvisa.ResourceManager()
instrument = rm.open_resource('TCPIP0::05.20.133.05::8856::SOCKET')
def power_level(command):
instrument.write(command)
instrument.close()
# shutdown
rm.close()