【发布时间】:2012-08-06 09:57:04
【问题描述】:
我从串行端口获取代表 PIC 板上电压的字节。 但是我无法将这些字节(字符串)转换为十进制,因为我收到了上面的错误消息。 这里是函数(其实是和tkinter按钮关联的)
def channel8():
ser.write(chr(0xFF))
print "you have select channel8"
x=ser.read(2)
w=int(x, 16)
print w
print "Voltage on channel8 is:" , x
ValueError: int() 基数为 16 的无效文字:'\x0e\xa3'
def channel8():
ser.write(chr(0xFF))
print "you have select channel8"
x=ser.read(2)
z=struct.unpack("h", x)
#w=int(z, 16)
print z
我明白了:
通道 8 上的电压为:(28942,)
你能解释一下我是如何得到这个值的吗?它不匹配任何东西:D
【问题讨论】:
标签: python string tkinter decimal pyserial