示例#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
示例#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)
示例#3
0
def init_ag_33500(conf_string):
    """Initialize ag_33500 pattern generator.
    
    *conf_string*: must include a bus parameter with the conf_string of the underlying link module (gpib, tcp, serial, ...)

    Returns ag_33500_id"""

    try:
        conf = conf_strings.parse(conf_string)
    except Exception as e:
        submod.setres(0,str(e))
        return
    if conf.name!="ag_33500":
        submod.setres(0,"ag_33500: Invalid module name %s in conf_string instead of ag_33500"%(conf.name))
        return
    if not conf.has("bus"):
        submod.setres(0,"ag_33500: Error: a required parameter in conf_string is not present")
        return
    try:
        conf_bus = conf_strings.parse(conf.params["bus"])
    except Exception as e:
        submod.setres(0,"ag_33500: %s" % (str(e)))
        return
    retcode,res = submod.execcmd("init_"+conf_bus.name,conf.params["bus"])
    if retcode==0:
        submod.setres(0,"ag_33500: Error initializing link <- %s" % (res))
        return
    ag_33500_id = ag_33500_pool.new({
        "bus": conf_bus.name,
        "bus_id": res,
        "cache_func": ["",""],
        "cache_freq": ["",""],
        "cache_hl": ["",""],
        "cache_ll": ["",""],
        "cache_dc": ["",""],
        "cache_sym": ["",""],
        "cache_pw": ["",""],
        "cache_re": ["",""],
        "cache_fe": ["",""],
        "cache_phase": ["",""],
        "cache_sync": -1,
        "cache_sync_ch": ""})
    submod.setres(1,ag_33500_id)
示例#4
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
示例#5
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
示例#6
0
def init_motion(cs1,cs2,cs3):
    "Initialize motion system. Provide the conf_strings for its three axis *csn* (for axis number n: 1,2,3)"
    motion = {}
    cs = [cs1,cs2,cs3]
    for i in [1,2,3]:
        try:
            conf = conf_strings.parse(cs[i-1])
        except Exception as e:
            submod.setres(0,"motion: %s" % str(e))
            return
        retcode,res = submod.execcmd("init_"+conf.name,cs[i-1])
        if retcode==0:
            submod.setres(0,"motion: error initializing axis %d <- %s"%(i,res))
            return
        motion["id_%d"%(i)] = res
        motion["model_%d"%(i)] = conf.name
    motion_id = motion_pool.new(motion)
    submod.setres(1,motion_id)
示例#7
0
 def init(self,conf_string):
     try:
         conf = conf_strings.parse(conf_string)
     except Exception as e:
         return 0,str(e)
     # Initialize MULTIMETER
     model = conf.name
     retcode,res=submod.execcmd("init_"+model,conf_string)
     if retcode==0:
         return 0,"Error initializing %s power supply <- %s" % (model,res)
     model_id = res
     # Get API of the module and add it to the api_pool, if it's not already there
     if not api_pool.is_present(model):
         retcode,res=submod.execcmd("getapi_"+model)
         if retcode==0:
             return 0,"Can't get API for %s <- %s" % (model,res)
         api_pool.add_api_from_string(model,res)
     multimeter_id = self.multimeter_pool.new({"model":model,"model_id":model_id})
     return 1,multimeter_id
示例#8
0
 def init(self,conf_string):
     try:
         conf = conf_strings.parse(conf_string)
     except Exception as e:
         return 0,str(e)
     if conf.name!="tcp":
         return 0,"Invalid module name %s in conf_string. Should be tcp" % (conf.name)
     if not conf.has("host","port"):
         return 0,"A required parameter in conf_string is not present"
     host = conf.params["host"]
     port = int(conf.params["port"])
     if conf.has("timeout") and conf.params["timeout"]!="undef":
         timeout = float(conf.params["timeout"])
     else:
         timeout = socket.getdefaulttimeout()
     # Validate parameters
     if (port < 0 or port > 65535):
         return 0,"Invalid destination port: %d" % (port)
     # Add to the pool
     tcp_id = self.tcp_pool.new({"host": host, "port": port, "timeout": timeout})
     return 1,tcp_id
示例#9
0
def init_pg_signal(conf_string):
    """Initialize pattern generator where *conf_string* is that of the instrument to initialize:

       Returns id of the pattern generator *pg_id*"""
    try:
        conf = conf_strings.parse(conf_string)
    except Exception as e:
        submod.setres(0, "signal: %s" % (str(e)))
        return
    # Initialize PG
    retcode, res = submod.execcmd("init_" + conf.name, conf_string)
    if retcode == 0:
        submod.setres(0, "signal: Error initializing %s pattern generator <- %s" % (conf.name, res))
        return
    model_id = res
    # Get API of the module and add it to the api_pool, if it's not already there
    if not api_pool.is_present(conf.name):
        retcode, res = submod.execcmd("getapi_" + conf.name)
        if retcode == 0:
            submod.setres(0, "signal: cant get API for %s  <- %s" % (conf.name, res))
            return
        api_pool.add_api_from_string(conf.name, res)
    pg_id = pg_pool.new({"model": conf.name, "model_id": model_id})
    submod.setres(1, pg_id)
示例#10
0
#
# 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 conf_strings

test_string = (
    "ag_33200(reset=7,bus1=gpib(addr=3,vol=5,bus=tcp(ip=10.220.0.3,port=2300),caddr=0),bus2=udp(ip=localhost))"
)

c = conf_strings.parse(test_string)

if c.name != "ag_33200":
    raise Exception("Incorrect name parsing of ag_33200")
if not c.has("reset", "bus1", "bus2"):
    raise Exception("Incorrect parsing of the variables")
if c.params["reset"] != "7":
    raise Exception("Incorrect parsing of reset variable")
if c.params["bus1"] != "gpib(addr=3,vol=5,bus=tcp(ip=10.220.0.3,port=2300),caddr=0)":
    raise Exception("Incorrect parsing of bus1 variable")
if c.params["bus2"] != "udp(ip=localhost)":
    raise Exception("Incorrect parsing of bus2 variable")

d = conf_strings.parse(c.params["bus1"])

if d.name != "gpib":
示例#11
0
 def init(self,conf_string):
     try:
         conf = conf_strings.parse(conf_string)
     except Exception as e:
         return 0,str(e)
     if conf.name!="serial":
         return 0,"Invalid module name %s in conf_string. Should be serial" % (conf.name)
     serialnum=vendor=product=device = "undef"
     baudrate = "9600"
     bytesize = serial.EIGHTBITS
     stopbits = serial.STOPBITS_ONE
     parity = serial.PARITY_NONE
     flow = "undef"
     # serial number
     if conf.has("serialnum"):
         serialnum = conf.params["serialnum"]
     # vendor/product or device
     if conf.has("vendor","product"):
         vendor = conf.params["vendor"]
         product = conf.params["product"]
         # validate
         if (len(vendor)!=4 or len(product)!=4):
             return 0,"Invalid length of vendor or product id's"
     elif conf.has("device"):
         device = conf.params["device"]
     else:
         return 0,"conf_string does not contain neither vendor and product id's or device name"
     # baudrate
     if conf.has("baudrate") and conf.params["baudrate"]!="undef":
         baudrate = int(conf.params["baudrate"])
         if baudrate not in baudrates:
             return 0,"baudrate %d in conf_string is not valid"%(baudrate)
     # bytesize
     if conf.has("bytesize") and conf.params["bytesize"]!="undef":
         bytesize = conf.params["bytesize"]
         if bytesize=="8":
             bytesize = serial.EIGHTBITS
         elif bytesize=="7":
             bytesize = serial.SEVENBITS
         elif bytesize=="6":
             bytesize = serial.SIXBITS
         elif bytesize=="5":
             bytesize = serial.FIVEBITS
         else:
             return 0,"bytesize %s in conf_string is not valid"%(bytesize)
     # stopbits
     if conf.has("stopbits") and conf.params["stopbits"]!="undef":
         stopbits = conf.params["stopbits"]
         if stopbits=="1":
             stopbits = serial.STOPBITS_ONE
         elif stopbits=="1.5":
             stopbits = serial.STOPBITS_ONE_POINT_FIVE
         elif stopbits=="2":
             stopbits = serial.STOPBITS_TWO
         else:
             return 0,"stopbits %s in conf_string are not valid"%(stopbits)
     # parity
     if conf.has("parity") and conf.params["parity"]!="undef":
         parity = conf.params["parity"]
         if parity=="N":
             parity = serial.PARITY_NONE
         elif parity=="E":
             parity = serial.PARITY_EVEN
         elif parity=="O":
             parity = serial.PARITY_ODD
         elif parity=="M":
             parity = serial.PARITY_MARK
         elif parity=="S":
             partiy = serial.PARITY_SPACE
         else:
             return 0,"parity %s in conf_string is not valid"%(parity)
     # flow control
     if conf.has("flow") and conf.params["flow"]!="undef":
         flow = conf.params["flow"]
         if flow!="xonxoff" and flow!="rtscts" and flow!="dsrdtr":
             return 0,"invalid flow. must be xonxoff, rtscts or dsrftr"
     # timeout
     if conf.has("timeout") and conf.params["timeout"]!="undef":
         timeout = float(conf.params["timeout"])
     else:
         timeout = 60
     # Add to the pool
     serial_id = self.serial_pool.new({"vendor": vendor, "product": product, "device": device, "serialnum": serialnum, "baudrate": baudrate, "bytesize": bytesize, "stopbits": stopbits, "parity": parity, "flow": flow, "timeout": timeout})
     return 1,serial_id