I have an RFID reader that attaches via USB. Via `/var/log/syslog` I found out, that it is available as `/dev/tty1`. The following Python script should read and print the scanned RFID tags:

    #!/usr/bin/python3
    import sys,datetime
    
    def main():
        while True:
            sys.stdin = open('/dev/tty1', 'r')
            rfid = input()
            print("Read code from RFID reader: "+str(rfid.rstrip()))
            sys.stdin.close()
    
    main()

While this **usually** works fine, it is not reliable at all. For the first scan, the reader beeps as if it read successfully, but the script doesn't print anything.

The firs thing that is read/printed by the script is a mangled RFID. The following scans work, but some of the read RFIDs are skipped. After a while the script crashes.

Read code from RFID reader: 002420004284829
Read code from RFID reader: 0004284829
Read code from RFID reader: 0004284829
[...]
Traceback (most recent call last):
  File "rfid.py", line 14, in <module>
    main()
  File "rfid.py", line 7, in main
    rfid = input()
EOFError: EOF when reading a line

How can I modify the script to be more reliable. In the end the Raspberry Pi 2 should log the days and time where specific tags are scanned.