Beispiel #1
0
 def test_ihexcksum(self):
     self.assertEqual(hexutils.ihexcksum(':03000006030000F4'), 'F4')
     self.assertEqual(hexutils.ihexcksum(':03000006030000'), 'F4')
     self.assertEqual(hexutils.ihexcksum(':00000001FF'), 'FF')
     self.assertEqual(hexutils.ihexcksum(':00000001'), 'FF')
     self.assertEqual(hexutils.ihexcksum(':100130003F0156702B5E712B722B732146013421C7'), 'C7')
     self.assertEqual(hexutils.ihexcksum(':100130003F0156702B5E712B722B732146013421'), 'C7')
Beispiel #2
0
    def send(self, data):
        """Send message to device."""
# we suppose that trought serial line is send only intel hex
# so we check if hex is OK or need append checksum
        if data[0] != ':':
            raise ValueError("FIXME: we expect intel hex but got: %s" % data)
        l = int(data[1:3], 16)
        if 1 + 2 + 4 + 2 + 2*l == len(data):
            data = data + hexutils.ihexcksum(data)
        elif 1 + 2 + 4 + 2 + 2*l + 2 != len(data):
            raise ValueError("FIXME: Invalid lenght for intel hex???: %s" % data)
        print("SerialIO.send(%s)" % data)
        return self.port.write(bytes(data, 'ascii') + self._nl)
Beispiel #3
0
 def send(self, data):
     """Send message to device."""
     # we suppose that trought serial line is send only intel hex
     # so we check if hex is OK or need append checksum
     if data[0] != ':':
         raise ValueError("FIXME: we expect intel hex but got: %s" % data)
     l = int(data[1:3], 16)
     if 1 + 2 + 4 + 2 + 2 * l == len(data):
         data = data + hexutils.ihexcksum(data)
     elif 1 + 2 + 4 + 2 + 2 * l + 2 != len(data):
         raise ValueError("FIXME: Invalid lenght for intel hex???: %s" %
                          data)
     print("SerialIO.send(%s)" % data)
     return self.port.write(bytes(data, 'ascii') + self._nl)
Beispiel #4
0
 def test_ihexcksum(self):
     self.assertEqual(hexutils.ihexcksum(':03000006030000F4'), 'F4')
     self.assertEqual(hexutils.ihexcksum(':03000006030000'), 'F4')
     self.assertEqual(hexutils.ihexcksum(':00000001FF'), 'FF')
     self.assertEqual(hexutils.ihexcksum(':00000001'), 'FF')
     self.assertEqual(
         hexutils.ihexcksum(':100130003F0156702B5E712B722B732146013421C7'),
         'C7')
     self.assertEqual(
         hexutils.ihexcksum(':100130003F0156702B5E712B722B732146013421'),
         'C7')