Raspberry Pi 4指纹传感器初始化失败求助:数据包无有效头部
指纹传感器初始化失败问题排查求助
我为学业评估购买了一款Basic Fingerprint Sensor With Socket Header Cable。最初自己写的代码能让传感器正常工作,但不符合评估要求。和老师沟通后拿到了经测试可用的代码,一开始运行正常,但修改代码适配评估规格后,传感器彻底无法工作,始终输出以下错误:
The fingerprint sensor could not be initialized!
Exception message: The received packet do not begin with a valid header!
之后我尝试了更换代码、更换依赖包、更换树莓派设备、更换传感器,甚至重装RaspOS系统,问题都没有解决,求可行的排查思路。
以下是最初可用、现在却报错的代码:
#!/usr/bin/env python # -*- coding: utf-8 -*- #PyFingerprint ##Copyright (C) 2015 Bastian Raschke #All rights reserved. import tempfile from pyfingerprint.pyfingerprint import PyFingerprint ## Reads image and download it ## ## Tries to initialize the sensor try: f = PyFingerprint('/dev/ttyS0', 57600, 0xFFFFFFFF, 0x00000000) if ( f.verifyPassword() == False ): raise ValueError('The given fingerprint sensor password is wrong!') except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) exit(1) ## Gets some sensor information print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) ## Tries to read image and download it try: print('Waiting for finger...') ## Wait that finger is read while ( f.readImage() == False ): pass print('Downloading image (this take a while)...') imageDestination = tempfile.gettempdir() + '/fingerprint.bmp' f.downloadImage(imageDestination) print('The image was saved to "' + imageDestination + '".') except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
内容的提问来源于stack exchange,提问作者Epilox
相关产品推荐
相关产品推荐

