rick_2047
rick_2047

Reputation: 23

pySerial receives as ASCII how to convert into integer?

I am using pySerial to talk to an MSP430 module. This module is transmitting over serial and I am using pySerial to read (as in com.read(20) ). But the type of what pyserial receives is ascii. So when I send out 0x37 from the MSP430 it receives it as '7' and all this is then given to me as a string something like "7☺7" for [0x37 0x1 0x37]. How do I retrieve my data in the same array format I intend. The next step is to plot it using pylab.

Upvotes: 1

Views: 1659

Answers (1)

phihag
phihag

Reputation: 287865

Unpack the data with struct:

>>> import struct
>>> data = '\x37\x01\x37'
>>> struct.unpack('!BBB', data)
(55, 1, 55)

Upvotes: 2

Related Questions