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); }
/// <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); }