Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEX Format #2

Open
desmphil opened this issue Aug 31, 2021 · 1 comment
Open

HEX Format #2

desmphil opened this issue Aug 31, 2021 · 1 comment
Labels
question Further information is requested

Comments

@desmphil
Copy link

desmphil commented Aug 31, 2021

I run multiple turnstile with USB and Serial RFID reader of many brands.
Serial RFID are easy to handle but the RFIDEA HID reader always forced me to work in the console session.

I was using this in P3 which is not really flexible

if readerUSB == True: #(PYTHON 3 NO ORD REQUIRED - See archives functions.)
  print("******** WAITING FOR CARD ACCESS with USB **************")
  try:
    while True:
      while not done:			## Get the character from the HID
        buffer = fp.read(8)
        for c in buffer:
          if c > 0:	##  40 is carriage return which signifies we are done looking for characters
            if int(c) == 40:
              done = True
              break;	##  If we are shifted then we have to  use the hid2 characters.
            if shift: 	## If it is a '2' then it is the shift key
              if int(c) == 2 :
                shift = True
              else:	# if not a 2, lookup mapping
                rfid_number += hid2[ int(c) ]
                shift = False
            else:		# if not shifted, use the hid characters
              if int(c) == 2 :	# if 2, then it is the shift key
                shift = True
              else:	# If not a 2, lookup mapping
                rfid_number += hid[ int(c) ]

With your code I was able to read USB data off console.
However, the HEX data returned is reversed to my requirements

Data Return: Tag data: 35 88 8a 67 50 01 04 e0
Data required: E0040150678A8835

I played with the pcprox.py to reverse the HEX data and i have to create a loop but getting there.

def _format_hex(i: bytes) -> Text:
    return ''.join(reversed(['%02x' % c for c in i]))

Have you had any requirements as such?

@micolous
Copy link
Owner

It sounds like the previous code you had there was reading from the PCProx as a keyboard input.

This library doesn't try to use the settings to change how get_tag() works; it just gives you the raw data that the reader sent. I think your reader may be configured with bRevBytes set differently to my reader (I don't have my reader handy to check); but in "SDK mode" there is some processing the reader doesn't do, so that setting and iIDBitCnt are ignored.

_format_hex is an internal function that's designed for display purposes: changing it won't change the outputs that this library gives you.

This library gives back raw bytes from the device; if you want to reverse it and display it with uppercase letters like that, you want something like:

import base64

# removed other setup code (see usbtest.py)
tag = dev.get_tag()
if tag is None:
  print('tag not found')
  return

tag_id, bit_length = tag
# Reverse the tag ID
tag_id = tag_id[::-1]
# Hex-encode the tag ID in upper case
tag_id = base64.b16encode(tag_id)
# (do something with this data)...

@micolous micolous added the question Further information is requested label Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants