def setUp(self): ''' Initializes the test environment ''' self.context = ModbusSlaveContext(**{ 'di' : ModbusSequentialDataBlock(0, [0]*100), 'co' : ModbusSequentialDataBlock(0, [0]*100), 'ir' : ModbusSequentialDataBlock(0, [0]*100), 'hr' : ModbusSequentialDataBlock(0, [0]*100)}) self.initialize()
def modbus_context_decoder(mapping_blocks): """ Given a mapping block input, generate a backing slave context with initialized data blocks. .. note:: This expects the following for each block: address, value, and function where function is one of di (discretes), co (coils), hr (holding registers), or ir (input registers). :param mapping_blocks: The mapping blocks :returns: The initialized modbus slave context """ blocks = defaultdict(dict) for block in mapping_blocks.itervalues(): for mapping in block.itervalues(): value = int(mapping['value']) address = int(mapping['address']) function = mapping['function'] blocks[function][address] = value return ModbusSlaveContext(**blocks)
def create_context(inverter): fdb = FroniusDataBlock(inverter) return ModbusSlaveContext(hr=fdb, it=fdb)