Ejemplo n.º 1
0
 def test_readTelegram(self):
     vc = c.viCommand('Anlagentyp')
     vt = v.viTelegram(vc, 'read')
     self.assertEqual('4105000100f80200', vt.hex())
     vc = c.viCommand('Warmwassertemperatur')
     vt = v.viTelegram(vc, 'read')
     self.assertEqual('41050001010d0216', vt.hex())
Ejemplo n.º 2
0
    def execWriteCmd(self, cmdname, value) -> viData:
        # sends a read command and gets the response.

        vc = viCommand(cmdname)
        if not vc.write:
            raise viControlException(f'command {cmdname} cannot be written')

        # create viData object
        vd = viData.create(vc.unit, value)
        # create write Telegram
        vt = viTelegram(vc, 'Write', 'Request', vd)
        # send Telegram
        self.vs.send(vt)

        # Check if sending was successfull
        ack = self.vs.read(1)
        logging.debug(f'Received  {ack.hex()}')
        if ack != ctrlcode['acknowledge']:
            raise viControlException(
                f'Expected acknowledge byte, received {ack}')

        # Receive response and evaluate data
        vr = self.vs.read(vt.__responselen__)  # receive response
        logging.debug(
            f'Requested {vt.__responselen__} bytes. Received telegram {vr.hex()}'
        )

        self.vs.send(ctrlcode['acknowledge'])  # send acknowledge

        vt = viTelegram.frombytes(vr)  # create response Telegram
        if vt.tType == viTelegram.tTypes['error']:
            raise viControlException('Write command returned an error')

        return viData.create(vt.vicmd.unit,
                             vt.payload)  # return viData object from payload
Ejemplo n.º 3
0
 def execWriteCmd(self, cmdName, value):
     vc = viCommand(cmdName)
     return None
Ejemplo n.º 4
0
 def execReadCmd(self, cmdName):
     vc = viCommand(cmdName)
     return viData.create('IUNON', random.randint(0, 50))
Ejemplo n.º 5
0
 def test_vicmdWarmwassertemperatur(self):
     # create command from string
     vc = viCommand('Warmwassertemperatur')
     self.assertEqual(vc.hex(), '010d02')
Ejemplo n.º 6
0
 def test_vicmdAussentemperatur(self):
     # create command from string
     vc = viCommand('Aussentemperatur')
     self.assertEqual(vc.hex(), '010102')
Ejemplo n.º 7
0
 def test_vicmdWWeinmal(self):
     # create command from string
     vc = viCommand('WWeinmal')
     self.assertEqual(vc.hex(), 'b02001')
Ejemplo n.º 8
0
 def test_vicmdAnlagentyp(self):
     # create command from string
     vc = viCommand('Anlagentyp')
     self.assertEqual(vc.hex(), '00f802')
Ejemplo n.º 9
0
 def test_vicmdnomatch(self):
     # Command not existing
     with self.assertRaises(viCommandException):
         vc = viCommand.frombytes(b'\xF1\x00')
     with self.assertRaises(viCommandException):
         vc = viCommand('foo')