예제 #1
0
def ReadTagPageZero(fd):
    # read the tag page 00 command
    notag = True

    print ("Reading Tag Data Page 00.......")

    print ("Waiting for a tag ....")

    notag = True
    while notag:
        WaitForCTS()
        # print ("Sending Tag Read Page Command")    #Added for Debug purposes
        wiringpi2.serialPutchar(fd, 0x52)
        wiringpi2.serialPutchar(fd, 0x00)
        time.sleep(0.1)
        ans = ReadInt(fd)
        # print ("Tag Status: %s" % hex(ans))    #Added for Debug purposes
        if ans == int("0xD6", 16):
            # Tag present and read
            notag = False
            # print ("Tag Present") #Added for Debug purposes
            ans = ReadText(fd)
            print ("Page 00")
            print ("-->%s<--" % ans)
    return
예제 #2
0
def ReadTagAndBlocks(fd):
    # read the tag and all blocks from within it
    # Only works for HS/1 as other tags don't support it
    notag = True

    print ("Reading Tag Data Blocks 00, 01, 02, 03 .......")

    print ("Waiting for a tag ....")

    notag = True
    while notag:
        WaitForCTS()
        # print ("Sending Tag Read Blocks command")  #Added for Debug purposes
        wiringpi2.serialPutchar(fd, 0x74)
        wiringpi2.serialPutchar(fd, 0x04)
        time.sleep(0.1)
        ans = ReadInt(fd)
        # print ("Tag Status: %s" % hex(ans))    #Added for Debug purposes
        if ans == int("0xD6", 16):
            # Tag present and read
            notag = False
            # print ("Tag Present")  #Added for Debug purposes
            ans = ReadText(fd)
            print ("Blocks 00, 01, 02, 03")
            print ("-->%s<--" % ans)
    return
예제 #3
0
def TransmitData(channel, payload):
    """
    Given the payload, transmit it over the UART line
    """
    logging.info('Data to be sent to the serial port %s' % payload)
    for items in payload:
        logging.debug('Data packet to be sent >%x< on channel:%x' %
                      (items, channel))
        wiringpi.serialPutchar(channel, items)

    return
예제 #4
0
def _serial(send=None):
    wiringpi.wiringPiSetup()
    serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
    if send != None:
        wiringpi.serialPuts(serial, send)
        wiringpi.serialPutchar(serial, 3)
        wiringpi.serialClose(serial)
    else:
        char = ""
        asciinum = -1
        while (True):
            asciinum = wiringpi.serialGetchar(serial)
            if asciinum != -1 and asciinum != 3:
                char += chr(asciinum)
            elif asciinum == 3:
                break
        wiringpi.serialClose(serial)
        return char
예제 #5
0
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 write(self, data):
        wiringpi.serialPutchar(self.serial, ord('['))  # Start of packet
        for c in data:
            print(c)
            wiringpi.serialPutchar(self.serial, ord(c))

        wiringpi.serialPutchar(self.serial, ord(']'))  # End of packet
예제 #7
0
def FactoryReset(fd):
    # send the factory reset command
    WaitForCTS()
    # print ("Performing a factory reset ....") #Added for Debug purposes
    wiringpi2.serialPutchar(fd, 0x46)
    wiringpi2.serialPutchar(fd, 0x55)
    wiringpi2.serialPutchar(fd, 0xAA)
    time.sleep(0.1)
    print ("FACTORY RESET COMPLETE ")
    print ("")
    return
예제 #8
0
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)
예제 #9
0
 def write(self, data):
     """ write bytes of data to serial port. """
     for char in data:
         wiringpi.serialPutchar(self.serial_fd, char)
예제 #10
0
 def putc(self, c):
     self.waitbusy()
     wpi.serialPutchar(self.serial, c)