Source code for cmd_dio
#!/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 conf_strings,pools,apipools
# CLASS ##########################################################
dio_pool=pools.pool("dio")
[docs]def init_dio(dio_id,conf_string):
"""Registers in the pool and initializes a new DIO. *conf_string* is the configuration string for the module to be initialized"""
try:
conf=conf_strings.parse(conf_string)
except Exception as e:
return 0,str(e)
# Initialize DIO
model=conf.name
model_id="diomodel_%s"%(dio_id)
retcode,res=submod_execcmd("init@"+model,model_id,conf_string)
if retcode==0:
return 0,"Error initializing %s power supply <- %s" % (model,res)
dio_pool.new(dio_id,{"model":model,"model_id":model_id})
return 1,"ok"
[docs]def deinit_dio(dio_id):
"Deregister a DIO from the pool"
try:
dio=dio_pool.get(dio_id)
except Exception as e:
return 0,str(e)
# Call the deinitializer function for the model
retcode,res=submod_execcmd("deinit@"+dio["model"],dio["model_id"])
if retcode==0:
return 0,"Error deinitializing %s power supply <- %s" % (dio["model"],res)
# Remove dio from the pool
try:
dio_pool.remove(dio_id)
except Exception as e:
return 0,str(e)
return retcode,res
[docs]def config_dio(dio_id):
"Configure the DIO"
try:
dio=dio_pool.get(dio_id)
except Exception as e:
return 0,str(e)
# Call the configuration function for the model
retcode,res=submod_execcmd("config@"+dio["model"],dio["model_id"])
if retcode==0:
return 0,"Error configuring %s power supply <- %s" % (dio["model"],res)
return retcode,res
[docs]def inval_dio(dio_id):
"Invalidate configuration of DIO"
try:
dio=dio_pool.get(dio_id)
except Exception as e:
return 0,str(e)
# Call the invalidation function for the model
retcode,res=submod_execcmd("inval@"+dio["model"],dio["model_id"])
if retcode==0:
return 0,"Error invalidating %s power supply <- %s" % (dio["model"],res)
return retcode,res
[docs]def set_digital_dio(dio_id,level):
"Set digital *level* (high/low)"
try:
dio=dio_pool.get(dio_id)
except Exception as e:
return 0,str(e)
retcode,res=submod_execcmd("set_digital"+"@"+dio["model"],dio["model_id"],level)
if retcode==0:
return 0,"Error setting digital IO <- %s"%(res)
return 1,res