Exemplo n.º 1
0
        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));
                }
            }
        }
Exemplo n.º 2
0
        private void SpCabinet_DataReceived(DataReceivedEventArgs e)
        {
            var temps = e.data.Split(' ');

            if (temps.Length == 5 && temps[0] == "8A")
            {
                if (temps[3] == "11")
                {
                    isOpening = true;
                    var msginfo = string.Format("{0}号柜门已打开!请放入设备,并关闭柜门。", Convert.ToInt32(temps[2], 16));
                    this.ShowMessageInfo(msginfo, this.greenBrush);
                    // 启动轮询定时器查询锁状态
                    if (timer.IsEnabled)
                    {
                        timer.Stop();
                    }
                    var msg = string.Format("80 01 {0} 33", temps[2]);
                    timer.Tag = string.Format("{0} {1}", msg, BCC.CheckXOR(msg));
                    timer.Start();
                }
                else
                {
                    var msg = string.Format("{0}号柜门打开失败,请重试!", Convert.ToInt32(temps[2], 16));
                    this.ShowMessageInfo(msg, this.redBrush);
                    Log.WriteLog("ERROR-RET:" + msg);
                }
            }
            else if (temps.Length > 5 && temps[0] == "80")
            {
                if (temps[4] == "01")
                {
                    // MessageBox.Show(string.Format("{0}号柜门已打开!", Convert.ToInt32(temps[1], 16)));
                }
                else if (temps[4] == "00")
                {
                    this.timer.Stop();
                    Log.WriteLog(string.Format("INFO-RET:{0}号柜门已关闭!操作人员:{1}", this.gridNo, this.staffName));

                    if (grid2RFID.ContainsKey(this.gridNo))
                    {
                        this.ReturnSling(grid2RFID[this.gridNo]);
                    }

                    var msg = string.Format("{0}号柜门已关闭!", this.gridNo);
                    isOpening = false;
                    this.ShowMessageInfo(msg, this.greenBrush);
                }
            }
        }
Exemplo n.º 3
0
        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));
                }
            }
        }