Skip to content

struct.error: unpack requires a buffer of 2 bytes #41

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

Closed
decentralMind opened this issue Jan 6, 2022 · 3 comments · Fixed by #47
Closed

struct.error: unpack requires a buffer of 2 bytes #41

decentralMind opened this issue Jan 6, 2022 · 3 comments · Fixed by #47

Comments

@decentralMind
Copy link

Hi, I am using r307 fingerprint sensor. I'm trying to compare fingerprint template by uploading it to the fingerprint sensor flash storage.

I'm trying to run this example code.

Here is the piece of code from the example which I failed to run. I've already saved the fingerprint template('template0.dat') file before executing this code.


# pylint: disable=too-many-branches
def fingerprint_check_file():
    """Compares a new fingerprint template to an existing template stored in a file
    This is useful when templates are stored centrally (i.e. in a database)"""
    print("Waiting for finger print...")
    set_led_local(color=3, mode=1)
    while finger.get_image() != adafruit_fingerprint.OK:
        pass
    print("Templating...")
    if finger.image_2_tz(1) != adafruit_fingerprint.OK:
        return False

    print("Loading file template...", end="", flush=True)
    with open("template0.dat", "rb") as file:
        data = file.read()
    finger.send_fpdata(list(data), "char", 2)

    i = finger.compare_templates()
    if i == adafruit_fingerprint.OK:
        set_led_local(color=2, speed=150, mode=6)
        print("Fingerprint match template in file.")
        return True
    if i == adafruit_fingerprint.NOMATCH:
        set_led_local(color=1, mode=2, speed=20, cycles=10)
        print("Templates do not match!")
    else:
        print("Other error!")
    return False

I got following error:

Waiting for finger print...
Templating...
Loading file template...Traceback (most recent call last):
File "/home/mockupsystem/Adafruit_CircuitPython_Fingerprint/examples/fingerprint_template_file_compare.py", line 203, in
fingerprint_check_file()
File "/home/mockupsystem/Adafruit_CircuitPython_Fingerprint/examples/fingerprint_template_file_compare.py", line 73, in fingerprint_check_file
i = finger.compare_templates()
File "/home/mockupsystem/python-env/some/lib/python3.10/site-packages/adafruit_fingerprint.py", line 323, in compare_templates
self.confidence = struct.unpack(">H", bytes(r[1:3]))
struct.error: unpack requires a buffer of 2 bytes

@tekktrik
Copy link
Member

tekktrik commented Feb 23, 2022

Adafruit_Fingerprint has the ability to print out debug text if you set it's _debug flag:

...

finger = adafruit_fingerprint.Adafruit_Fingerprint(uart)
finger._debug = True

...

What does the console read when that is done?

@ajiekurniawansaputra
Copy link
Contributor

Hi guys, I have solved the problem, it's in the _send_data function, the checksum should concatenate ENDDATAPACKET on the last send. I have request pull on the main branch, I hope they accept my request.

@tekktrik
Copy link
Member

tekktrik commented Mar 9, 2022

Nice! I'm working on getting my Pi set up to test this in the coming days, hopefully someone can get to it faster!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants