public Message TransactMessage(Message msg, int time_out)
        {
            bool[] bit_array = msg.ToBitArray();
            byte[] data = Util.ConvertBitArrayToByteArray(bit_array);
            try
            {
                transactEvt = new ManualResetEvent(false);
                Transaction.Send(cI, data);

                msg_id = (int)msg.MSG_ID;

                if (msg.MSG_TYPE != (uint)ENUM_LLRP_MSG_TYPE.CUSTOM_MESSAGE) msg_type = (short)(msg.MSG_TYPE + 10);
                else
                    msg_type = (short)msg.MSG_TYPE;

                if (transactEvt.WaitOne(time_out, false))
                {
                    BitArray bArr;
                    int length;
                    int cursor = 0;
                    switch ((ENUM_LLRP_MSG_TYPE)msg_type)
                    {

                        case ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_GET_READER_CAPABILITIES_RESPONSE r_msg = MSG_GET_READER_CAPABILITIES_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.ADD_ROSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_ADD_ROSPEC_RESPONSE r_msg = MSG_ADD_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_DELETE_ROSPEC_RESPONSE r_msg = MSG_DELETE_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.START_ROSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_START_ROSPEC_RESPONSE r_msg = MSG_START_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.STOP_ROSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_STOP_ROSPEC_RESPONSE r_msg = MSG_STOP_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_ENABLE_ROSPEC_RESPONSE r_msg = MSG_ENABLE_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_DISABLE_ROSPEC_RESPONSE r_msg = MSG_DISABLE_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.GET_ROSPECS_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_GET_ROSPECS_RESPONSE r_msg = MSG_GET_ROSPECS_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_ADD_ACCESSSPEC_RESPONSE r_msg = MSG_ADD_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_DELETE_ACCESSSPEC_RESPONSE r_msg = MSG_DELETE_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_ENABLE_ACCESSSPEC_RESPONSE r_msg = MSG_ENABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_DISABLE_ACCESSSPEC_RESPONSE r_msg = MSG_DISABLE_ACCESSSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_GET_ACCESSSPECS_RESPONSE r_msg = MSG_GET_ACCESSSPECS_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_GET_READER_CONFIG_RESPONSE r_msg = MSG_GET_READER_CONFIG_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_SET_READER_CONFIG_RESPONSE r_msg = MSG_SET_READER_CONFIG_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        case ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION_RESPONSE:
                            {
                                bArr = Util.ConvertByteArrayToBitArray(data);
                                length = bArr.Count;
                                MSG_CLOSE_CONNECTION_RESPONSE r_msg = MSG_CLOSE_CONNECTION_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                                return r_msg;
                            }

                        default:
                            return null;
                    }
                }
                else
                {
                    return null;
                }

            }
            catch
            {
                throw new Exception("Transaction Failed");
            }
        }
        public void SendMessage(Message msg)
        {
            bool[] bit_array = msg.ToBitArray();
            byte[] data = Util.ConvertBitArrayToByteArray(bit_array);

            lock (this)
            {
                b_enqueue = true;
            }

            try
            {
                Transaction.Send(cI, data);
            }
            catch
            {
                throw new Exception("Transaction Failed");
            }
        }