Notifications
Clear all

Structures, Serialisation, XOR Checksums etc.

91 Posts
7 Users
8 Reactions
30.5 K Views
(@pugwash)
Sorcerers' Apprentice
Joined: 6 years ago
Posts: 923
Topic starter  

@frogandtoad

Here's a bit of info on struct packing,

After reading the article, I changed the sketch again to:

typedef struct{
  float afloat = 15.4;
  uint8_t abyte = 12;  
  uint8_t bbyte = 5;
  }data;

data myData; 

and the Python code to:

while True:

data = ser.read(6)

#struct.unpack(format, bytestring)
tup = struct.unpack('fcc', data)
print(data)
print(tup)

ser.close()

And got the following aligned output:

(15.399999618530273, b'\x0c', b'\x05')
b'ffvA\x0c\x05'
(15.399999618530273, b'\x0c', b'\x05')
b'ffvA\x0c\x05'

I guess I can get back to my pre-Xmas stress now ? 

 


   
ReplyQuote
Page 7 / 7