Source code for cmd_om_ithx_m

#!/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

om_ithx_m_pool=pools.pool()

[docs]def init_om_ithx_m(om_ithx_m_id,conf_string): """Initialize OM_ITHX_M meter. conf_string must contain the parameters: - bus: a conf_string for cmd_tcp""" try: conf=conf_strings.parse(conf_string) except Exception as e: return 0,str(e) if conf.name!="om_ithx_m": return 0,"Invalid module name %s in conf_string instead of om_ithx_m"%(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) conf_bus.params["port"]=2000 bus_id="bus_%s"%(om_ithx_m_id) retcode,res=submod_execcmd("init@"+conf_bus.name,bus_id,conf_strings.unparse(conf_bus)) if retcode==0: return 0,"Error initializing link <- %s" % (res) om_ithx_m_pool.new(om_ithx_m_id,{"bus":conf_bus.name,"bus_id":bus_id,"conf_string":conf_string}) return 1,"ok"
[docs]def deinit_om_ithx_m(om_ithx_m_id): "Deinitialize *om_ithx_m_id* meter." try: om_ithx_m=om_ithx_m_pool.get(om_ithx_m_id) except Exception as e: return 1,str(e) retcode,res=submod_execcmd("deinit@"+om_ithx_m["bus"],om_ithx_m["bus_id"]) if retcode==0: return 0,"Error deinitializing link <- %s" % (res) om_ithx_m_pool.remove(om_ithx_m_id) return 1,"ok"
def config_om_ithx_m(om_ithx_m_id): return 1,"ok" def inval_om_ithx_m(om_ithx_m_id): return 1,"ok" def wrnrd(om_ithx_m_id,cmd): try: om_ithx_m=om_ithx_m_pool.get(om_ithx_m_id) except Exception as e: return 0,str(e) retcode,res=submod_execcmd("config@"+om_ithx_m["bus"],om_ithx_m["bus_id"]) if retcode==0: return 0,"Error configuring link <- %s" % (res) retcode,res=submod_execcmd("wrnrd_until@"+om_ithx_m["bus"],om_ithx_m["bus_id"],cmd+r"\r",r"\r") if retcode==0: return 0,"Error reading temperature <- %s" % (res) value=str(float(res)) retcode,res=submod_execcmd("inval@"+om_ithx_m["bus"],om_ithx_m["bus_id"]) if retcode==0: return 0,"Error invalidating link <- %s" % (res) return 1,value
[docs]def get_temp_om_ithx_m(om_ithx_m_id): "Take a temperature measure from *om_ithx_m_id* meter" return wrnrd(om_ithx_m_id,"*SRT")
[docs]def get_rh_om_ithx_m(om_ithx_m_id): "Take a humidity measure from *om_ithx_m_id* meter" return wrnrd(om_ithx_m_id,"*SRH")