Jump to content

Filippo Persia

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by Filippo Persia

  1. Wonderful and clear explanation. Adding sys.path.append("C:\Python27\Lib") is perfectly doable for me. I'll try it out. Although I must say the python 2.7 is not working properly (2.5 works fine). When I try to set the python27.dll in sys.32 as the server executor for labpython I get errors and if I insist in runnin a script I end up hanging all the labview processes leading to a forced kill with taskman. I have a doubt this is due to the OS (unfortunately Win 8.1) but I cannot change it (IT rules). Anyway all this venture in python is due to my stubborn idea depicted in the video of "recording Vi Macros" ... I'm already able to do so but the macro script is not a full featured language, the next improvement I want to do is record the marco in a proper programming language in order to have access to nice statement like "for, while, if, case ....." python ended up to be a nice choice as a scripting language. Best Regards Filippo
  2. I agree globalizing everything could be viable, altough ugly, workaround. The other solution I have in mind may be calling pyhon directly form the command line. This will obviously impair a lot my ability to move data back and forth but I really don't need it that much. What I'm working on is something like this https://dl.dropboxusercontent.com/u/13519740/TCPA%20Automation%20Engine.mp4 where the macro is recorded directly in python. Running in the command line may help avoiding ugly issues when the python code has obvious hang up like (while 1 ... ) and the Vi hangs up as well. Best Regards Filippo P.S. Using LabVIEW 2015 Labpython 4.0.0.4 Python 2.5 (and 2.7)
  3. 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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.