IndexError: string index out of range, pyserial tkinter, python 3.4
IndexError: string index out of range, pyserial tkinter, python 3.4
我正在尝试在我的串口识别出 **@* 或 **`* 后更改标签的颜色
这是我的代码
while set_ser.isOpen():
time.sleep(0.0001)
bytess = set_ser.inWaiting()
bytes = set_ser.read(bytess)
get_serial = str(bytes.decode("utf-8", errors="ignore"))
loop.set(get_serial)
if (get_serial[2]=='@'): #busy
sLabelRead.configure(bg = 'red', fg='white')
sLabelRead.place(x=10,y=600)
mGui.update()
elif (get_serial[2]=='`'): #ready:
sLabelRead.configure(bg = 'orange', fg='black')
sLabelRead.place(x=10,y=600)
mGui.update()
elif (get_serial==''): #none:
sLabelRead.configure(bg = 'black', fg='white')
sLabelRead.place(x=10,y=600)
mGui.update()
mGui.update()
else:
print (get_serial)
mGui.update()
但是我收到这个错误
if (get_serial[1]=='@'): #busy
IndexError: string index out of range
谁能帮帮我
谢谢
确实我的字符串少于 2 个字符。所以我只是检查了它的长度并修改了我的条件,谢谢,我并没有一直得到 2 或 3 个元素,有时只有 1 个或什么都没有
我正在尝试在我的串口识别出 **@* 或 **`* 后更改标签的颜色
这是我的代码
while set_ser.isOpen():
time.sleep(0.0001)
bytess = set_ser.inWaiting()
bytes = set_ser.read(bytess)
get_serial = str(bytes.decode("utf-8", errors="ignore"))
loop.set(get_serial)
if (get_serial[2]=='@'): #busy
sLabelRead.configure(bg = 'red', fg='white')
sLabelRead.place(x=10,y=600)
mGui.update()
elif (get_serial[2]=='`'): #ready:
sLabelRead.configure(bg = 'orange', fg='black')
sLabelRead.place(x=10,y=600)
mGui.update()
elif (get_serial==''): #none:
sLabelRead.configure(bg = 'black', fg='white')
sLabelRead.place(x=10,y=600)
mGui.update()
mGui.update()
else:
print (get_serial)
mGui.update()
但是我收到这个错误
if (get_serial[1]=='@'): #busy
IndexError: string index out of range
谁能帮帮我 谢谢
确实我的字符串少于 2 个字符。所以我只是检查了它的长度并修改了我的条件,谢谢,我并没有一直得到 2 或 3 个元素,有时只有 1 个或什么都没有