Hi All,
I'm trying to get some script running in labpython.
the code is the follwing
=====================
import socket
class tcpalinks :
def __init__(self) :
self.linkslist={}
print("TCPALINK Init")
def gettcpalink(self, visatring = ""):
if visatring not in self.linkslist :
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((visatring.split("::")[1],int(visatring.split("::")[2])))
print("build connection: %s"%(visatring))
self.linkslist[visatring] = sock
else :
print("connection already exist %s"%(visatring))
return self.linkslist[visatring]
def tcpalinkcloseall(self) :
for sockname in self.linkslist :
self.linkslist[sockname].close()
class tcpalink :
def __init__(self,sock) :
self.currentsock=sock
def tcpaquery(self, message) :
self.currentsock.send(message+'''\r\n''')
reply=self.currentsock.recv(1024)
return reply
listoflinks = tcpalinks()
currentlink = tcpalink(listoflinks.gettcpalink("TCPIP0::127.0.0.1::41000::SOCKET"))
currentlink.tcpaquery("stop 1")
listoflinks.tcpalinkcloseall()
=====================
The code works perfectly when called from python25.exe or 27 but when called through the Labpython interface fails claining "socket" is not defined.
I'm pretty sure the instruction is sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) but I can't understand why.
===================
Error 1050 occurred at PYTHON Execute Script__ogtk.vi->PYTHON sandbox.vi:<type 'exceptions.NameError'>, global name 'socket' is not defined
Possible reason(s):
LabVIEW: Error occurred while executing script.
PYTHON Execute Script__ogtk.vi->PYTHON sandbox.vi:<type 'exceptions.NameError'>, global name 'socket' is not defined
===================
Any suggestion would be more than welcome.
The same instruction works fine when called directly and not inside the tcpalinks tcpalinks.
Best Regards
Filippo