I am sending a float value to a python program as follows.
Serial.write((byte)1.001);
Python function to read the data:
def on_buttonClick_runTest(self, button):
print("\n Beginning Test..")
totx = []
t = []
self.port.write('b')
print ("\n Starting Test")
self.port.flush()
#Start Sampling Takes 2000 samples
while len(totx) < 2000:
totx.append(self.port.read(4))
print("\n Finish")
self.port.write('a')
#Converts to float
for i in totx:
try:
t.append(struct.unpack('>f', i))
except:
pass
for i in t:
print(i)
'''
for i in totx:
try:
temp = float(i)/9.81
if temp > 16:
t.append(0)
else:
t.append(temp)
except:
pass
for i in t:
print(i)
'''
self.port.flush()
#display Figure
fig = pl.figure(figsize= (4.25,4))
pl.title('G / Samples')
#Spl.axhline(15)
pl.plot(t, color="black")
fig.savefig('plot.png')
self.image_icon.set_from_file("plot.png")
#fig.show()
and the result I get is this:
(2.5784852031307537e-09,)
(2.5784852031307537e-09,)
(2.5784852031307537e-09,)
(2.5784852031307537e-09,)
…
Can anyone explain this to me. I’ve tried both little and big ended with struct.unpack