#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright 2012-2017 Frédéric Magniette, Miguel Rubio-Roy
# This file is part of Pyrame.
#
# Pyrame is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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 pools,conf_strings
sg_wl350_pool=pools.pool()
# Functions
[docs]def init_sg_wl350(sg_wl350_id,conf_string):
"""Initialize SG_WL350 motion controller.
*conf_string* must contain a bus parameter with the conf_string of the GPIB module"""
try:
conf=conf_strings.parse(conf_string)
except Exception as e:
return 0,str(e)
if conf.name!="sg_wl350":
return 0,"Invalid module name %s in conf_string instead of th_apt"%(conf.name)
if not conf.has("bus"):
return 0,"Error: the required parameter bus in conf_string is not present"
try:
conf_bus=conf_strings.parse(conf.params["bus"])
except Exception as e:
return 0,str(e)
if conf_bus.name!="gpib":
return 0,"Error: only the GPIB bus is accepted"
# Initialize GPIB link
bus_id="bus_%s"%(sg_wl350_id)
retcode,res=submod_execcmd("init@gpib",bus_id,conf.params["bus"])
if retcode==0:
return 0,"Error initializing GPIB link <- %s"%(res)
sg_wl350_pool.new(sg_wl350_id,{"bus_id":bus_id})
return 1,"ok"
[docs]def deinit_sg_wl350(sg_wl350_id):
"Deinitialize and deregister sg_wl350 motion controller from the pool."
try:
sg_wl350=sg_wl350_pool.get(sg_wl350_id)
except Exception as e:
return 1,str(e)
retcode,res=submod_execcmd("deinit@gpib",sg_wl350["bus_id"])
if retcode==0:
return 0,"Error deinitializing link <- %s"%(res)
try:
sg_wl350_pool.remove(sg_wl350_id)
except Exception as e:
return 0,"%s"%(str(e))
return 1,"ok"
def config_sg_wl350(sg_wl350_id):
try:
sg_wl350=sg_wl350_pool.get(sg_wl350_id)
except Exception as e:
return 0,"%s"%(str(e))
retcode,res=submod_execcmd("config@gpib",sg_wl350["bus_id"])
if retcode==0:
return 0,"Error configuring link <- %s"%(res)
sg_wl350["configured"]=True
return 1,"ok"
def inval_sg_wl350(sg_wl350_id):
try:
sg_wl350=sg_wl350_pool.get(sg_wl350_id)
except Exception as e:
return 0,"%s"%(str(e))
if "configured" not in sg_wl350:
return 1,"not configured"
retcode,res=submod_execcmd("inval@gpib",sg_wl350["bus_id"])
if retcode==0:
return 0,"Error invalidating link <- %s"%(res)
del sg_wl350["configured"]
return 1,"ok"
def execute_command(sg_wl350_id,command):
try:
sg_wl350=sg_wl350_pool.get(sg_wl350_id)
except Exception as e:
return 0,str(e)
if "configured" not in sg_wl350:
return 0,"not configured"
retcode,res=submod_execcmd("wrnrd@gpib",sg_wl350["bus_id"],command+r"\n")
if retcode==0:
return 0,"Error writing and reading to/from GPIB <- %s"%(res)
if res=="C":
return 1,"ok"
return 0,"Error processing execute command: %s"%(res)
def request_command(sg_wl350_id,command):
try:
sg_wl350=sg_wl350_pool.get(sg_wl350_id)
except Exception as e:
return 0,str(e)
if "configured" not in sg_wl350:
return 0,"not configured"
retcode,res=submod_execcmd("wrnrd@gpib",sg_wl350["bus_id"],command+r"\n")
if retcode==0:
return 0,"Error writing and reading to/from GPIB <- %s"%(res)
if res=="#":
return 0,"Error processing request command: %s"%(res)
return 1,res
[docs]def next_sg_wl350(sg_wl350_id):
"Go to next position in predefined path"
command="NEXT"
retcode,res=execute_command(sg_wl350_id,command)
if retcode==0:
return 0,"Error going to next position: %s"%(res)
return 1,"ok"
[docs]def get_pos(sg_wl350_id,units="um"):
"""Get position"""
if units=="" or units=="undef":
return 0,"Valid units are needed"
if units=="um":
command="GETDIE"
elif units=="colrow":
command="GETCR"
else:
return 0,"Invalid units"
retcode,res=request_command(sg_wl350_id,command)
if retcode==0:
return 0,"Error getting position: %s"%(res)
return 1,res
[docs]def get_pos_sg_wl350(sg_wl350_id,units="um"):
"""Get position"""
retcode,res=get_pos(sg_wl350_id,units)
if retcode==0:
return retcode,"%s"%(res)
return retcode,res
def go_first_point_sg_wl350(sg_wl350_id):
command="TOFIRSTSITE"
retcode,res=execute_command(sg_wl350_id,command)
if retcode==0:
return 0,"Error going to first position: %s"%(res)
return 1,"ok"
def is_last_point_sg_wl350(sg_wl350_id):
command="GETLASTPOINT"
retcode,res=request_command(sg_wl350_id,command)
if retcode==0:
return 0,"Error checking if it's last position: %s"%(res)
if res.lower()=="yes":
res="1"
else:
res="0"
return 1,res