def SetPollingDalay(fd):
    # set the polling delay for the reader
    print ("Setting Polling delay .......")
    WaitForCTS()

    wiringpi2.serialPutchar(fd, 0x50)
    wiringpi2.serialPutchar(fd, 0x00)
    # various polling delays possible, standard one uncommented
    #wiringpi2.serialPutchar(fd, 0x00) # 0x00 is no delay
    #wiringpi2.serialPutchar(fd, 0x20) # 0x20 is approx 20ms
    #wiringpi2.serialPutchar(fd, 0x40) # 0x40 is approx 65ms
    wiringpi2.serialPutchar(fd, 0x60) # 0x60 is approx 262ms
    #wiringpi2.serialPutchar(fd, 0x80) # 0x60 is approx 1 Seconds
    #wiringpi2.serialPutchar(fd, 0xA0) # 0x60 is approx 4 Seconds

    time.sleep(0.1)
    ans = ReadInt(fd)
    # print ("Tag Status: %s" % hex(ans))    # Added for Debug Purposes 
    if ans == int("0xC0", 16):
        # C0 is a positive result
        print ("Polling delay changed ......")
    else:
        print ("Unexpected response %s" % hex(ans))
        # flush any remaining characters from the buffer
        wiringpi2.serialFlush(fd)
    return
def ChangeReaderOpMode(fd):
    # prvide an additional menu to choose the type of tag to be read and set the reader accordingly
    print ("Setting Reader Operating Tag Mode.......")

    desc = ""
    choice = ""
    while choice == "":
        print ("*********************************************")
        print ("a - Hitag H2")
        print ("b - Hitag H1/S (factory default)")
        print ("c - EM/MC2000")
        # promt the user for a choice
        choice = input("Please select tag type .....:")
        # print ("choice: %s" % choice)  # Added for Debug purposes
        
        if choice =="a" or choice == "A":
            desc = "Hitag H2"
            WaitForCTS()
            wiringpi2.serialPutchar(fd, 0x76)
            wiringpi2.serialPutchar(fd, 0x01) # 0x01 = H2
        elif choice =="b" or choice == "B":
            desc = "Hitag H1/S"
            WaitForCTS()
            wiringpi2.serialPutchar(fd, 0x76)
            wiringpi2.serialPutchar(fd, 0x02) # 0x01 = H1/S
        elif choice =="c" or choice == "C":
            desc = "Em / MC2000"
            WaitForCTS()
            wiringpi2.serialPutchar(fd, 0x76)
            wiringpi2.serialPutchar(fd, 0x03) # 0x03 = EM/MC2000
        else:
            print ("Invalid option.  Please try again...")
            choice = ""

    time.sleep(0.1)
    ans = ReadInt(fd)
    # print ("Tag Status: %s" % hex(ans)) #Added for Debug purposes
    if ans == int("0xC0", 16):
        # Positive result
        print ("Reader Operating Mode %s ......" % desc)
    else:
        print ("Unexpected response %s" % hex(ans))
        # clear the buffer
        wiringpi2.serialFlush(fd)
def RFIDSetup():
    # setup up the serial port and the wiringpi software for use
    # call setup for the wiringpi2 software
    response = wiringpi2.wiringPiSetup()
    # set the GPIO pin for input
    wiringpi2.pinMode(GPIO_PIN, 0)
    # open the serial port and set the speed accordingly
    fd = wiringpi2.serialOpen('/dev/serial0', 9600)

    # clear the serial buffer of any left over data
    wiringpi2.serialFlush(fd)
    
    if response == 0 and fd >0:
        # if wiringpi is setup and the opened channel is greater than zero (zero = fail)
        print ("PI setup complete on channel %d" %fd)
    else:
        print ("Unable to Setup communications")
        sys.exit()
        
    return fd
Example #4
0
def SetupUART():
    """
    Setup the UART for communications and return an object referencing it. Does:-
    -Initiates wiringpi software
    -Opens the serial port
    -Checks all is ok and returns the object
    """

    response = wiringpi.wiringPiSetup()
    # open the serial port and set the speed accordingly
    sp = wiringpi.serialOpen('/dev/ttyAMA0', 9600)

    # clear the serial buffer of any left over data
    wiringpi.serialFlush(sp)

    if response == 0 and sp > 0:
        # if wiringpi is setup and the opened channel is greater than zero (zero = fail)
        logging.info("PI setup complete on channel %d" % sp)
    else:
        logging.critical("Unable to Setup communications")
        sys.exit()

    return sp