Пример #1
0
 def _setupMbus(self):
     """create the mbus connection"""
     try:
         path = config.getConfig('mbus', 'libpath', None)
         if not config.configs.has_option('mbus', 'device'):
             if not config.configs.has_option('mbus', 'host'):
                 logger.error('mbus configuration missing: device or host')
                 return
             else:
                 if config.configs.has_option('mbus', 'port'):
                     self._mbus = MBus(host=config.configs.get('mbus', 'host'), port=config.configs.get('mbus', 'port'), libpath=path)
                 else:
                     self._mbus = MBus(host=config.configs.get('mbus', 'host'), libpath=path)
         else:
             self._mbus = MBus(device=config.configs.get('mbus', 'device'), libpath=path)
     except:
         logger.exception("failed to setup mbus")
Пример #2
0
 def _reconnect(self):
     if self._mbus:
         try:
             self._mbus.disconnect()
             self._mbus = None
         except Exception as ex:
             log.error("MBus close exception %s", ex)
     if not self._mbus:
         try:
             self._mbus = MBus(device=self._port, libpath='./libmbus.so')
         except Exception as ex:
             log.error("MBus create exception %s", ex)
             return
         try:
             self._mbus.connect()
         except Exception as ex:
             log.error("MBus open exception %s", ex)
             self._mbus = None
Пример #3
0
 def __init__(self, libpath=None):
     self._mbus = MBus(host="localhost", port=8888, libpath=libpath)
     self._mbus_frame = MBusFrame()
Пример #4
0
#!/usr/bin/env python3
# ------------------------------------------------------------------------------
# Copyright (C) 2012, Robert Johansson <*****@*****.**>, Raditex Control AB
# All rights reserved.
# ------------------------------------------------------------------------------
"""
mbus test: send a request frame and receive and parse the reply
"""

from mbus.MBus import MBus

debug = True
address = 1

mbus = MBus(host="mbus-gw1", port=8888)

if debug:
    print("mbus = " + str(mbus))

mbus.connect()

if debug:
    print("mbus = " + str(mbus))

mbus.send_request_frame(address)

reply = mbus.recv_frame()

if debug:
    print("reply =", reply)
Пример #5
0
#!/usr/bin/env python3
# ------------------------------------------------------------------------------
# Copyright (C) 2012, Robert Johansson <*****@*****.**>, Raditex Control AB
# All rights reserved.
# ------------------------------------------------------------------------------
"""
mbus test: send a request frame and receive and parse the reply
"""

from mbus.MBus import MBus

debug = True
address = 0

#mbus = MBus(host="mbus-gw1", port=8888)
mbus = MBus(device="/dev/ttyUSB0",
            libpath="/home/ph/git/python-mbus/examples/libmbus.so")

if debug:
    print("mbus = " + str(mbus))

mbus.connect()

if debug:
    print("mbus = " + str(mbus))

mbus.serial_set_baudrate(2400)

res = mbus.send_ping_frame(0xFD, 1)
print(res)
res = mbus.send_ping_frame(0, 1)
print(res)