I am currently forcing some errors using serial to test I am reading them correctly.
JavaScript
x
13
13
1
def errorCheck():
2
while(1):
3
if(ser.in_waiting >= 0):
4
serString = ser.readline()
5
decoding = serString.decode('Ascii')
6
serDecode = str(decoding)
7
if(serDecode in errorHandling):
8
ErrMsg(serDecode)
9
return
10
break
11
12
errorHandling = ["*F", "*N", "*I", "*U", "*L"]
13
I am receiving at least one error message each time that is within errorHandling. But for some reason, the if statement isn’t recognising the error code as being in the errorHandling list. What am I missing?
printing to console shows me this
JavaScript
1
4
1
*U <---This is serDecode
2
['*F', '*N', '*I', '*U', '*L'] <---- errorHandling list
3
False <---printing serDecode in errorHandling
4
Advertisement
Answer
As stated by @MByD I needed to strip(‘r’) from my received readline().
so the code now looks like this:
JavaScript
1
12
12
1
def errorCheck():
2
while(1):
3
if(ser.in_waiting >= 0):
4
serString = ser.readline()
5
serDecode = serString.decode('Ascii').strip('r')
6
if(serDecode in errorHandling):
7
ErrMsg(serDecode)
8
return
9
break
10
11
errorHandling = ["*F", "*N", "*I", "*U", "*L"]
12
The carriage return was invisible on my console, so I wasn’t aware it was there.