Esempio n. 1
0
class QDataStreamWrite(unittest.TestCase):
    '''Test case for QDatastream write* functions'''

    def setUp(self):
        self.ba = QByteArray()
        self.read = QDataStream(self.ba, QIODevice.ReadOnly)
        self.write = QDataStream(self.ba, QIODevice.WriteOnly)

    def testWriteUInt8(self):
        '''QDataStream.writeUInt8 (accepting str of size 1)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeUInt8, 'aaaaa')

    def testWriteInt8(self):
        '''QDataStream.writeInt8 (accepting str of size 1)'''
        x = 65
        self.write.writeInt8(chr(x))
        y = self.read.readInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeInt8, 'aaaaa')

    def testWriteUInt8Int(self):
        '''QDataStream.writeUInt8 (accepting integer)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

    def testWriteInt8Int(self):
        '''QDataStream.writeInt8 (accepting integer)'''
        x = 65
        self.write.writeInt8(x)
        y = self.read.readInt8()
        self.assertEqual(x, y)

    def testWriteUInt16(self):
        '''QDataStream.writeUInt16'''
        x = 0x4423
        self.write.writeUInt16(x)
        y = int(self.read.readUInt16())
        self.assertEqual(x, y)

    def testWriteUInt32(self):
        '''QDataStream.writeUInt32'''
        x = 0xdeadbeef
        self.write.writeUInt32(x)
        y = int(self.read.readUInt32())
        self.assertEqual(x, y)
Esempio n. 2
0
class QDataStreamWrite(unittest.TestCase):
    '''Test case for QDatastream write* functions'''

    def setUp(self):
        self.ba = QByteArray()
        self.read = QDataStream(self.ba, QIODevice.ReadOnly)
        self.write = QDataStream(self.ba, QIODevice.WriteOnly)

    def testWriteUInt8(self):
        '''QDataStream.writeUInt8 (accepting str of size 1)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeUInt8, 'aaaaa')

    def testWriteInt8(self):
        '''QDataStream.writeInt8 (accepting str of size 1)'''
        x = 65
        self.write.writeInt8(chr(x))
        y = self.read.readInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeInt8, 'aaaaa')

    def testWriteUInt8Int(self):
        '''QDataStream.writeUInt8 (accepting integer)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

    def testWriteInt8Int(self):
        '''QDataStream.writeInt8 (accepting integer)'''
        x = 65
        self.write.writeInt8(x)
        y = self.read.readInt8()
        self.assertEqual(x, y)

    def testWriteUInt16(self):
        '''QDataStream.writeUInt16'''
        x = 0x4423
        self.write.writeUInt16(x)
        y = int(self.read.readUInt16())
        self.assertEqual(x, y)

    def testWriteUInt32(self):
        '''QDataStream.writeUInt32'''
        x = 0xdeadbeef
        self.write.writeUInt32(x)
        y = int(self.read.readUInt32())
        self.assertEqual(x, y)
Esempio n. 3
0
    def MoveDCMotors(self, MotorsSpeed: DC_Motor_Control_Data):
        self.STEP_MOTOR_COMMAND = QByteArray()
        stream = QDataStream(self.STEP_MOTOR_COMMAND,
                             QtCore.QIODevice.ReadWrite)

        stream.writeInt8(self.MotorsState.HEADER_B1)
        stream.writeInt8(self.MotorsState.HEADER_B2)
        stream.writeInt8(self.MotorsState.UNIT_SIZE)

        stream.writeInt16(self.MotorsState.Speed1)
        stream.writeInt16(self.MotorsState.Speed2)
        stream.writeInt16(self.MotorsState.Speed3)
        stream.writeInt16(self.MotorsState.Speed4)
Esempio n. 4
0
    def send_data_old_main_board(self):

        datagram = QByteArray()
        stream = QDataStream(datagram, QIODevice.WriteOnly)
        # print(self.angularspeed.joint1)
        low_byte1, high_byte1 = two_byte_int_to_byte(self.angularspeed.joint1)
        low_byte2, high_byte2 = two_byte_int_to_byte(self.angularspeed.joint2)
        low_byte3, high_byte3 = two_byte_int_to_byte(self.angularspeed.joint3)
        low_byte4, high_byte4 = two_byte_int_to_byte(
            self.angularspeed.prismatic)
        low_byte5, high_byte5 = two_byte_int_to_byte(self.angularspeed.joint4)
        low_byte6, high_byte6 = two_byte_int_to_byte(self.angularspeed.joint5)
        low_byte7, high_byte7 = two_byte_int_to_byte(
            self.angularspeed.sensor_box)

        stream.writeInt8(self.direction.joint1)
        stream.writeInt8(self.direction.joint2)
        stream.writeInt8(self.direction.joint3)
        stream.writeInt8(self.direction.prismatic)
        stream.writeInt8(self.direction.joint4)
        stream.writeInt8(self.direction.joint5)

        stream.writeInt8(self.direction.sensor_box)

        stream.writeUInt8(low_byte1)
        stream.writeUInt8(high_byte1)

        stream.writeUInt8(low_byte2)
        stream.writeUInt8(high_byte2)

        stream.writeUInt8(low_byte3)
        stream.writeUInt8(high_byte3)

        stream.writeUInt8(low_byte4)
        stream.writeUInt8(high_byte4)

        stream.writeUInt8(low_byte5)
        stream.writeUInt8(high_byte5)

        stream.writeUInt8(low_byte6)
        stream.writeUInt8(high_byte6)

        stream.writeUInt8(low_byte7)
        stream.writeUInt8(high_byte7)

        stream.writeUInt8(self.reset_motor.reset_main_board_motor)
        stream.writeUInt8(self.home_position.home_position)
        stream.writeUInt8(self.emergency_stop.emergency_stop)
        self.socket_old_main_board.writeDatagram(
            datagram, self.main_board_ip, self.mainboard_port)
Esempio n. 5
0
    def MoveStepMotor(self, MotorCommand: Step_Motor_Control_Data):

        stream = QDataStream(self.STEP_MOTOR_COMMAND,
                             QtCore.QIODevice.ReadWrite)
        stream.writeInt8(MotorCommand.HEADER_B1)
        stream.writeInt8(MotorCommand.HEADER_B2)
        stream.writeInt8(MotorCommand.UNIT_SIZE)

        stream.writeInt16(MotorCommand.SpeedMotor1)
        stream.writeInt16(MotorCommand.SpeedMotor2)
        stream.writeInt16(MotorCommand.SpeedMotor3)

        stream.writeInt16(MotorCommand.AngleMotor1)
        stream.writeInt16(MotorCommand.AngleMotor2)
        stream.writeInt16(MotorCommand.AngleMotor3)
 def __rshift__(self, Sender: QDataStream):
     Sender.writeInt16(self.HEADER_B1)
     Sender.writeInt16(self.HEADER_B2)
     Sender.writeInt16(self.UNIT_SIZE)
     Sender.writeInt8(self.Connect)