예제 #1
0
    def test_create_id(self):
        for i in range(0xFF):
            br = Baudrate(i, baudtype=Baudrate.Type.Identifier)
            self.assertEqual(br.get_bytes(), struct.pack('B', i))

        with self.assertRaises(ValueError):
            br = Baudrate(0x100, baudtype=Baudrate.Type.Identifier)
예제 #2
0
    def test_create_auto(self):
        # Direct ID
        br = Baudrate(1)
        self.assertEqual(br.get_bytes(), b'\x01')

        br = Baudrate(0xFF)
        self.assertEqual(br.get_bytes(), b'\xFF')

        # Fixed baudrate
        br = Baudrate(115200)
        self.assertEqual(br.get_bytes(), b'\x05')

        br = Baudrate(500000)
        self.assertEqual(br.get_bytes(), b'\x12')

        #Specific Baudrate:
        br = Baudrate(0x123456)
        self.assertEqual(br.get_bytes(), b'\x12\x34\x56')
예제 #3
0
    def test_create_specific(self):
        br = Baudrate(115200, baudtype=Baudrate.Type.Specific)
        self.assertEqual(br.get_bytes(), b'\x01\xC2\x00')

        with self.assertRaises(ValueError):
            br = Baudrate(0x1000000, baudtype=Baudrate.Type.Specific)
예제 #4
0
    def test_create_fixed(self):
        br = Baudrate(115200, baudtype=Baudrate.Type.Fixed)
        self.assertEqual(br.get_bytes(), b'\x05')

        with self.assertRaises(ValueError):
            br = Baudrate(123456, baudtype=Baudrate.Type.Fixed)