Python - 从 QlineEdit 读取数据并将其作为十六进制字节发送到串行?

Python - read data from QlineEdit and send as hex bytes to Serial?

我想转换来自 QLineEdit 的输入并以十六进制字节发送到串行。

示例:

QlineEdit input03040506

写入串行为0x03 0x04 0x05 0x06

谢谢,

您可以使用 bytes.fromhex

轻松完成此操作
data = "03040506"
out = bytes.fromhex(data)
print(out)

输出

b'\x03\x04\x05\x06'

要将这些字节发送到串行端口,只需执行类似 ser.write(out) 的操作,其中 ser 是一个打开的串行端口。