0

I want to send a float number to serial port. I wrote this code:

import serial
import time
import struct

my_float = 125.568
my_data = struct.pack('f',my_float)
n=ser.write(my_data)
# print(ser.write() + " Bytes successfully written")
print(n,"Bytes successfully written")

Is that right?

khelwood
  • 55,782
  • 14
  • 81
  • 108
shina
  • 1
  • We're not able to answer this question: it depends entirely on what is on the other end of the connection. You're packing the float into a binary representation here, but what if the thing on the other ends wants a simple ASCII string? Or JSON? Or something else? – larsks Nov 25 '19 at 12:47
  • what's the issue? – gold_cy Nov 25 '19 at 12:48

0 Answers0