Ejemplo n.º 1
0
        public Message Transact(Message msg, out MSG_ERROR_MESSAGE msg_err, int time_out)
        {
            msg_err = (MSG_ERROR_MESSAGE)null;
            Message msg1 = (Message)null;

            this.commIF.OnFrameReceived += new delegateMessageReceived(this.ProcessFrame);
            this.Send(msg);
            switch (WaitHandle.WaitAny(new WaitHandle[2]
            {
                (WaitHandle)this.rsp_event,
                (WaitHandle)this.err_event
            }, time_out))
            {
            case 0:
                LLRPBinaryDecoder.Decode(ref this.rsp_data, out msg1);
                break;

            case 1:
                int      cursor   = 0;
                BitArray bitArray = Util.ConvertByteArrayToBitArray(this.rsp_data);
                int      count    = bitArray.Count;
                msg_err = MSG_ERROR_MESSAGE.FromBitArray(ref bitArray, ref cursor, count);
                break;
            }
            this.commIF.OnFrameReceived -= new delegateMessageReceived(this.ProcessFrame);
            return(msg1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a message transaction with the reader.  Sends the msg and waitws
        /// for a response, an error message or a timeout
        /// </summary>
        /// <param name="msg">Message to send</param>
        /// <param name="msg_err">Output contains error message if sent by reader</param>
        /// <param name="time_out">Timeout value to abort waiting for response</param>
        /// <returns>Response Message or NULL if error or timeout </returns>
        public Message Transact(Message msg, out MSG_ERROR_MESSAGE msg_err, int time_out)
        {
            msg_err = null;
            Message rsp_msg = null;

            // subscribe to the comminucations interface delegate to look for the response
            commIF.OnFrameReceived += new delegateMessageReceived(this.ProcessFrame);

            Send(msg);

            // wait for either response or error
            WaitHandle[] wait        = new WaitHandle[] { rsp_event, err_event };
            int          wait_result = WaitHandle.WaitAny(wait, time_out);

            switch (wait_result)
            {
            case 0:
                /* got a response. already checked the mssage type */
                LLRPBinaryDecoder.Decode(ref rsp_data, out rsp_msg);
                break;

            case 1:
            {
                int      cursor = 0;
                int      length;
                BitArray bArr;

                /* got an error */
                bArr    = Util.ConvertByteArrayToBitArray(rsp_data);
                length  = bArr.Count;
                msg_err = MSG_ERROR_MESSAGE.FromBitArray(ref bArr, ref cursor, length);
            }
            break;
            }

            // remove the event handler when  our transaction is over
            commIF.OnFrameReceived -= new delegateMessageReceived(this.ProcessFrame);

            return(rsp_msg);
        }
Ejemplo n.º 3
0
        public static void Decode(ref byte[] packet, out Message msg)
        {
            LLRPBinaryDecoder.LLRP_Envelope env;
            LLRPBinaryDecoder.Decode_Envelope(packet, out env);
            BitArray bitArray = Util.ConvertByteArrayToBitArray(packet);
            int      cursor   = 0;

            switch (env.msg_type)
            {
            case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES:
                msg = (Message)MSG_GET_READER_CAPABILITIES.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG:
                msg = (Message)MSG_GET_READER_CONFIG.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG:
                msg = (Message)MSG_SET_READER_CONFIG.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION_RESPONSE:
                msg = (Message)MSG_CLOSE_CONNECTION_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES_RESPONSE:
                msg = (Message)MSG_GET_READER_CAPABILITIES_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG_RESPONSE:
                msg = (Message)MSG_GET_READER_CONFIG_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG_RESPONSE:
                msg = (Message)MSG_SET_READER_CONFIG_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION:
                msg = (Message)MSG_CLOSE_CONNECTION.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC:
                msg = (Message)MSG_ADD_ROSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC:
                msg = (Message)MSG_DELETE_ROSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.START_ROSPEC:
                msg = (Message)MSG_START_ROSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC:
                msg = (Message)MSG_STOP_ROSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC:
                msg = (Message)MSG_ENABLE_ROSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC:
                msg = (Message)MSG_DISABLE_ROSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_ROSPECS:
                msg = (Message)MSG_GET_ROSPECS.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC_RESPONSE:
                msg = (Message)MSG_ADD_ROSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC_RESPONSE:
                msg = (Message)MSG_DELETE_ROSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.START_ROSPEC_RESPONSE:
                msg = (Message)MSG_START_ROSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC_RESPONSE:
                msg = (Message)MSG_STOP_ROSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC_RESPONSE:
                msg = (Message)MSG_ENABLE_ROSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC_RESPONSE:
                msg = (Message)MSG_DISABLE_ROSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_ROSPECS_RESPONSE:
                msg = (Message)MSG_GET_ROSPECS_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC:
                msg = (Message)MSG_ADD_ACCESSSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC:
                msg = (Message)MSG_DELETE_ACCESSSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC:
                msg = (Message)MSG_ENABLE_ACCESSSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC:
                msg = (Message)MSG_DISABLE_ACCESSSPEC.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS:
                msg = (Message)MSG_GET_ACCESSSPECS.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC_RESPONSE:
                msg = (Message)MSG_ADD_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC_RESPONSE:
                msg = (Message)MSG_DELETE_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC_RESPONSE:
                msg = (Message)MSG_ENABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC_RESPONSE:
                msg = (Message)MSG_DISABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS_RESPONSE:
                msg = (Message)MSG_GET_ACCESSSPECS_RESPONSE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.GET_REPORT:
                msg = (Message)MSG_GET_REPORT.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.RO_ACCESS_REPORT:
                msg = (Message)MSG_RO_ACCESS_REPORT.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.KEEPALIVE:
                msg = (Message)MSG_KEEPALIVE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.READER_EVENT_NOTIFICATION:
                msg = (Message)MSG_READER_EVENT_NOTIFICATION.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ENABLE_EVENTS_AND_REPORTS:
                msg = (Message)MSG_ENABLE_EVENTS_AND_REPORTS.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.KEEPALIVE_ACK:
                msg = (Message)MSG_KEEPALIVE_ACK.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.ERROR_MESSAGE:
                msg = (Message)MSG_ERROR_MESSAGE.FromBitArray(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            case ENUM_LLRP_MSG_TYPE.CUSTOM_MESSAGE:
                msg = (Message)CustomMsgDecodeFactory.DecodeCustomMessage(ref bitArray, ref cursor, (int)env.msg_len * 8);
                break;

            default:
                throw new MalformedPacket("Unrecognized message " + (object)env.msg_type);
            }
        }