/// <summary> /// Set write transmit power list /// </summary> /// <param name="val"></param> /// <returns>object</returns> private object SetWriteTransmitPowerList(Object val) { int power = 0; int[] amode = new int[antennaMax]; string[] rpoint = new string[antennaMax]; PARAM_ThingMagicAntennaConfiguration[] paramAntennaConfig = new PARAM_ThingMagicAntennaConfiguration[antennaMax]; //Get readpointdescription, antennamode MSG_GET_READER_CONFIG msgGetConfig = new MSG_GET_READER_CONFIG(); msgGetConfig.RequestedData = ENUM_GetReaderConfigRequestedData.Identification; PARAM_ThingMagicDeviceControlConfiguration deviceConfig = new PARAM_ThingMagicDeviceControlConfiguration(); deviceConfig.RequestedData = ENUM_ThingMagicControlConfiguration.ThingMagicAntennaConfiguration; msgGetConfig.AddCustomParameter(deviceConfig); try { MSG_GET_READER_CONFIG_RESPONSE msgGetConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgGetConfig); for (int count = 0; count < antennaMax; count++) { paramAntennaConfig[count] = (PARAM_ThingMagicAntennaConfiguration)msgGetConfigResp.Custom[count]; } } catch (Exception ex) { throw new ReaderException(ex.Message); } //Set PortWritePowerList MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG(); MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp; int[][] prpListValues = (int[][])val; foreach (int[] row in prpListValues) { PARAM_ThingMagicAntennaConfiguration pa = new PARAM_ThingMagicAntennaConfiguration(); PARAM_RFTransmitter prf = new PARAM_RFTransmitter(); List<int> pwrValueList = new List<int>(); foreach (DictionaryEntry pwrEntry in PowerIndexTable) { pwrValueList.Add(Convert.ToInt32(pwrEntry.Key)); } int[] pwrValue = pwrValueList.ToArray(); Array.Sort(pwrValue); if ((row[0] > 0) && (row[0] <= antennaMax)) { power = row[1]; ValidatePowerLevel(power); if ((model.Equals("Astra-EX")) && (regionId.Equals(Region.NA)) && (row[0] == 1)) { if (power > 3000) { throw new ArgumentOutOfRangeException(String.Format("Requested power ({0:D}) too high (RFPowerMax={1:D}cdBm)", power, 3000)); } } if (true == PowerIndexTable.ContainsKey(Convert.ToInt16(power))) { paramAntennaConfig[row[0] - 1].WriteTransmitPower.WriteTransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]); } else { power = RoundOffPowerLevel(power, pwrValue); paramAntennaConfig[row[0] - 1].WriteTransmitPower.WriteTransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]); } msgSetConfig.AddCustomParameter(paramAntennaConfig[row[0] - 1]); } else { throw new ArgumentOutOfRangeException("Antenna id is invalid"); } } try { msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig); } catch (Exception ex) { throw new ReaderException(ex.Message); } return val; }
static void Main(string[] args) { LLRPClient reader; if (args.Length != 1) { usage(); return; } string readerName = args[0]; Console.WriteLine( "Impinj C# LTK.NET RFID Application DocSample2 reader - " + readerName + "\n"); #region Initializing { Console.WriteLine("Initializing\n"); //Create an instance of LLRP reader client. reader = new LLRPClient(); //Impinj Best Practice! Always Install the Impinj extensions Impinj_Installer.Install(); } #endregion #region EventHandlers { Console.WriteLine("Adding Event Handlers\n"); reader.OnReaderEventNotification += new delegateReaderEventNotification(reader_OnReaderEventNotification); reader.OnRoAccessReportReceived += new delegateRoAccessReport(reader_OnRoAccessReportReceived); } #endregion #region Connecting { Console.WriteLine("Connecting To Reader\n"); ENUM_ConnectionAttemptStatusType status; //Open the reader connection. Timeout after 5 seconds bool ret = reader.Open(readerName, 5000, out status); //Ensure that the open succeeded and that the reader // returned the correct connection status result if (!ret || status != ENUM_ConnectionAttemptStatusType.Success) { Console.WriteLine("Failed to Connect to Reader \n"); return; } } #endregion #region EnableExtensions { Console.WriteLine("Enabling Impinj Extensions\n"); MSG_IMPINJ_ENABLE_EXTENSIONS imp_msg = new MSG_IMPINJ_ENABLE_EXTENSIONS(); MSG_ERROR_MESSAGE msg_err; imp_msg.MSG_ID = 1; // not this doesn't need to bet set as the library will default //Send the custom message and wait for 8 seconds MSG_CUSTOM_MESSAGE cust_rsp = reader.CUSTOM_MESSAGE(imp_msg, out msg_err, 8000); MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE msg_rsp = cust_rsp as MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE; if (msg_rsp != null) { if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("Enable Extensions Command Timed out\n"); reader.Close(); return; } } #endregion #region FactoryDefault { Console.WriteLine("Factory Default the Reader\n"); // factory default the reader MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG(); MSG_ERROR_MESSAGE msg_err; msg_cfg.ResetToFactoryDefault = true; msg_cfg.MSG_ID = 2; //this doesn't need to bet set as the library will default //if SET_READER_CONFIG affects antennas it could take several seconds to return MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000); if (rsp_cfg != null) { if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("SET_READER_CONFIG Command Timed out\n"); reader.Close(); return; } } #endregion #region getReaderCapabilities { Console.WriteLine("Getting Reader Capabilities\n"); MSG_GET_READER_CAPABILITIES cap = new MSG_GET_READER_CAPABILITIES(); cap.MSG_ID = 2; // not this doesn't need to bet set as the library will default cap.RequestedData = ENUM_GetReaderCapabilitiesRequestedData.All; //Send the custom message and wait for 8 seconds MSG_ERROR_MESSAGE msg_err; MSG_GET_READER_CAPABILITIES_RESPONSE msg_rsp = reader.GET_READER_CAPABILITIES(cap, out msg_err, 8000); if (msg_rsp != null) { if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("GET reader Capabilities Command Timed out\n"); reader.Close(); return; } // Get the reader model number PARAM_GeneralDeviceCapabilities dev_cap = msg_rsp.GeneralDeviceCapabilities; // Check to make sure the model number mathces and that this device // is an impinj reader (deviceManufacturerName == 25882) if ((dev_cap != null) && (dev_cap.DeviceManufacturerName == 25882)) { } else { Console.WriteLine("Could not determine reader model number\n"); reader.Close(); return; } // get the uhf band capabilities. Inside this is the power table. // take the last element of the power table to get the highest power. PARAM_UHFBandCapabilities uhf = msg_rsp.RegulatoryCapabilities.UHFBandCapabilities; PARAM_TransmitPowerLevelTableEntry entry = uhf.TransmitPowerLevelTableEntry[uhf.TransmitPowerLevelTableEntry.Length - 1]; txPwrIndx = entry.Index; double power = entry.TransmitPowerValue / 100; Console.WriteLine(" Max Power " + power.ToString() + " dbm."); } #endregion #region getReaderConfig { Console.WriteLine("Getting Reader Configuration\n"); MSG_GET_READER_CONFIG cap = new MSG_GET_READER_CONFIG(); cap.MSG_ID = 2; // not this doesn't need to bet set as the library will default cap.RequestedData = ENUM_GetReaderConfigRequestedData.All; //Send the custom message and wait for 8 seconds MSG_ERROR_MESSAGE msg_err; MSG_GET_READER_CONFIG_RESPONSE msg_rsp = reader.GET_READER_CONFIG(cap, out msg_err, 8000); if (msg_rsp != null) { if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("GET reader Config Command Timed out\n"); reader.Close(); return; } // Get the hopTableId and Channel Index if ((null != msg_rsp.AntennaConfiguration) && (0 < msg_rsp.AntennaConfiguration.Length) && (null != msg_rsp.AntennaConfiguration[0].RFTransmitter)) { PARAM_RFTransmitter rftx = msg_rsp.AntennaConfiguration[0].RFTransmitter; // we have to get these two values as well otherwise // we won't know what to fill in the RFTransmitter // parameter when we set transmit power ChannelIndex = rftx.ChannelIndex; hopTableID = rftx.HopTableID; Console.WriteLine(" Saving ChanIndex " + ChannelIndex.ToString() + " hopTableId " + hopTableID.ToString()); } else { Console.WriteLine("Could not get rf transmitter parameters\n"); reader.Close(); return; } } #endregion #region SetReaderConfigWithXML { Console.WriteLine("Adding SET_READER_CONFIG from XML file \n"); Org.LLRP.LTK.LLRPV1.DataType.Message obj; ENUM_LLRP_MSG_TYPE msg_type; // read the XML from a file and validate its an ADD_ROSPEC try { FileStream fs = new FileStream(@"..\..\setReaderConfig.xml", FileMode.Open); StreamReader sr = new StreamReader(fs); string s = sr.ReadToEnd(); fs.Close(); LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type); if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG) { Console.WriteLine("Could not extract message from XML"); reader.Close(); return; } } catch { Console.WriteLine("Unable to convert to valid XML"); reader.Close(); return; } // Communicate that message to the reader MSG_SET_READER_CONFIG msg = (MSG_SET_READER_CONFIG)obj; // set the max power available but don' forget to // apply the hoptable and channelIndex from the // current configuration PARAM_AntennaConfiguration ant = msg.AntennaConfiguration[0]; ant.RFTransmitter.TransmitPower = (ushort)txPwrIndx; ant.RFTransmitter.ChannelIndex = (ushort)ChannelIndex; ant.RFTransmitter.HopTableID = (ushort)hopTableID; MSG_ERROR_MESSAGE msg_err; MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000); if (rsp != null) { if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("SET_READER_CONFIG Command Timed out\n"); reader.Close(); return; } } #endregion #region ADDRoSpecWithXML { Console.WriteLine("Adding RoSpec from XML file \n"); Org.LLRP.LTK.LLRPV1.DataType.Message obj; ENUM_LLRP_MSG_TYPE msg_type; // read the XML from a file and validate its an ADD_ROSPEC try { FileStream fs = new FileStream(@"..\..\addRoSpec.xml", FileMode.Open); StreamReader sr = new StreamReader(fs); string s = sr.ReadToEnd(); fs.Close(); LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type); if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.ADD_ROSPEC) { Console.WriteLine("Could not extract message from XML"); reader.Close(); return; } } catch { Console.WriteLine("Unable to convert to valid XML"); reader.Close(); return; } // covert to the proper message type MSG_ADD_ROSPEC msg = (MSG_ADD_ROSPEC)obj; // Communicate that message to the reader MSG_ERROR_MESSAGE msg_err; MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 12000); if (rsp != null) { if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("ADD_ROSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region EnableRoSpec { Console.WriteLine("Enabling RoSpec\n"); MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC(); MSG_ERROR_MESSAGE msg_err; msg.ROSpecID = 1111; // this better match the ROSpec we created above MSG_ENABLE_ROSPEC_RESPONSE rsp = reader.ENABLE_ROSPEC(msg, out msg_err, 12000); if (rsp != null) { if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("ENABLE_ROSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region StartRoSpec { Console.WriteLine("Starting RoSpec\n"); MSG_START_ROSPEC msg = new MSG_START_ROSPEC(); MSG_ERROR_MESSAGE msg_err; msg.ROSpecID = 1111; // this better match the RoSpec we created above MSG_START_ROSPEC_RESPONSE rsp = reader.START_ROSPEC(msg, out msg_err, 12000); if (rsp != null) { if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("START_ROSPEC Command Timed out\n"); reader.Close(); return; } } #endregion // wait around to collect some data Thread.Sleep(60000); #region StopRoSpec { Console.WriteLine("Stopping RoSpec\n"); MSG_STOP_ROSPEC msg = new MSG_STOP_ROSPEC(); MSG_ERROR_MESSAGE msg_err; msg.ROSpecID = 1111; // this better match the RoSpec we created above MSG_STOP_ROSPEC_RESPONSE rsp = reader.STOP_ROSPEC(msg, out msg_err, 12000); if (rsp != null) { if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("STOP_ROSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region Clean Up Reader Configuration { Console.WriteLine("Factory Default the Reader\n"); // factory default the reader MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG(); MSG_ERROR_MESSAGE msg_err; msg_cfg.ResetToFactoryDefault = true; msg_cfg.MSG_ID = 2; // not this doesn't need to bet set as the library will default // Note that if SET_READER_CONFIG affects antennas it could take several seconds to return MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000); if (rsp_cfg != null) { if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success) { Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString()); reader.Close(); return; } } else if (msg_err != null) { Console.WriteLine(msg_err.ToString()); reader.Close(); return; } else { Console.WriteLine("SET_READER_CONFIG Command Timed out\n"); reader.Close(); return; } } #endregion Console.WriteLine(" Received " + reportCount + " Tag Reports."); Console.WriteLine(" Received " + eventCount + " Events."); Console.WriteLine("Closing\n"); // clean up the reader reader.Close(); reader.OnReaderEventNotification -= new delegateReaderEventNotification(reader_OnReaderEventNotification); reader.OnRoAccessReportReceived -= new delegateRoAccessReport(reader_OnRoAccessReportReceived); }
private object SetReadTransmitPowerList(Object val) { int power = 0; MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG(); MSG_SET_READER_CONFIG_RESPONSE msgSetConfigRes = new MSG_SET_READER_CONFIG_RESPONSE(); List<PARAM_AntennaConfiguration> ac = new List<PARAM_AntennaConfiguration>(); int[][] prpListValues = (int[][])val; foreach (int[] row in prpListValues) { PARAM_AntennaConfiguration pa = new PARAM_AntennaConfiguration(); PARAM_RFTransmitter prf = new PARAM_RFTransmitter(); if ((row[0] > 0) && (row[0] <= antennaMax)) { power = row[1]; ValidatePowerLevel(power); pa.AntennaID = (ushort)row[0]; if ((model.Equals("Astra-EX")) && (regionId.Equals(Region.NA)) && (pa.AntennaID == 1)) { if (power > 3000) { throw new ArgumentOutOfRangeException(String.Format("Requested power ({0:D}) too high (RFPowerMax={1:D}cdBm)", power, 3000)); } } List<int> pwrValueList = new List<int>(); foreach (DictionaryEntry pwrEntry in PowerIndexTable) { pwrValueList.Add(Convert.ToInt32(pwrEntry.Key)); } int[] pwrValue = pwrValueList.ToArray(); Array.Sort(pwrValue); if (true == PowerIndexTable.ContainsKey(Convert.ToInt16(power))) { prf.TransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]); } else { power = RoundOffPowerLevel(power, pwrValue); prf.TransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]); } pa.RFTransmitter = prf; ac.Add(pa); } else { throw new ArgumentOutOfRangeException("Antenna id is invalid"); } } msgSetConfig.AntennaConfiguration = ac.ToArray(); try { msgSetConfigRes = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig); } catch (Exception ex) { throw new ReaderException(ex.Message); } return val; }