我从串口获取字节,表示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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
我得到这个:
通道8上的电压为:(28942,)
你能解释一下我是如何得到这个价值的吗?它不匹配任何东西:D