0 Replies - 421 Views - Last Post: 28 October 2019 - 09:05 AM Rate Topic: -----

#1 gratna   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-October 19

Sending 4 bytes Hex data over serial in PyQt

Posted 28 October 2019 - 09:05 AM

Hi,

I would like to send 4 Bytes of Hex data over serial to a microcontroller which are being received from GUI in PyQt5.
For example, consider the first two bytes received as characters 'a' and 'b' while the remaining two bytes as integers (ranging from 0 to 127) and I would like to send all the 4 bytes as Hex values over serial.Kindly help.

firstByte = 'a'
secondByte = 'b'
thirdByte = 100
fourthByte = 120

Until now I have tried the following methods but they did not help my case.

1.
thirdByte = 100
fourthByte = 120
my_bytestring3 = bytes([hex(ord('a')), hex(ord('b')), hex(thirdByte), hex(fourthByte)])
serial.write(my_bytestring3)

2.
thirdByte = 100
fourthByte = 120
my_bytestring2 = bytes([int(a), int(B), thirdByte, fourthByte])
serial.write(my_bytestring2)


Thanks in advance,
gratna

Is This A Good Question/Topic? 0
  • +

Page 1 of 1