private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var resSling = ((sender as FrameworkElement).Tag as ListData).Data as ResSling; this.curSling = resSling; this.tbInfo.Text = ""; this.gridNo = resSling.CabinetGrid; // 发送开锁信号,通知柜门开锁 if (spCabinet.IsOpen) // 已打开,直接发送消息 { var msg = string.Format("8A 01 {0} 11", Convert.ToInt32(resSling.CabinetGrid).ToString("X2")); var flag = spCabinet.Write(string.Format("{0} {1}", msg, BCC.CheckXOR(msg))); if (!flag) { Log.WriteLog(string.Format("ERROR-BOM:开锁消息发送失败,{0}", msg)); } } else // 未打开,先打开端口 { SpConfig spConfig = new SpConfig(); spConfig.PortName = ConfigurationManager.AppSettings["CabinetPort"]; spConfig.BaudRate = 9600; // 波特率 spConfig.Parity = System.IO.Ports.Parity.None; // 偶校验位 spConfig.DataBits = 8; spConfig.StopBits = System.IO.Ports.StopBits.One; // 停止位 try { // 打开 string err = ""; if ((err = spCabinet.Open(spConfig)) != "") { this.ShowMessageInfo(err, this.redBrush); } // 发开锁消息 var msg = string.Format("8A 01 {0} 11", Convert.ToInt32(resSling.CabinetGrid).ToString("X2")); var flag = spCabinet.Write(string.Format("{0} {1}", msg, BCC.CheckXOR(msg))); if (!flag) { Log.WriteLog(string.Format("ERROR-BOM:开锁消息发送失败,{0}", msg)); } } catch (Exception ex) { this.ShowMessageInfo("开锁失败,请重试!", this.redBrush); Log.WriteLog(string.Format("ERROR-BOM:开锁失败,失败信息:{0}", ex.Message)); } } }
public ReturnView() { InitializeComponent(); txtStaffID.AddHandler(TextBox.MouseLeftButtonDownEvent, new MouseButtonEventHandler(txtStaffID_MouseLeftButtonDown), true); timer.Tick += Timer_Tick; timer.Interval = TimeSpan.FromSeconds(1); faceIdUtil = new FaceIDUtil(); faceIdUtil.FaceSearchCompleted += FaceIdUtil_FaceSearchCompleted; string err = ""; if ((err = faceIdUtil.Init()) != "") { this.tbFaceError.Text = err; } this.listBox.ItemsSource = dataList; spCard.DataReceived += spCard_DataReceived; spCard.Error += spCard_Error; // 打开读卡器监听 SpConfig spConfig = new SpConfig(); spConfig.PortName = ConfigurationManager.AppSettings["CardPort"]; spConfig.BaudRate = 19200; // 波特率 spConfig.Parity = System.IO.Ports.Parity.Even; // 偶校验位 spConfig.DataBits = 8; spConfig.StopBits = System.IO.Ports.StopBits.One; // 停止位 spCard.Open(spConfig); // 设置读卡器为主动模式 string msg = "02 06 00 00 00 03 C9 F8"; var flag = spCard.Write(msg); if (!flag) { Log.WriteLog(string.Format("ERROR-RET:主动模式设置失败,{0}", msg)); } spCabinet.DataReceived += SpCabinet_DataReceived; spCabinet.Error += SpCabinet_Error; //string[] cameras = MultimediaUtil.VideoInputNames;//获取摄像头 //if (cameras.Length > 0) //{ // this.videoPlayer.VideoCaptureSource = cameras[0]; //} new Thread(() => { Thread.Sleep(100); faceIdUtil.OpenRealData(); }).Start(); }
private void OpenCabinet(string cabinetGrid, string cabinetId) { // 发送开锁信号,通知柜门开锁 if (spCabinet.IsOpen) // 已打开,直接发送消息 { var msg = string.Format("8A 01 {0} 11", Convert.ToInt32(cabinetGrid).ToString("X2")); var flag = spCabinet.Write(string.Format("{0} {1}", msg, BCC.CheckXOR(msg))); if (!flag) { Log.WriteLog(string.Format("ERROR-STR:开锁消息发送失败,{0}", msg)); } } else // 未打开,先打开端口 { SpConfig spConfig = new SpConfig(); spConfig.PortName = ConfigurationManager.AppSettings["CabinetPort"]; spConfig.BaudRate = 9600; // 波特率 spConfig.Parity = System.IO.Ports.Parity.None; // 偶校验位 spConfig.DataBits = 8; spConfig.StopBits = System.IO.Ports.StopBits.One; // 停止位 try { // 打开 spCabinet.Open(spConfig); // 发开锁消息 var msg = string.Format("8A 01 {0} 11", Convert.ToInt32(cabinetGrid).ToString("X2")); var flag = spCabinet.Write(string.Format("{0} {1}", msg, BCC.CheckXOR(msg))); if (!flag) { Log.WriteLog(string.Format("ERROR-STR:开锁消息发送失败,{0}", msg)); } } catch (Exception ex) { this.ShowMessageInfo("开锁失败,请重试!", this.redBrush); Log.WriteLog(string.Format("ERROR-STR:开锁失败,失败信息:{0}", ex.Message)); } } }