0

I have two rfid card the values are 0004518403 and 000452738 after reading their value in python terminal. I want to give them name like 0004518403 is "javed" and 000452738 as "aquib". So when next time when I use the card it must not show me the value but it must show me the name which I've defined to them.

import serial
import time
serial = serial.Serial('/dev/ttyUSB0', baudrate = 9600)
while True:
if serial.inWaiting() > 0:
    read_result =serial.read(15)
    print("Sleeping 2 seconds")

    if(read_result==0004520738):
        print "aquib"
    elif(read_result==0004518403):
        print "javed"

    time.sleep(2)
    serial.flushInput() # ignore errors, no data

I am trying this code but it show me an error :

SyntaxError: invalid token

In the first if condition. I am not getting where is the problem.

1 Answer 1

2

You should compare read results with strings, not numbers, like

read_result=='0004520738'

0004520738 without quotes is a number. As it starts with a 0 sign, it is interpreted as number of base 8. Numbers of base 8 cannot contain digits 8 and 9 apparently.

>>> 01234567
342391
>>> 012345678
  File "<stdin>", line 1
    012345678
            ^
SyntaxError: invalid token
>>> 

Also I don't get why you read 15 bytes, but compare results with 10 bytes string, that's smth wrong there

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.