예제 #1
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);
            }
        }