/// <summary> /// Send a command to the module /// </summary> /// <param name="cmd"></param> /// <param name="data"></param> private void SendCommand(FingerprintCommand cmd, byte[] data) { Console.WriteLine($"Command {cmd.ToString()}"); FingerPrintProtocol fp = new FingerPrintProtocol(cmd, data); _newPacket = false; _wiating = true; _inBuff.Clear(); _sps.Write(fp.GetStructuredPacket()); }
/// <summary> /// Data Received event handler /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> private void Sps_DataReceived(object arg1, byte[] arg2) { string str = BitConverter.ToString(arg2); if (_wiating) { //Console.WriteLine($"Received: {str}"); _inBuff.AddRange(arg2); if (FingerPrintProtocol.ValidatePacket(_inBuff.ToArray())) { _newPacket = true; } } }
/// <summary> /// Get a reply from the module /// </summary> /// <returns></returns> private FingerPrintProtocol GetReply() { var to = DateTime.Now.AddMilliseconds(1000); while (to > DateTime.Now) { if (_newPacket) { _wiating = false; var fpReply = FingerPrintProtocol.Parse(_inBuff.ToArray()); if (fpReply != null) { Console.WriteLine($"Reply {fpReply.ConfCode.ToString()}"); } return(fpReply); } Thread.Sleep(1); } Console.WriteLine("Reply Timeout"); _wiating = false; return(null); }