Ejemplo n.º 1
0
 def init(self,conf_string):
     try:
         conf = conf_strings.parse(conf_string)
     except Exception as e:
         return 0,str(e)
     if conf.name!="th_apt":
         return 0,"Invalid module name %s in conf_string instead of th_apt"%(conf.name)
     if not conf.has("bus","model"):
         return 0,"Error: some of the required parameters (bus,model) in conf_string are not present"
     chan = "undef"
     if conf.has("chan"):
         chan = int(conf.params["chan"])
     try:
         conf_bus = conf_strings.parse(conf.params["bus"])
     except Exception as e:
         return 0,str(e)
     if not conf_bus.has("vendor"):
         conf_bus.params["vendor"]="0403"
     if not conf_bus.has("product"):
         conf_bus.params["product"]="faf0"
     if not conf_bus.has("baudrate"):
         conf_bus.params["baudrate"]="115200"
     retcode,res = submod.execcmd("init_"+conf_bus.name,conf_strings.unparse(conf_bus))
     if retcode==0:
         return 0,"Error initializing link <- %s" % (res)
     th_apt_id = self.th_apt_pool.new({"bus": conf_bus.name, "bus_id": res, "chan": chan, "model": conf.params["model"]})
     return 1,th_apt_id
Ejemplo n.º 2
0
def init_nw_esp301(conf_string):
    """Initialize NW_ESP301 motion controller.
    
    *conf_string* must contain:

    - bus: conf_string of the underlying link module
    - chan: 1, 2 or 3 for the channel of the axis

    Returns id of NW_ESP301, nw_esp301_id"""
    try:
        conf = conf_strings.parse(conf_string)
    except Exception as e:
        submod.setres(0,"nw_esp301: %s" % str(e))
        return
    if conf.name!="nw_esp301":
        submod.setres(0,"nw_esp301: Invalid module name %s in conf_string instead of nw_esp301"%(conf.name))
        return
    if not conf.has("bus","chan"):
        submod.setres(0,"nw_esp301: Some of the required parameters (bus and chan) in conf_string are not present")
        return
    if conf.params["chan"] not in axes:
        submod.setres(0,"nw_esp301: invalid channel")
        return
    try:
        conf_bus = conf_strings.parse(conf.params["bus"])
    except Exception as e:
        return 0,str(e)
    if conf_bus.name=="serial" and not conf_bus.has("baudrate"):
        conf_bus.params["baudrate"]="115200"
    retcode,res = submod.execcmd("init_"+conf_bus.name,conf_strings.unparse(conf_bus))
    if retcode==0:
        submod.setres(0,"nw_esp301: error initializing axis <- %s"%(res))
        return
    nw_esp301_id = nw_esp301_pool.new({"bus":conf_bus.name,"bus_id":res,"chan":conf.params["chan"]})
    submod.setres(1,nw_esp301_id)
Ejemplo n.º 3
0
 def init(self,conf_string):
     # Extract parameters from conf_string
     try:
         conf = conf_strings.parse(conf_string)
     except Exception as e:
         return 0,str(e)
     if conf.name!="gpib":
         return 0,"Invalid module name in conf_string"
     if not conf.has("bus","dst_addr"):
         return 0,"bus and dst_addr needed in conf_string"
     bus_cs = conf.params["bus"]
     try:
         bus_conf = conf_strings.parse(bus_cs)
     except Exception as e:
         return 0,str(e)
     if bus_conf.name=="tcp" and not bus_conf.has("port"):
         bus_conf.params["port"] = 1234
     elif bus_conf.name=="serial" and not bus_conf.has("device") and not bus_conf.has("vendor","product"):
         bus_conf.params["vendor"] = "0403"
         bus_conf.params["product"] = "6001"
     try:
         conf.params["bus"] = conf_strings.unparse(bus_conf)
     except Exception as e:
         return 0,str(e)
     dst_addr = conf.params["dst_addr"]
     adapter_addr = "0"
     if conf.has("adapter_addr"):
         adapter_addr = conf.params["adapter_addr"]
     # Validate parameters
     if dst_addr=="" or dst_addr=="undef" or int(dst_addr) not in range(0,30):
         return 0,"Invalid dst_addr %s" % (dst_addr)
     if adapter_addr=="" or adapter_addr=="undef" or int(adapter_addr) not in range(0,30):
         return 0,"Invalid adapter_addr %s" % (adapter_addr)
     # Initialize bus
     retcode,res = submod.execcmd("init_"+bus_conf.name,conf.params["bus"])
     if retcode==0:
         return 0,"Error initializing bus <- %s" % (res)
     bus_id = res
     # Add to the pool
     gpib_id = self.gpib_pool.new({"bus_type": bus_conf.name, "bus_id": bus_id, "dst_addr": dst_addr, "adapter_addr": adapter_addr})
     return 1,gpib_id
Ejemplo n.º 4
0
 def init(self,conf_string):
     try:
         conf = conf_strings.parse(conf_string)
     except Exception as e:
         return 0,str(e)
     if conf.name!="ls_421":
         return 0,"Invalid module name %s in conf_string instead of ls_421"%(conf.name)
     if not conf.has("bus"):
         return 0,"Error: some of the required parameters (bus) in conf_string are not present"
     try:
         conf_bus = conf_strings.parse(conf.params["bus"])
     except Exception as e:
         return 0,str(e)
     if conf_bus.name=="serial" and not conf_bus.has("baudrate"):
         conf_bus.params["baudrate"]="9600"
     conf_bus.params["parity"]="O"
     conf_bus.params["bytesize"]="7"
     retcode,res = submod.execcmd("init_"+conf_bus.name,conf_strings.unparse(conf_bus))
     if retcode==0:
         return 0,"Error initializing link <- %s" % (res)
     ls_421_id = self.ls_421_pool.new({"bus": conf_bus.name, "bus_id": res})
     return 1,ls_421_id