Пример #1
0
    def test_request_frame(self):
        self.reset()
        frame = meterbus.TelegramShort()
        frame.header.cField.parts = [
            meterbus.CONTROL_MASK_REQ_UD2 | meterbus.CONTROL_MASK_DIR_M2S
        ]
        frame.header.aField.parts = [0]

        meterbus.send_request_frame(self.master, req=frame)

        self.assertEqual(self.slave.read(5), b"\x10\x5B\x00\x5B\x16")
Пример #2
0
 def test_frame_crc(self):
     frame = meterbus.TelegramShort(self.frame)
     self.assertEqual(frame.check_crc(), True)
Пример #3
0
 def test_frame_header_setter(self):
     frame = meterbus.TelegramShort(self.frame)
     hdr = meterbus.TelegramHeader()
     frame.header = hdr
     self.assertIs(frame.header, hdr)
Пример #4
0
    def test_load_crc_error(self):
        frame_data = list(self.frame)
        frame_data[-2] = '\xFF'

        with self.assertRaises(MBusFrameCRCError):
            meterbus.TelegramShort(frame_data)
Пример #5
0
 def test_load_bytes(self):
     frame = meterbus.TelegramShort(self.frame_bytes)
     frame_bytes = list(map(char2int, list(self.frame_bytes)))
     self.assertEqual(list(frame), frame_bytes)
Пример #6
0
    def test_load_crc_error(self):
        frame_data = list(map(char2int, list(self.frame_bytes)))
        frame_data[-2] = 255

        with self.assertRaises(MBusFrameCRCError):
            meterbus.TelegramShort(frame_data)