我想做一个程序,从串口获取数据的开始和停止位将是*和#。收到的数据将在* 1234567#这种形式。但它说我的'类型'对象不是可以下载的。我对Python真的很陌生,我不知道下一步该怎么做,任何人都可以帮我解决这个问题吗?类型错误发生使用缓冲区memoryview
import serial
ser = serial.Serial(
port='COM5',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=0)
MAX_BUF_SIZE = 16
bits = 0
v = memoryview
print("connected to: " + ser.portstr)
while(1):
for memoryview in ser.read():
if v[0] == 42:
if v[-1] == 35:
print(v[1:-1].tobytes())
else:
memoryview = 0
ser.close()
connected to: COM5
Traceback (most recent call last):
File "C:\Python33\Saves\Receive using buff.py", line 24, in <module>
if v[0] == 42:
TypeError: 'type' object is not subscriptable
>>>
最初是什么'memoryview'?你把它分配给v。基本上这个错误说你不能在'v [0]中使用[]运算符'v' – Juho 2013-05-03 07:44:59
@Jhoho:'memoryview'是一个内建的。 – 2013-05-03 08:02:22