/// <summary> /// 一个大循环 用来操作指纹仪. /// 这个函数要放到一个线程里来执行 /// </summary> /// <param name="studentList"></param> /// <param name="updateUserInterfaceDelegate">用来操作UI的委托</param> public static void Enroll(List <Student> studentList, UpdateUserInterfaceDelegate updateUserInterfaceDelegate) { FingerPrintHandle = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); // 打开指纹仪驱动 //while (FingerPrintHandle == IntPtr.Zero) { // var confirmResault = ShowConfirmBox ( "指纹仪初始化失败 \n是否重新初始化指纹仪?" ); // if (confirmResault == DialogResult.OK) { // FingerPrintHandle = HdFingerprintHelper.FpOpenUsb ( 0xFFFFFFFF, 1000 ); // } else { // ShowMsgBox ( "当前指纹仪无法工作,请使用手动考勤." ); // return; // } //} //如果打不开 就只能手动签到了 //上面的这些已经注释了. 因为在switch那边有对错误的处理. var acceptPlayer = new SoundPlayer(Resources.Accept); var rejectPlayer = new SoundPlayer(Resources.Reject); var fingerprintImagePath = GlobalParams.RootDir + "/fingerprint.bmp"; while (IsRollCalling) { UInt16 fingerprintid = 1000; UInt16 similarity = 0; var fingerPrintStat = HdFingerprintHelper.StartVerify(FingerPrintHandle, fingerprintImagePath, ref fingerprintid, ref similarity, 3000); if (!IsRollCalling) { return; // 如果结束点名了 这个函数直接返回即可 } switch (fingerPrintStat) { case 0: { acceptPlayer.Play(); var index = studentList.FindIndex(s => s.FingerprintId == fingerprintid); if (index == -1) { continue; } var student = studentList[index]; student.SignIn(DateTime.Now); //var fingerprintImage = new File(GlobalParams.RootDir+@"/fingerprint.bmp") var fileInfo = new FileInfo(fingerprintImagePath); Image fingerprintImage; if (fileInfo.Length != 0) { var stream = File.Open(fingerprintImagePath, FileMode.Open); fingerprintImage = Image.FromStream(stream); stream.Close(); } else { fingerprintImage = null; } var normalStudentNum = CountNormalStudent(studentList); var absentStudentNum = CountAbsentStudent(studentList); var lateStudentNum = CountLateStudent(studentList); var askForLeaveStudentNum = CountAskForLeaveStudent(studentList); var leaveEarlyStudentNum = CountLeaveEarlyStudent(studentList); var expectedStudentNum = studentList.Count; var course = new CourseInfo(expectedStudentNum: expectedStudentNum, didNotSubmitStudentNum: absentStudentNum, actualStudentNum: normalStudentNum, askForLeaveStudentNum: askForLeaveStudentNum); updateUserInterfaceDelegate(fingerprintImage, course, student); CopyOfStudentList = studentList; break; } case 9: { //这里会出现文件占用的问题. 文件->流->图片 var fileInfo = new FileInfo(fingerprintImagePath); Image fingerprintImage; if (fileInfo.Length != 0) { var stream = File.Open(fingerprintImagePath, FileMode.Open); fingerprintImage = Image.FromStream(stream); stream.Close(); } else { fingerprintImage = null; } updateUserInterfaceDelegate(fingerprintImage, null); rejectPlayer.Play(); break; } default: { var confirmResault = ConfirmBox.ShowConfirmBoxDialog(string.Format("指纹仪故障 故障代码:{0}\n 是否重新打开指纹仪", fingerPrintStat)); if (confirmResault == DialogResult.Cancel) { IsRollCalling = false; return; // 如果点了否 就结束指纹仪点名. 点是 重新初始化. 手动签到那里要判断一下(不用判断了 在switch的入口那边加了一个对IsrollCalling的一个判断.) } else { FingerPrintHandle = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); // 重新初始化指纹仪 } break; } } } }
/// <summary> /// 初始化指纹仪 向指纹仪中下载指纹数据 /// </summary> /// <param name="studentList"></param> /// <param name="updateProgress"></param> /// <param name="showConfirmBox"></param> /// <param name="closeProgressBar"></param> public static void InitFingerprint(ref List <Student> studentList, UpdateProgressBarDelegate updateProgress, ShowConfirmBoxDelegate showConfirmBox, CloseProgressBarDelegate closeProgressBar) { Thread.Sleep(1000); // 等待进度条窗口创建完毕 var fingerprintPtr = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); // 打开指纹仪驱动 while (fingerprintPtr == IntPtr.Zero) { var confirmResault = showConfirmBox("指纹仪初始化失败 \n是否重新初始化指纹仪?"); if (confirmResault == DialogResult.OK) { fingerprintPtr = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); } else { closeProgressBar(); return; } } HdFingerprintHelper.FpEmpty(fingerprintPtr, 5000); //清空指纹仪 ushort fingerprintId = 0; // 指纹Id var total = studentList.Count; // 获取学生总数 foreach (var student in studentList) { if (string.IsNullOrEmpty(student.FingerprintString)) { continue; } fingerprintId++; var operationResault = HdFingerprintHelper.Download1Fingerprint(fingerprintPtr, student.FingerprintString, fingerprintId, 1000); // 初始化一个指纹. updateProgress(1, string.Format("正在初始化 第{0}个指纹,\n共{1}个\n该学生的姓名为:{2}", fingerprintId, total, student.StudentName)); if (operationResault != 0) { var confirmResault = showConfirmBox(string.Format("有一条指纹初始化失败 错误代码:{0}\n该指纹对应的学生学号为:{1}\n学生姓名为:{2}\n是否继续初始化指纹仪?" , operationResault, student.StudentId, student.StudentName)); if (confirmResault == DialogResult.Cancel) { closeProgressBar(); return; } //和上面初始化指纹仪的过程是一样的 fingerprintPtr = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); // 打开指纹仪驱动 while (fingerprintPtr == IntPtr.Zero) { confirmResault = showConfirmBox("指纹仪初始化失败 \n是否重新初始化指纹仪?"); if (confirmResault == DialogResult.OK) { fingerprintPtr = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); } else { closeProgressBar(); return; } } //结束. 这块操作可以封装成一个函数 } student.FingerprintId = fingerprintId; // 将指纹编号放到StudentList中. } closeProgressBar(); HdFingerprintHelper.FpCloseUsb(fingerprintPtr); // 初始化完毕之后关闭指纹仪 等需要签到的时候再打开指纹仪.. }