如何使用 Pyserial 编写两个数字变量

How do I write two numeric variables using Pyserial

一个简单的小问题: 我想在 Python 中将数字变量写入串行。 这是在 if 循环中完成的。类似于:

If(condition=true):
    ser.write(str(value1)
    ser.write(str(value2)

这是否正确?

或者我应该这样做:

If(condition=true):
    ser.write(str(value1), (str(value2))

我知道这很简单,但卡在这里了。将这些值写入 Arduino。

提前致谢

您可以做的不是用不同的方式编写每个值,而是制作一个值的字符串,然后在 arduino 上解码该字符串以从编码数据中获取值。以下是您可以在列表中执行的功能列表,并且在大多数情况下可以完成所需的工作。

Strings Reference

快乐编码。希望这会有所帮助。