/// <summary></summary> private void GetReaderConfig(bool isSaved = false) { var msg = new MSG_GET_READER_CONFIG(); msg.AntennaID = 0; msg.RequestedData = ENUM_GetReaderConfigRequestedData.All; MSG_ERROR_MESSAGE?msgErr = null; var resp = this.BaseClient?.GET_READER_CONFIG(msg, out msgErr, 3000); this.CheckLLRPError(resp, msgErr); if (resp != null) { Console.Error.WriteLine($"{resp.ToString()}"); if (isSaved) { System.IO.File.WriteAllTextAsync( path: "get_reader_config.xml", contents: resp.ToString()) .Wait(); } } }
/// <summary></summary> private void GetReaderConfig() { MSG_GET_READER_CONFIG msg = new MSG_GET_READER_CONFIG(); msg.RequestedData = ENUM_GetReaderConfigRequestedData.All; PARAM_ImpinjRequestedData pRequestData = new PARAM_ImpinjRequestedData(); msg.Custom.Add(pRequestData); pRequestData.RequestedData = ENUM_ImpinjRequestedDataType.All_Configuration; MSG_ERROR_MESSAGE?msgErr = null; MSG_GET_READER_CONFIG_RESPONSE?msgResp = this.llrpClient?.GET_READER_CONFIG( msg: msg, msg_err: out msgErr, time_out: this.timeout); LLRPHelper.CheckError(msgResp, msgErr); if (msgResp != null) { if (msgResp.Identification != null) { switch (msgResp.Identification.IDType) { case ENUM_IdentificationType.MAC_Address: this.macAddress = msgResp.Identification.ReaderID.ToHexString(); break; } } } }
private void Get_Reader_Config() { MSG_GET_READER_CONFIG msg = new MSG_GET_READER_CONFIG(); msg.RequestedData = ENUM_GetReaderConfigRequestedData.All; //msg.AntennaID = 1; //msg.GPIPortNum = 0; MSG_GET_READER_CONFIG_RESPONSE rsp = reader.GET_READER_CONFIG(msg, out msg_err, 12000); if (rsp != null && rsp.Custom.Count > 0) { Type type = rsp.Custom[0].GetType(); if (type == typeof(PARAM_ImpinjSubRegulatoryRegion)) { ENUM_ImpinjRegulatoryRegion region = ((PARAM_ImpinjSubRegulatoryRegion)(rsp.Custom[0])).RegulatoryRegion; } } if (rsp != null) { textBox2.Text = rsp.ToString(); } else if (msg_err != null) { textBox2.Text = msg_err.ToString(); } else { textBox2.Text = "Command time out!"; } }
private void Get_Reader_Config() { MSG_GET_READER_CONFIG msg = new MSG_GET_READER_CONFIG(); msg.AntennaID = 1; msg.GPIPortNum = 0; MSG_GET_READER_CONFIG_RESPONSE rsp = reader.GET_READER_CONFIG(msg, out msg_err, 3000); //rsp. if (rsp != null) { textBox2.Text = rsp.ToString(); } else if (msg_err != null) { textBox2.Text = msg_err.ToString(); } else { textBox2.Text = "Command time out!"; } }
////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// #region Reader Config public void Get_Reader_Config() { MSG_GET_READER_CONFIG msg = new MSG_GET_READER_CONFIG(); msg.AntennaID = 1; msg.GPIPortNum = 0; MSG_GET_READER_CONFIG_RESPONSE rsp = client.GET_READER_CONFIG(msg, out msg_err, 3000); if (rsp != null) { //textBox2.Text = rsp.ToString() + "\n"; WriteMessage(rsp.ToString(), "Get_Reader_Config"); } else if (msg_err != null) { WriteMessage("Get_Reader_Config " + msg_err.ToString() + "\n"); } else { WriteMessage("Get_Reader_Config Command time out!" + "\n"); } }
public static void ParseXMLToLLRPMessage(string xmlstr, out object msg, out ENUM_LLRP_MSG_TYPE type) { XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(xmlstr); XmlNode node = (XmlNode)xdoc.DocumentElement; switch (node.Name) { case "CUSTOM_MESSAGE": msg = (object)MSG_CUSTOM_MESSAGE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.CUSTOM_MESSAGE; return; case "GET_READER_CAPABILITIES": msg = (object)MSG_GET_READER_CAPABILITIES.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES; return; case "GET_READER_CAPABILITIES_RESPONSE": msg = (object)MSG_GET_READER_CAPABILITIES_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES_RESPONSE; return; case "ADD_ROSPEC": msg = (object)MSG_ADD_ROSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ADD_ROSPEC; return; case "ADD_ROSPEC_RESPONSE": msg = (object)MSG_ADD_ROSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ADD_ROSPEC_RESPONSE; return; case "DELETE_ROSPEC": msg = (object)MSG_DELETE_ROSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC; return; case "DELETE_ROSPEC_RESPONSE": msg = (object)MSG_DELETE_ROSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC_RESPONSE; return; case "START_ROSPEC": msg = (object)MSG_START_ROSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.START_ROSPEC; return; case "START_ROSPEC_RESPONSE": msg = (object)MSG_START_ROSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.START_ROSPEC_RESPONSE; return; case "STOP_ROSPEC": msg = (object)MSG_STOP_ROSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.STOP_ROSPEC; return; case "STOP_ROSPEC_RESPONSE": msg = (object)MSG_STOP_ROSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.STOP_ROSPEC_RESPONSE; return; case "ENABLE_ROSPEC": msg = (object)MSG_ENABLE_ROSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC; return; case "ENABLE_ROSPEC_RESPONSE": msg = (object)MSG_ENABLE_ROSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC_RESPONSE; return; case "DISABLE_ROSPEC": msg = (object)MSG_DISABLE_ROSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC; return; case "DISABLE_ROSPEC_RESPONSE": msg = (object)MSG_DISABLE_ROSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC_RESPONSE; return; case "GET_ROSPECS": msg = (object)MSG_GET_ROSPECS.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_ROSPECS; return; case "GET_ROSPECS_RESPONSE": msg = (object)MSG_GET_ROSPECS_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_ROSPECS_RESPONSE; return; case "ADD_ACCESSSPEC": msg = (object)MSG_ADD_ACCESSSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC; return; case "ADD_ACCESSSPEC_RESPONSE": msg = (object)MSG_ADD_ACCESSSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC_RESPONSE; return; case "DELETE_ACCESSSPEC": msg = (object)MSG_DELETE_ACCESSSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC; return; case "DELETE_ACCESSSPEC_RESPONSE": msg = (object)MSG_DELETE_ACCESSSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC_RESPONSE; return; case "ENABLE_ACCESSSPEC": msg = (object)MSG_ENABLE_ACCESSSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC; return; case "ENABLE_ACCESSSPEC_RESPONSE": msg = (object)MSG_ENABLE_ACCESSSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC_RESPONSE; return; case "DISABLE_ACCESSSPEC": msg = (object)MSG_DISABLE_ACCESSSPEC.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC; return; case "DISABLE_ACCESSSPEC_RESPONSE": msg = (object)MSG_DISABLE_ACCESSSPEC_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC_RESPONSE; return; case "GET_ACCESSSPECS": msg = (object)MSG_GET_ACCESSSPECS.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS; return; case "GET_ACCESSSPECS_RESPONSE": msg = (object)MSG_GET_ACCESSSPECS_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS_RESPONSE; return; case "GET_READER_CONFIG": msg = (object)MSG_GET_READER_CONFIG.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG; return; case "GET_READER_CONFIG_RESPONSE": msg = (object)MSG_GET_READER_CONFIG_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG_RESPONSE; return; case "SET_READER_CONFIG": msg = (object)MSG_SET_READER_CONFIG.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG; return; case "SET_READER_CONFIG_RESPONSE": msg = (object)MSG_SET_READER_CONFIG_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG_RESPONSE; return; case "CLOSE_CONNECTION": msg = (object)MSG_CLOSE_CONNECTION.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION; return; case "CLOSE_CONNECTION_RESPONSE": msg = (object)MSG_CLOSE_CONNECTION_RESPONSE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION_RESPONSE; return; case "GET_REPORT": msg = (object)MSG_GET_REPORT.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.GET_REPORT; return; case "RO_ACCESS_REPORT": msg = (object)MSG_RO_ACCESS_REPORT.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.RO_ACCESS_REPORT; return; case "KEEPALIVE": msg = (object)MSG_KEEPALIVE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.KEEPALIVE; return; case "KEEPALIVE_ACK": msg = (object)MSG_KEEPALIVE_ACK.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.KEEPALIVE_ACK; return; case "READER_EVENT_NOTIFICATION": msg = (object)MSG_READER_EVENT_NOTIFICATION.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.READER_EVENT_NOTIFICATION; return; case "ENABLE_EVENTS_AND_REPORTS": msg = (object)MSG_ENABLE_EVENTS_AND_REPORTS.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ENABLE_EVENTS_AND_REPORTS; return; case "ERROR_MESSAGE": msg = (object)MSG_ERROR_MESSAGE.FromString(xmlstr); type = ENUM_LLRP_MSG_TYPE.ERROR_MESSAGE; return; default: msg = null; type = 0; return; } }
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 PARAM_C1G2RFControl GetRFcontrol() { PARAM_C1G2RFControl rfControl = null; MSG_GET_READER_CONFIG readerConfig = new MSG_GET_READER_CONFIG(); readerConfig.RequestedData = ENUM_GetReaderConfigRequestedData.AntennaConfiguration; MSG_GET_READER_CONFIG_RESPONSE readerConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(readerConfig); // get active mode index // Fetch the antenna configurationList from the response PARAM_AntennaConfiguration[] antConfigList = readerConfigResp.AntennaConfiguration; for (int getAntCfg = 0; getAntCfg < antConfigList.Length; getAntCfg++) { UNION_AirProtocolInventoryCommandSettings getProtocolList = antConfigList[getAntCfg].AirProtocolInventoryCommandSettings; rfControl = ((PARAM_C1G2InventoryCommand)getProtocolList[0]).C1G2RFControl; } return rfControl; }
private void ProbeHardware() { //get antenna portlist int antennaport = 0; MSG_GET_READER_CONFIG msgConfig = new MSG_GET_READER_CONFIG(); MSG_GET_READER_CONFIG_RESPONSE msgConfigRes; try { msgConfig.AntennaID = 0; msgConfig.RequestedData = ENUM_GetReaderConfigRequestedData.AntennaProperties; msgConfigRes = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgConfig); } catch (Exception ex) { throw new ReaderException(ex.Message); } //Build antenna portlist List<int> antennaPortlist = new List<int>(); if (null == msgConfigRes) { throw new Exception("Not able to get reader configuration"); } PARAM_AntennaProperties[] ant = msgConfigRes.AntennaProperties; antennaMax = ant.Length; for (int port = 0; port < antennaMax; port++) { try { antennaport = Convert.ToInt32(msgConfigRes.AntennaProperties[port].AntennaID); antennaPortlist.Add(antennaport); } catch (Exception ex) { throw new ReaderException(ex.Message); } } antennaPorts = antennaPortlist.ToArray(); //Get Power max and power min MSG_GET_READER_CAPABILITIES msgCapab = new MSG_GET_READER_CAPABILITIES(); MSG_GET_READER_CAPABILITIES_RESPONSE msgCapabRes; try { msgCapab.RequestedData = ENUM_GetReaderCapabilitiesRequestedData.All; msgCapabRes = (MSG_GET_READER_CAPABILITIES_RESPONSE)SendLlrpMessage(msgCapab); } catch (Exception ex) { throw new ReaderException(ex.Message); } //Build Power max and power min List<int> pwrlist = new List<int>(); PARAM_TransmitPowerLevelTableEntry[] powertable = msgCapabRes.RegulatoryCapabilities.UHFBandCapabilities.TransmitPowerLevelTableEntry; for (int PwrLevelTableIndex = 0; PwrLevelTableIndex < powertable.Length; PwrLevelTableIndex++) { try { int value = Convert.ToInt32(msgCapabRes.RegulatoryCapabilities.UHFBandCapabilities.TransmitPowerLevelTableEntry[PwrLevelTableIndex].TransmitPowerValue); pwrlist.Add(value); } catch (Exception ex) { throw new ReaderException(ex.Message); } } pwrlist.Sort(); rfPowerMin = pwrlist[0]; rfPowerMax = pwrlist[(powertable.Length) - 1]; //cache frequency hop table frequencyHopTable = msgCapabRes.RegulatoryCapabilities.UHFBandCapabilities.FrequencyInformation.FrequencyHopTable; //cache the PowerTableEntry PowerTableEntry = msgCapabRes.RegulatoryCapabilities.UHFBandCapabilities.TransmitPowerLevelTableEntry; //Build table from PowerTableEntry to get transmitpwrvalue and index PowerValueTable = new Hashtable(); PowerIndexTable = new Hashtable(); foreach (PARAM_TransmitPowerLevelTableEntry pwrEntry in PowerTableEntry) { PowerValueTable.Add(pwrEntry.Index, pwrEntry.TransmitPowerValue); PowerIndexTable.Add(pwrEntry.TransmitPowerValue, pwrEntry.Index); } //cache the UHF band capabilities to set blf and tari PARAM_UHFBandCapabilities capabilities = msgCapabRes.RegulatoryCapabilities.UHFBandCapabilities; CacheRFModeTable(capabilities); //model if (msgCapabRes.GeneralDeviceCapabilities.DeviceManufacturerName == TM_MANUFACTURER_ID) //ThingMagic vendor id { //building model as M6 switch (msgCapabRes.GeneralDeviceCapabilities.ModelName) { case 6: model = "Mercury6"; break; case 48: model = "Astra-EX"; break; default: model = "Unknown"; break; } } //GPIO if (model.Equals("Mercury6") || model.Equals("Astra-EX")) { //GPIO InputList gpiList = new int[] { 3, 4, 6, 7 }; //GPIO OutputList gpoList = new int[] { 0, 1, 2, 5 }; } //software version softwareVersion = msgCapabRes.GeneralDeviceCapabilities.ReaderFirmwareVersion; //Region Id try { MSG_GET_READER_CONFIG_RESPONSE readerConfigResponse = GetCustomReaderConfigResponse(ENUM_ThingMagicControlConfiguration.ThingMagicRegionConfiguration); PARAM_ThingMagicRegionConfiguration par = (PARAM_ThingMagicRegionConfiguration)readerConfigResponse.Custom[0]; regionId = (Region)par.RegionID; } catch (Exception ex) { throw new ReaderException(ex.Message); } }
/// <summary> /// Get reader configuration response. /// </summary> /// <param name="requestData">ENUM_GetReaderConfigRequestedData</param> private MSG_GET_READER_CONFIG_RESPONSE GetReaderConfigResponse(ENUM_GetReaderConfigRequestedData requestData) { MSG_GET_READER_CONFIG getReadConfig = new MSG_GET_READER_CONFIG(); MSG_GET_READER_CONFIG_RESPONSE getReadConfigResp; getReadConfig.RequestedData = requestData; try { getReadConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(getReadConfig); } catch (Exception ex) { throw new ReaderException(ex.Message); } return getReadConfigResp; }
/// <summary> /// Get custom reader configuration response. /// </summary> /// <param name="requestData">ENUM_ThingMagicControlConfiguration</param> private MSG_GET_READER_CONFIG_RESPONSE GetCustomReaderConfigResponse(ENUM_ThingMagicControlConfiguration requestData) { // Create Get reader config message MSG_GET_READER_CONFIG getReadConfig = new MSG_GET_READER_CONFIG(); MSG_GET_READER_CONFIG_RESPONSE getReadConfigResp; getReadConfig.RequestedData = ENUM_GetReaderConfigRequestedData.Identification; PARAM_ThingMagicDeviceControlConfiguration controlConfig = new PARAM_ThingMagicDeviceControlConfiguration (); // Set the requested data (i.e., controlconfig object) controlConfig.RequestedData = requestData ; //add to GET_READER_CONFIG message. getReadConfig.AddCustomParameter(controlConfig); //now the message is fully framed send the message try { getReadConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(getReadConfig); } catch (Exception ex) { throw new ReaderException(ex.Message); } return getReadConfigResp; }
/// <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; }
/// <summary> /// Get session /// </summary> /// <param name="val"></param> /// <returns>object</returns> private object GetSession(Object val) { MSG_GET_READER_CONFIG msgGetConfig = new MSG_GET_READER_CONFIG(); MSG_GET_READER_CONFIG_RESPONSE msgGetConfigResp; msgGetConfig.RequestedData = ENUM_GetReaderConfigRequestedData.AntennaConfiguration; try { msgGetConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgGetConfig); //All antenna configurations should have same session. //Hence considering only session of antenna Id 1's configuration PARAM_AntennaConfiguration[] antennaconfig = msgGetConfigResp.AntennaConfiguration; PARAM_C1G2SingulationControl SingulationControl = ((PARAM_C1G2InventoryCommand)(antennaconfig[0].AirProtocolInventoryCommandSettings[0])).C1G2SingulationControl; val = SingulationControl.Session.ToInt(); } catch (Exception ex) { throw new ReaderException(ex.Message); } return Enum.Parse(typeof(Gen2.Session),val.ToString(),true); }
/// <summary> /// Set ThingMagic DeDuplication fields such as RecordHighestRssi, UniqueByAntenna and UniqueByData. /// </summary> /// <param name="val"></param> /// <param name="deDuplicationfield"></param> /// <returns>object</returns> private object SetThingMagicDeDuplicationFields(Object val, ThingMagicDeDuplication deDuplicationfield) { MSG_GET_READER_CONFIG msgGetConfig = new MSG_GET_READER_CONFIG(); MSG_GET_READER_CONFIG_RESPONSE msgGetConfigResp; PARAM_ThingMagicDeDuplication defaultdeDuplicationFields; msgGetConfig.RequestedData = ENUM_GetReaderConfigRequestedData.Identification; PARAM_ThingMagicDeviceControlConfiguration deviceConfig = new PARAM_ThingMagicDeviceControlConfiguration(); deviceConfig.RequestedData = ENUM_ThingMagicControlConfiguration.ThingMagicDeDuplication; msgGetConfig.AddCustomParameter(deviceConfig); try { msgGetConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgGetConfig); defaultdeDuplicationFields = (PARAM_ThingMagicDeDuplication)msgGetConfigResp.Custom[0]; } catch (Exception ex) { throw new ReaderException(ex.Message); } MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG(); MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp; try { switch (deDuplicationfield) { case ThingMagicDeDuplication.RecordHighestRssi: defaultdeDuplicationFields.RecordHighestRSSI = (bool)val; break; case ThingMagicDeDuplication.UniqueByAntenna: defaultdeDuplicationFields.UniqueByAntenna = (bool)val; break; case ThingMagicDeDuplication.UniqueByData: defaultdeDuplicationFields.UniqueByData = (bool)val; break; } msgSetConfig.AddCustomParameter(defaultdeDuplicationFields); msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig); } catch (Exception ex) { throw new ReaderException(ex.Message); } return val; }
/// <summary> /// Set Reader HostName /// </summary> /// <param name="val"></param> /// <returns>object</returns> private object SetReaderHostName(Object val) { string readerDescription = string.Empty; string readerRole = string.Empty; MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG(); MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp; PARAM_ThingMagicReaderConfiguration rd = new PARAM_ThingMagicReaderConfiguration(); 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.ThingMagicReaderConfiguration; msgGetConfig.AddCustomParameter(deviceConfig); try { MSG_GET_READER_CONFIG_RESPONSE msgGetConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgGetConfig); PARAM_ThingMagicReaderConfiguration par = (PARAM_ThingMagicReaderConfiguration)msgGetConfigResp.Custom[0]; readerDescription = par.ReaderDescription; readerRole = par.ReaderRole; } catch (Exception ex) { { throw new ReaderException(ex.Message); } } string value = (string)val; rd.ReaderHostName = value; rd.ReaderDescription = readerDescription; rd.ReaderRole = readerRole; msgSetConfig.AddCustomParameter(rd); try { msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig); } catch (Exception ex) { throw new ReaderException(ex.Message); } return val; }
/// <summary> /// Get the state of all of the reader's GPI pins. /// </summary> /// <returns>array of GpioPin objects representing the state of all input pins</returns> public override GpioPin[] GpiGet() { MSG_GET_READER_CONFIG msg = new MSG_GET_READER_CONFIG(); msg.RequestedData = ENUM_GetReaderConfigRequestedData.GPIPortCurrentState; MSG_GET_READER_CONFIG_RESPONSE response = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msg); List<GpioPin> list = new List<GpioPin>(); if (response.GPIPortCurrentState != null) { foreach (PARAM_GPIPortCurrentState state in response.GPIPortCurrentState) { int id = LlrpToTmGpi(state.GPIPortNum); bool high = (ENUM_GPIPortState.High == state.State); bool output = false; GpioPin pin = new GpioPin(id, high, output); list.Add(pin); } } return list.ToArray(); }