Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将浮点数写入串行端口_Python_Python 3.x_Pyserial - Fatal编程技术网

Python 如何将浮点数写入串行端口

Python 如何将浮点数写入串行端口,python,python-3.x,pyserial,Python,Python 3.x,Pyserial,我想向串行端口发送一个浮点数。我写了这段代码: 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") 是吗?我们无法回答这个问题:这完全

我想向串行端口发送一个浮点数。我写了这段代码:

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")

是吗?

我们无法回答这个问题:这完全取决于连接另一端的内容。在这里,您将浮点数打包为二进制表示,但是如果另一端的东西需要一个简单的ASCII字符串呢?还是JSON?还是别的什么?有什么问题吗?