예제 #1
0
        /// <summary>
        /// Receive Message
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="msg"></param>
        void r_OnMessageNotificationReceived(BaseReader reader, IMessageNotification msg)
        {
            IsRunning = true;
            bool   ismatch     = false;//是否有数据
            string strtid      = "";
            string strepc      = "";
            string struserdata = "";
            string rssi        = "";
            string errInfo     = "";

            String msgType = msg.GetMessageType();

            msgType = msgType.Substring(msgType.LastIndexOf('.') + 1);

            switch (msgType)
            {
                #region RXD_TagData
            case "RXD_TagData":
            {
                RXD_TagData m = (RXD_TagData)msg;

                strepc = Util.ConvertByteArrayToHexWordString(m.ReceivedMessage.EPC);

                strtid = Util.ConvertByteArrayToHexWordString(m.ReceivedMessage.TID);

                struserdata = Util.ConvertByteArrayToHexWordString(m.ReceivedMessage.UserData);


                if (m.ReceivedMessage.RSSI != null)
                {
                    if (reader.ModelNumber.IndexOf("502E") != -1 || reader.ModelNumber == "XC-RF811")        //502E
                    {
                        rssi = m.ReceivedMessage.RSSI[0].ToString("X2") + m.ReceivedMessage.RSSI[1].ToString("X2");
                    }
                    else
                    {
                        rssi = m.ReceivedMessage.RSSI[0].ToString("X2");
                    }
                }
                ismatch = true;
                AddToListAsync(new TagView1(strtid, strepc, struserdata, rssi));
            }
            break;

                #endregion
            default:
                if (msg.StatusCode == 0x00)
                {
                    ismatch = true;
                }
                break;
            }
            if (!ismatch)//无标签数据
            {
                errInfo = "Read Failure";
                if (msg.ErrInfo != null && msg.ErrInfo != "")
                {
                    errInfo = string.Format("Read Failure,{0}", msg.StatusCode.ToString("X2"));
                }

                AddToStatusAsync(errInfo);
            }
        }
예제 #2
0
        void r_OnMessageNotificationReceived(BaseReader reader, IMessageNotification msg)
        {
            String nowString         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            String utcString         = nowString;
            String reserve           = string.Empty;
            NotificationMessage nmsg = null;

            switch (reader.ProtocolVersion)
            {
            case "IRP1":
            {
                if (msg.StatusCode != 0)
                {
                    if (OnReaderErrorMsg != null)
                    {
                        OnReaderErrorMsg((IRP1.Reader)reader, msg.ErrInfo);
                    }
                    Log.Debug(reader.ReaderName + ":" + msg.ErrInfo);
                    return;
                }
                String msgType = msg.GetMessageType();
                msgType = msgType.Substring(msgType.LastIndexOf('.') + 1);
                switch (msgType)
                {
                    #region RXD_TagData
                case "RXD_TagData":
                {
                    IRP1.RXD_TagData m     = (IRP1.RXD_TagData)msg;
                    Byte[]           bRssi = m.ReceivedMessage.RSSI;
                    string           rssi  = "";
                    if (bRssi != null)
                    {
                        if (reader.ModelNumber.IndexOf("502E") != -1 || reader.ModelNumber.IndexOf("811") != -1)
                        {
                            rssi = bRssi[0].ToString("X2") + bRssi[1].ToString("X2");
                        }
                        else
                        {
                            rssi = bRssi[0].ToString("X2");
                        }
                    }
                    string rxdTime = Common.ReadTimeToString(m.ReceivedMessage.RXDTime);
                    if (rxdTime != "")
                    {
                        nowString = rxdTime;
                    }
                    nmsg = new NotificationMessage(
                        m.ReceivedMessage.ReaderName,
                        m.ReceivedMessage.TagType,
                        Util.ConvertByteArrayToHexWordString(m.ReceivedMessage.EPC),
                        Util.ConvertByteArrayToHexWordString(m.ReceivedMessage.TID),
                        Util.ConvertByteArrayToHexWordString(m.ReceivedMessage.UserData),
                        Util.ConvertByteArrayToHexWordString(m.ReceivedMessage.Reserved),
                        rssi,
                        m.ReceivedMessage.Antenna,
                        nowString
                        );
                }
                break;

                    #endregion
                    #region EasAlarm_6C
                case "EasAlarm_6C":
                {
                    IRP1.EasAlarm_6C m = (IRP1.EasAlarm_6C)msg;
                    if (m.ReceivedMessage.AnswerType == 0xa0)
                    {
                        if (OnTagAlarm != null)
                        {
                            OnTagAlarm(null, EventArgs.Empty);
                        }
                    }
                }
                break;

                    #endregion
                    #region PcSendTime_500(805)
                case "PcSendTime_500":
                {
                    IRP1.PcSendTime_500 m   = (IRP1.PcSendTime_500)msg;
                    DateTime            now = DateTime.Now;
                    TimeSpan            ts  = now - new DateTime(1970, 1, 1);
                    int    d     = (int)ts.TotalSeconds;
                    Byte[] bytes = BitConverter.GetBytes(d);
                    Byte[] time  = new Byte[4];


                    time[0] = bytes[3];
                    time[1] = bytes[2];
                    time[2] = bytes[1];
                    time[3] = bytes[0];

                    IRP1.PcSendTime_500 order = new IRP1.PcSendTime_500(m.ReceivedMessage.ReaderID, time);
                    reader.Send(order);
                }
                break;

                    #endregion
                    #region RXD_IOTriggerSignal_800
                case "RXD_IOTriggerSignal_800":
                {
                    IRP1.RXD_IOTriggerSignal_800 m = (IRP1.RXD_IOTriggerSignal_800)msg;
                    if (m.ReceivedMessage.IsStart)
                    {
                        //TODO:
                    }
                    else
                    {
                        //TODO:
                    }
                }
                break;

                    #endregion
                    #region Keepalive
                case "Keepalive":
                {
                    reader.Send(new IRP1.Keepalive());
                }
                break;
                    #endregion
                }
            }
            break;

            case "IRP2":
                // TODO:
                break;
            }
            if (OnReaderNotificationMsg != null)
            {
                OnReaderNotificationMsg((IRP1.Reader)reader, nmsg);
            }
        }