def finalize_apc(self,device,name): """this function is called after the initialization of a device and all its subdevices""" #print what we discovered #print ("===> finalize_apc for a %s with name %s on phase %s" %(device,name,self.phase)) #searching for such a name in cmod if submod.DEBUG: print("calling external function get_id_cmod") retcode,res=bindpyrame.sendcmd("127.0.0.1",bindpyrame.get_port("CMOD_PORT",self.port_table),"get_id_cmod",name) if retcode==1: local_id=res else: local_id="-1" #depile the device id self.devices_lifo.pop() #extract the function func="%s_fin_%s"%(self.phase,device) #get the module name modname="cmd_%s"%device #extract the api if not self.apipools.is_present(modname): self.apipools.add_api_from_file(modname,"/opt/pyrame/%s.api"%modname) api=self.apipools.get_api(modname,func) #execute the command if api!= -1: #extract the port port_name="%s_PORT"%(device.upper()) port=bindpyrame.get_port(port_name,self.port_table) if submod.DEBUG: print("calling external function %s"%(func)) retcode,res=bindpyrame.sendcmd(self.domip,port,func,local_id) #print("-->result %d,%s"%(retcode,res)) if retcode==0: print("Error:%s when executing %s"%(res,func)) return retcode,res else: #print("no function %s for device %s"%(func,device)) return 1,"no function with that name"
def web_socket_transfer_data(request): received_request = request.ws_stream.receive_message() if received_request is None: return received_request = json.loads(received_request) port_string = received_request.pop("port") command = received_request.pop("command") params = [] i = 1 for param in received_request: params.append(received_request["param%d"%i]) i += 1 try: table = bindpyrame.init_ports_table("/opt/pyrame/ports.txt") port = bindpyrame.get_port(port_string,table) retcode,res=bindpyrame.sendcmd("localhost",port,command,*params) except Exception as e: retcode = 0 res = str(e) answer = json.dumps({"retcode": retcode, "res": res}) request.ws_stream.send_message(answer, binary=False)
def init_apc(self,device,name,dicoCmds): """this function apply a function to the discovered device""" #print what we discovered #print("===> init_apc for a %s with name %s on phase %s" %(device,name,self.phase)) #store the name in the dicoCmds under name dev_name dicoCmds["dev_name"]=name #searching for such a name in cmod if submod.DEBUG: print("calling external function get_id_cmod") retcode,res=bindpyrame.sendcmd("127.0.0.1",bindpyrame.get_port("CMOD_PORT",self.port_table),"get_id_cmod",name) if retcode==1: dicoCmds["%s_id"%(device)]=res #store the parent device id in the dicoCmds if self.devices_lifo!=[]: dicoCmds["parent_device"]=self.devices_lifo[-1] else: dicoCmds["parent_device"]="0" #if domain store the ip for future pyrame commands if device=="domain": #store the ip for future pyrame commands self.domip= dicoCmds["domain_ip"] if self.domip=="undef": print("domain without IP : exiting...") retcode=0 res="no ip" return retcode,res #get the module name modname="cmd_%s"%device #extract the function func="%s_%s"%(self.phase,device) #extract the api if not self.apipools.is_present(modname): self.apipools.add_api_from_file(modname,"/opt/pyrame/%s.api"%modname) api=self.apipools.get_api(modname,func) #send the command to the module if api!= -1: #extract the port port_name="%s_PORT"%(device.upper()) port=bindpyrame.get_port(port_name,self.port_table) if submod.DEBUG: print("calling external function %s"%(func)) params=[] for arg in api["args"]: if arg=="parent_device": realargname="parent_device" elif arg=="dev_name": realargname="dev_name" elif arg=="%s_id"%device: realargname="%s_id"%device else: realargname="%s_%s"%(device,arg) params.append(dicoCmds[realargname]) retcode,res=bindpyrame.sendcmd(self.domip,port,func,*params) #print("-->result %d,%s"%(retcode,res)) if retcode==0: print("Error:%s when executing %s"%(res,func)) #TODO break if return=0 #stock the result if it is an id self.devices_lifo.append(res) else: self.devices_lifo.append("-1") #print("no function %s for device %s"%(func,device)) retcode=1 res="no function with that name" return retcode,res
# Pyrame is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Pyrame. If not, see <http://www.gnu.org/licenses/> import bindpyrame import socket socket.setdefaulttimeout(20) import sys try: table = bindpyrame.init_ports_table("/opt/pyrame/ports.txt") port = bindpyrame.get_port("TEST_PORT",table) except Exception as e: print e sys.exit(1) # SENDCMD try: retcode,res=bindpyrame.sendcmd("localhost",port,"twoargs_test","arg1","arg2") except Exception as e: print e sys.exit(1) print("sendcmd: retcode=%d res=%s"%(retcode,res)) print(""); # EXECCMD
current_limit=0.001 Irange=0.01 ###################################################### # Helper function def sendcmd(*params): retcode,res=bindpyrame.sendcmd("localhost",*params) if retcode==0: print(res) sys.exit(1) return res # Get ports from Pyrame table table=bindpyrame.init_ports_table("/opt/pyrame/ports.txt") ps_port=bindpyrame.get_port("PS_PORT",table) mm_port=bindpyrame.get_port("MULTIMETER_PORT",table) # Initialization of module PS and MULTIMETER ps_id=sendcmd(ps_port,"init_ps",conf_string_ps) mm_id=sendcmd(mm_port,"init_multimeter",conf_string_mm) # Configure modules sendcmd(ps_port,"config_ps",ps_id) sendcmd(mm_port,"config_multimeter",mm_id) # Set current limit on PS sendcmd(ps_port,"set_current_limit_ps",ps_id,str(current_limit)) # Power on PS sendcmd(ps_port,"power_on_ps",ps_id)
if sys.argv[1]=="-mo": offset=0 mo=True else: offset=1 mo=False host=sys.argv[2-offset] port=sys.argv[3-offset] command=sys.argv[4-offset] params=sys.argv[5-offset:len(sys.argv)] try: table = bindpyrame.init_ports_table("/opt/pyrame/ports.txt") port = bindpyrame.get_port(port,table) except Exception as e: print e sys.exit(1) retcode,res=bindpyrame.sendcmd(host,port,*([command]+params)) if mo: print(res) else: print("retcode=%d res=%s"%(retcode,res)) if retcode==0: sys.exit(1) sys.exit(0)
# If imported by getapi just exit. This is just a benchmarking script, not a module if __name__ != '__main__': sys.exit(0) # How-to if len(sys.argv) < 5: print "Usage: %s conf_string voltage current sleep [channel]" % (sys.argv[0]) print "where everything is in base units of the International System of Units" sys.exit(1) if len(sys.argv) > 5: channel = sys.argv[5] else: channel = "" # Init table = bindpyrame.init_ports_table("/opt/pyrame/ports.txt") port = bindpyrame.get_port("PS_PORT",table) retcode,res=bindpyrame.sendcmd("localhost",port,"init_ps",sys.argv[1]) if retcode==0: print("Error initializing PS") sys.exit(1) psid = res retcode,res=bindpyrame.sendcmd("localhost",port,"set_current_ps",psid,sys.argv[3],channel) if retcode==0: print("Error setting current with sendcmd") retcode,res=bindpyrame.sendcmd("localhost",port,"deinit_ps",psid) sys.exit(1) retcode,res=bindpyrame.sendcmd("localhost",port,"power_on_ps",psid,channel) if retcode==0: