public WebSocketResult TransCmd(SuperWebSocket.WebSocketSession session, string cmd, string pars)
        {
            WebSocketResult result = new WebSocketResult();
            result.ResultCode = PsDeviceConstant.RESULT_OK;

            switch (cmd)
            {
                case PsDeviceConstant.CMD_OPEN:
                    Open(result);
                    break;
                case PsDeviceConstant.CMD_STATE:
                    result.ResultData = _scanner.ScannerCount.ToString();
                    break;
                case PsDeviceConstant.CMD_CLOSE:
                    _scanner.Close();
                    result.ResultData = _scanner.ScannerCount.ToString();
                    break;
                default:
                    result.ResultCode = PsDeviceConstant.RESULT_FAILED;
                    result.ErrorMsg = PsDeviceConstant.UNKNOWNCMD;
                    break;
            }
            result.Command = cmd;
            result.DeviceID = ID;
            return result;
        }
 /// <summary>
 /// 打开指纹仪
 /// </summary>
 /// <param name="result">返回结果</param> 
 private void Openfingerprint(WebSocketResult result)
 {
     if (zpf == null)
     {
         zpf = new ZKFPEngXClass();
         zpf.OnCapture += zpf_OnCapture;
     }
     switch (zpf.InitEngine())
     {
         case 0:
             result.ResultData = PsDeviceConstant.START_OK;
             break;
         case 1:
             result.ResultCode = PsDeviceConstant.RESULT_FAILED;
             result.ErrorMsg = PsDeviceConstant.START_FAILED;
             break;
         case 2:
             result.ResultCode = PsDeviceConstant.RESULT_FAILED;
             result.ErrorMsg = PsDeviceConstant.NOTCONNECTED;
             break;
         case 3:
             result.ResultCode = PsDeviceConstant.RESULT_FAILED;
             result.ErrorMsg = PsDeviceConstant.NOTFIND;
             break;
     }
 }
        /// <summary>
        /// 打开扫描仪
        /// </summary>
        /// <param name="result">返回结果</param> 
        private void Open(WebSocketResult result)
        {
            string rst = string.Empty;
            if (_scanner != null)
            {
                if (_scanner.ScannerCount > 0)
                {
                    result.ResultData= _scanner.ScannerCount.ToString();
                }
                else
                {
                    _scanner.Open();
                    if (_scanner.ScannerCount != 0)
                    {
                        result.ResultData = _scanner.ScannerCount.ToString();

                    }
                    else
                    {
                        result.ResultCode = PsDeviceConstant.RESULT_FAILED;
                        result.ErrorMsg = PsDeviceConstant.SCANNER_NOTCONNECTED;
                    }
                }
            }
            else
            {
                _scanner = new MotoScanner();
                _scanner.OnBarcode += _scanner_OnBarcode;
                _scanner.Open();
                if (_scanner.ScannerCount != 0)
                {
                    result.ResultData = _scanner.ScannerCount.ToString();
                }
                else
                {
                    result.ResultCode = PsDeviceConstant.RESULT_FAILED;
                    result.ErrorMsg = PsDeviceConstant.SCANNER_NOTCONNECTED;
                }
            }
        }
        /// <summary>
        /// 成功取到指纹事件
        /// </summary>
        /// <param name="ActionResult"></param>
        /// <param name="ATemplate"></param>
        void zpf_OnCapture(bool ActionResult, object ATemplate)
        {
            foreach (WebSocketSession session in webSocketServer.GetAllSessions())
            {
                WebSocketResult result = new WebSocketResult();
                result.DeviceID = ID;
                try
                {
                    if (ActionResult)
                    {
                        ZKFPEngXClass ztlp = new ZKFPEngXClass();
                        string sss = ztlp.EncodeTemplate1(ATemplate);
                        result.ResultCode = PsDeviceConstant.RESULT_OK;
                        result.ResultData = sss;
                        result.ErrorMsg = "";
                        result.Command = "";

                    }
                    else
                    {
                        result.ResultCode = PsDeviceConstant.RESULT_FAILED;
                        result.ResultData = "";
                        result.ErrorMsg = PsDeviceConstant.READFP_FAILED;
                        result.Command = "";

                    }
                }
                catch (Exception e)
                {
                    result.ResultCode = PsDeviceConstant.RESULT_FAILED;
                    result.ResultData = "";
                    result.ErrorMsg = e.Message;
                    result.Command = "";

                }
                finally
                {
                    session.Send(result.JsonText);
                }
            }
        }
 /// <summary>
 /// 收到消息触发事件
 /// </summary>
 /// <param name="session"></param>
 /// <param name="value"></param>
 void m_WebSocketServer_NewMessageReceived(WebSocketSession session, string value)
 {
     try
     {
         _logger.Debug(string.Format("收到消息,消息内容={0}", value));
         string pars = value;
         string cmd = GetCommand(ref pars);
         foreach (IDeviceService item in devicelist)
         {
             if (cmd.StartsWith(item.ID + "_", StringComparison.OrdinalIgnoreCase))
             {
                 cmd = cmd.Substring(item.ID.Length + 1, cmd.Length - item.ID.Length - 1);
                 WebSocketResult result = item.TransCmd(session, cmd, pars);
                 session.Send(result.JsonText);
                 _logger.Debug(string.Format("对消息处理完成,消息内容={0}", value));
                 break;
             }
         }
     }
     catch (Exception e)
     {
         WebSocketResult result = new WebSocketResult();
         result.ResultCode = -1;
         result.DeviceID = "";
         result.ResultData = "";
         result.Command = value;
         result.ErrorMsg = e.Message;
         session.Send(result.JsonText);
         _logger.Error(string.Format("消息处理时产生异常,异常信息={0}", e.Message));
     }
 }
 /// <summary>
 /// 扫描到内容触发
 /// </summary>
 /// <param name="barcode"></param>
 void _scanner_OnBarcode(string barcode)
 {
     foreach (WebSocketSession session in webSocketServer.GetAllSessions())
     {
         WebSocketResult result = new WebSocketResult();
         result.DeviceID = ID;
         try
         {
             result.ResultCode = PsDeviceConstant.RESULT_OK;
             result.ResultData = barcode;
             result.ErrorMsg = "";
             result.Command = "";
         }
         catch (Exception e)
         {
             result.ResultCode = PsDeviceConstant.RESULT_FAILED;
             result.ResultData = "";
             result.ErrorMsg = e.Message;
             result.Command = "";
         }
         finally
         {
             session.Send(result.JsonText);
         }
     }
 }
 public WebSocketResult TransCmd(SuperWebSocket.WebSocketSession session, string cmd, string pars)
 {
     WebSocketResult result = new WebSocketResult();
     result.ResultCode = PsDeviceConstant.RESULT_OK;
     switch (cmd)
     {
         case PsDeviceConstant.CMD_OPEN:
             Openfingerprint(result);
             break;
         case PsDeviceConstant.CMD_BEGINCAPTURE:
             zpf.BeginCapture();
             result.ResultData = PsDeviceConstant.BEGINCAPTURE;
             break;
         case PsDeviceConstant.CMD_CANCLECAPTURE:
             zpf.CancelCapture();
             result.ResultData = PsDeviceConstant.CANCLECAPTURE;
             break;
         case PsDeviceConstant.CMD_CLOSE:
             zpf.EndEngine();
             result.ResultData = PsDeviceConstant.CLOSE_OK;
             break;
         default :
             result.ResultCode = PsDeviceConstant.RESULT_FAILED;
             result.ErrorMsg = PsDeviceConstant.UNKNOWNCMD;
             break;
     }
     result.Command = cmd;
     result.DeviceID = ID;
     return result;
 }