public static void Add_RoSpec(LLRPClient reader) { MSG_ERROR_MESSAGE errorMessage; var msg = new MSG_ADD_ROSPEC { ROSpec = new PARAM_ROSpec() }; msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled; msg.ROSpec.ROSpecID = 123; msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Immediate; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Null; msg.ROSpec.SpecParameter = new UNION_SpecParameter(); var aiSpec = new PARAM_AISpec { AntennaIDs = new UInt16Array() }; aiSpec.AntennaIDs = new UInt16Array(); aiSpec.AntennaIDs.Add(0); aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Null; aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1]; aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec(); aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234; aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; msg.ROSpec.SpecParameter.Add(aiSpec); msg.ROSpec.ROReportSpec = new PARAM_ROReportSpec(); msg.ROSpec.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec; msg.ROSpec.ROReportSpec.N = 1; msg.ROSpec.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector(); var response = reader.ADD_ROSPEC(msg, out errorMessage, 2000); if (response != null) { Console.WriteLine(response.ToString()); } else if (errorMessage != null) { Console.WriteLine(errorMessage.ToString()); } else { Console.WriteLine("Timeout Error"); } }
public static Result <MSG_ADD_ROSPEC_RESPONSE> Add_RoSpec(this LLRPClient reader, TimeSpan?timeout = null) { var startTrigger = new PARAM_ROSpecStartTrigger { ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Immediate }; var stopTrigger = new PARAM_ROSpecStopTrigger { ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Null }; if (timeout != null) { startTrigger.ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Null; stopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Duration; stopTrigger.DurationTriggerValue = (uint)timeout.Value.TotalMilliseconds; } var ROSpec = new PARAM_ROSpec() { // ROSpec must be disabled by default CurrentState = ENUM_ROSpecState.Disabled, ROSpecID = 1, // Specifies the start and stop triggers for the ROSpec ROBoundarySpec = new PARAM_ROBoundarySpec() { // The reader will start reading tags as soon as the is enabled ROSpecStartTrigger = new PARAM_ROSpecStartTrigger() { ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Immediate }, ROSpecStopTrigger = stopTrigger }, SpecParameter = new UNION_SpecParameter(), }; ROSpec.SpecParameter.Add(WispInventoryAISpec()); var message = new MSG_ADD_ROSPEC() { ROSpec = ROSpec }; var response = reader.ADD_ROSPEC(message, out var error, 2000); return(new Result <MSG_ADD_ROSPEC_RESPONSE>(response, error)); }
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 DocSample1 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"); // don't need two kinds of reader events, just use encaped here to demonstrate //reader.OnReaderEventNotification += new delegateReaderEventNotification(reader_OnReaderEventNotification); reader.OnEncapedReaderEventNotification += new delegateEncapReaderEventNotification(reader_OnEncapedReaderEventNotification); 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 ADDRoSpecWithObjects { Console.WriteLine("Adding RoSpec\n"); // set up the basic parameters in the ROSpec. Use all the defaults from the reader MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC(); MSG_ERROR_MESSAGE msg_err; msg.ROSpec = new PARAM_ROSpec(); msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled; msg.ROSpec.Priority = 0x00; msg.ROSpec.ROSpecID = 1111; // setup the start and stop triggers in the Boundary Spec msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Null; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Null; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.DurationTriggerValue = 0; // ignored by reader // Add a single Antenna Inventory to the ROSpec msg.ROSpec.SpecParameter = new UNION_SpecParameter(); PARAM_AISpec aiSpec = new PARAM_AISpec(); aiSpec.AntennaIDs = new UInt16Array(); aiSpec.AntennaIDs.Add(0); // all antennas aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Null; // use all the defaults from the reader. Just specify the minimum required aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1]; aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec(); aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234; aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; msg.ROSpec.SpecParameter.Add(aiSpec); 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(10000); #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 + " 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); }
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 DocSample3 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 = msgID++; // note :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 = msgID++; //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 = msgID++; 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 since some features are not // available on Speedway revolution. 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)) { Console.WriteLine("Could not determine reader model number\n"); reader.Close(); return; } // Find out how many inventory filters we support // don't run the application unless we support at least // two inventory filters and 1 access Spec PARAM_C1G2LLRPCapabilities g2_cap = (PARAM_C1G2LLRPCapabilities)msg_rsp.AirProtocolLLRPCapabilities[0]; if ((g2_cap == null) || (g2_cap.MaxNumSelectFiltersPerQuery < 2)) { Console.WriteLine(" reader supports " + g2_cap.MaxNumSelectFiltersPerQuery + " inventory filters \n"); Console.WriteLine("Reader does not support enough" + " inventory (select) filters--- closing\n"); reader.Close(); return; } // find out how many access spec we support. Don't run // the application unless we have 1 accessSpec PARAM_LLRPCapabilities llrp_cap = msg_rsp.LLRPCapabilities; if ((llrp_cap == null) || (llrp_cap.MaxNumAccessSpecs < 1)) { Console.WriteLine(" reader supports " + llrp_cap.MaxNumAccessSpecs + " accessSpecs \n"); Console.WriteLine("Reader does not support enough" + " accessSpecs --- closing\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; msg.MSG_ID = msgID++; 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 { string filename; filename = @"..\..\addRoSpec.xml"; FileStream fs = new FileStream(filename, 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; } MSG_ADD_ROSPEC msg = (MSG_ADD_ROSPEC)obj; msg.MSG_ID = msgID++; // 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 ADDAccessSpecWithXML { Console.WriteLine("Adding AccessSpec 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_ACCESS_SPEC try { FileStream fs = new FileStream(@"..\..\addAccessSpec.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_ACCESSSPEC) { 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_ADD_ACCESSSPEC msg = (MSG_ADD_ACCESSSPEC)obj; msg.MSG_ID = msgID++; MSG_ERROR_MESSAGE msg_err; MSG_ADD_ACCESSSPEC_RESPONSE rsp = reader.ADD_ACCESSSPEC(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_ACCESSSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region ADDAccessSpec { /* This section adds a second accessSpec identical to the * first (except for its ID). This is duplicate code with * the goal of showing an example of how to build LLRP specs * from C# objects rather than XML */ Console.WriteLine("Adding AccessSpec from C# objects \n"); // create the target tag filter spec to perform access only on these tags // This only requires a single filter (LTK/LLRP supports up to 2 ) PARAM_C1G2TargetTag[] targetTag = new PARAM_C1G2TargetTag[1]; targetTag[0] = new PARAM_C1G2TargetTag(); targetTag[0].Match = true; targetTag[0].MB = new TwoBits(1); targetTag[0].Pointer = 16; targetTag[0].TagData = LLRPBitArray.FromHexString("300035"); targetTag[0].TagMask = LLRPBitArray.FromHexString("f800ff"); PARAM_C1G2TagSpec tagSpec = new PARAM_C1G2TagSpec(); tagSpec.C1G2TargetTag = targetTag; // create the read operation to perform when this accessSpec is run PARAM_C1G2Read read = new PARAM_C1G2Read(); read.AccessPassword = 0; read.MB = new TwoBits(3); read.WordCount = 2; read.WordPointer = 0; read.OpSpecID = 2; // add the opSpec and the TagSpec to the AccessCmd PARAM_AccessCommand accessCmd = new PARAM_AccessCommand(); accessCmd.AirProtocolTagSpec = new UNION_AirProtocolTagSpec(); accessCmd.AirProtocolTagSpec.Add(tagSpec); accessCmd.AccessCommandOpSpec.Add(read); // create the stop trigger for the Access Spec PARAM_AccessSpecStopTrigger stop = new PARAM_AccessSpecStopTrigger(); stop.AccessSpecStopTrigger = ENUM_AccessSpecStopTriggerType.Null; stop.OperationCountValue = 0; // Create and set up the basic accessSpec PARAM_AccessSpec accessSpec = new PARAM_AccessSpec(); accessSpec.AccessSpecID = 24; accessSpec.AntennaID = 0; accessSpec.ROSpecID = 0; accessSpec.CurrentState = ENUM_AccessSpecState.Disabled; accessSpec.ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; // add the access command and stop trigger to the accessSpec accessSpec.AccessCommand = accessCmd; accessSpec.AccessSpecStopTrigger = stop; // Add the Access Spec to the ADD_ACCESSSPEC message MSG_ADD_ACCESSSPEC addAccess = new MSG_ADD_ACCESSSPEC(); addAccess.MSG_ID = msgID++; addAccess.AccessSpec = accessSpec; // communicate the message to the reader MSG_ERROR_MESSAGE msg_err; MSG_ADD_ACCESSSPEC_RESPONSE rsp = reader.ADD_ACCESSSPEC(addAccess, 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_ACCESSSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region EnableAccessSpec { Console.WriteLine("Enabling AccessSpec\n"); MSG_ENABLE_ACCESSSPEC msg = new MSG_ENABLE_ACCESSSPEC(); msg.MSG_ID = msgID++; MSG_ERROR_MESSAGE msg_err; msg.AccessSpecID = 23; // this better match the ACCESSSPEC we created above MSG_ENABLE_ACCESSSPEC_RESPONSE rsp = reader.ENABLE_ACCESSSPEC(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_ACCESSSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region EnableRoSpec { Console.WriteLine("Enabling RoSpec\n"); MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC(); msg.MSG_ID = msgID++; 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.MSG_ID = msgID++; 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. for (int delay = 0; delay < 5; delay++) { Thread.Sleep(30000); #region PollReaderReports { Console.WriteLine("Polling Report Data\n"); MSG_GET_REPORT msg = new MSG_GET_REPORT(); MSG_ERROR_MESSAGE msg_err; msg.MSG_ID = msgID++; reader.GET_REPORT(msg, out msg_err, 10000); } #endregion } #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 = msgID++;; // note 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 " + accessCount + " Access Reports."); 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); }
static void Add_RoSpec() { MSG_ERROR_MESSAGE msg_err; MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC(); // Reader Operation Spec (ROSpec) msg.ROSpec = new PARAM_ROSpec(); // ROSpec должен быть по умолчанию не доступен msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled; // The ROSpec ID может получить числовой ID msg.ROSpec.ROSpecID = 123; // ROBoundarySpec // Specifies the start and stop triggers for the ROSpec msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec(); // Immediate start trigger // The reader will start reading tags as soon as the ROSpec // is enabled msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger .ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Immediate; // No stop trigger. Keep reading tags until the ROSpec is disabled. msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Null; // Antenna Inventory Spec (AISpec) // Specifies which antennas and protocol to use msg.ROSpec.SpecParameter = new UNION_SpecParameter(); PARAM_AISpec aiSpec = new PARAM_AISpec(); aiSpec.AntennaIDs = new UInt16Array(); // Enable all antennas aiSpec.AntennaIDs.Add(0); // No AISpec stop trigger. It stops when the ROSpec stops. aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Null; aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1]; aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec(); aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234; aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; msg.ROSpec.SpecParameter.Add(aiSpec); // Report Spec msg.ROSpec.ROReportSpec = new PARAM_ROReportSpec(); // Send a report for every tag read msg.ROSpec.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec; msg.ROSpec.ROReportSpec.N = 1; msg.ROSpec.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector(); MSG_ADD_ROSPEC_RESPONSE rsp = readerR.ADD_ROSPEC(msg, out msg_err, 2000); }
public void ADDRoSpec() { Console.WriteLine("Adding RoSpec\n"); // set up the basic parameters in the ROSpec. Use all the defaults from the reader MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC(); MSG_ERROR_MESSAGE msg_err; msg.ROSpec = new PARAM_ROSpec(); msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled; msg.ROSpec.Priority = 0x00; msg.ROSpec.ROSpecID = 1111; // setup the start and stop triggers in the Boundary Spec msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Null; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Null; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.DurationTriggerValue = 0; // ignored by reader // Add a single Antenna Inventory to the ROSpec msg.ROSpec.SpecParameter = new UNION_SpecParameter(); PARAM_AISpec aiSpec = new PARAM_AISpec(); aiSpec.AntennaIDs = new UInt16Array(); aiSpec.AntennaIDs.Add(1); aiSpec.AntennaIDs.Add(2); aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Null; // use all the defaults from the reader. Just specify the minimum required aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1]; aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec(); aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234; aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; aiSpec.InventoryParameterSpec[0].AntennaConfiguration = new PARAM_AntennaConfiguration[1]; aiSpec.InventoryParameterSpec[0].AntennaConfiguration[0] = new PARAM_AntennaConfiguration(); aiSpec.InventoryParameterSpec[0].AntennaConfiguration[0].AntennaID = 0; aiSpec.InventoryParameterSpec[0].AntennaConfiguration[0].RFTransmitter = new PARAM_RFTransmitter(); aiSpec.InventoryParameterSpec[0].AntennaConfiguration[0].RFTransmitter.ChannelIndex = 1; aiSpec.InventoryParameterSpec[0].AntennaConfiguration[0].RFTransmitter.TransmitPower = 91; // Add the inventory command to the AI spec. PARAM_C1G2InventoryCommand c1g2Inv = CreateInventoryCommand(); aiSpec.InventoryParameterSpec[0].AntennaConfiguration[0].AirProtocolInventoryCommandSettings.Add(c1g2Inv); msg.ROSpec.SpecParameter.Add(aiSpec); 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; } }
private bool Add_RoSpec() { MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC(); msg.ROSpec = new PARAM_ROSpec(); msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled; msg.ROSpec.Priority = 0x00; msg.ROSpec.ROSpecID = 123; msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Null; //msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.GPITriggerValue = new PARAM_GPITriggerValue(); //msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.GPITriggerValue.GPIPortNum = 1; //msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.GPITriggerValue.Timeout = 10; //msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.GPITriggerValue.GPIEvent = true; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Duration; //msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.GPITriggerValue = new PARAM_GPITriggerValue(); //msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.GPITriggerValue.GPIEvent = false; //msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.GPITriggerValue.GPIPortNum = 1; //msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.GPITriggerValue.Timeout = 2000; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.DurationTriggerValue = 2000; msg.ROSpec.ROReportSpec = new PARAM_ROReportSpec(); msg.ROSpec.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_AISpec; msg.ROSpec.ROReportSpec.N = 1; msg.ROSpec.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector(); msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAccessSpecID = false; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAntennaID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableChannelIndex = false; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp = false; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = false; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp = false; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnablePeakRSSI = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableROSpecID = false; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableSpecIndex = false; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = false; msg.ROSpec.SpecParameter = new UNION_SpecParameter(); PARAM_AISpec aiSpec = new PARAM_AISpec(); aiSpec.AntennaIDs = new UInt16Array(); aiSpec.AntennaIDs.Add(0); //aiSpec.AntennaIDs.Add(2); aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Null; //aiSpec.AISpecStopTrigger.DurationTrigger = 4000; //aiSpec.AISpecStopTrigger.GPITriggerValue = new PARAM_GPITriggerValue(); //aiSpec.AISpecStopTrigger.GPITriggerValue.GPIEvent = false; //aiSpec.AISpecStopTrigger.GPITriggerValue.GPIPortNum = 1; //aiSpec.AISpecStopTrigger.GPITriggerValue.Timeout = 0; aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1]; aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec(); aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234; aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; msg.ROSpec.SpecParameter.Add(aiSpec); //PARAM_ImpinjLoopSpec testloopspec = new PARAM_ImpinjLoopSpec(); //testloopspec.LoopCount = 0; //msg.ROSpec.SpecParameter.AddCustomParameter(testloopspec); MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 12000); if (rsp != null) { //return rsp.ToString(); return(true); } else if (msg_err != null) { //return msg_err.ToString(); return(false); } else { //return "Command time out!"; return(false); } }
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 DocSample4 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)) { modelNumber = dev_cap.ModelName; } else { Console.WriteLine("Could not determine reader model number\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; 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()); Console.WriteLine(rsp.LLRPStatus.ErrorDescription.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(" Calculated " + directionCount + " Velocity Estimates."); 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 void Add_RoSpec() { MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC(); msg.ROSpec = new PARAM_ROSpec(); msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled; msg.ROSpec.Priority = 0x00; msg.ROSpec.ROSpecID = 123; msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Null; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger(); msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Duration; msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.DurationTriggerValue = 1000; msg.ROSpec.ROReportSpec = new PARAM_ROReportSpec(); msg.ROSpec.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec; msg.ROSpec.ROReportSpec.N = 0; msg.ROSpec.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector(); msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAccessSpecID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAntennaID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableChannelIndex = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnablePeakRSSI = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableROSpecID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableSpecIndex = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true; msg.ROSpec.SpecParameter = new UNION_SpecParameter(); PARAM_AISpec aiSpec = new PARAM_AISpec(); aiSpec.AntennaIDs = new LTKD.UInt16Array(); aiSpec.AntennaIDs.Add(0); //0 : applys to all antennae, //aiSpec.AntennaIDs.Add(1); //aiSpec.AntennaIDs.Add(2); ... aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Duration; aiSpec.AISpecStopTrigger.DurationTrigger = 1000; aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1]; aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec(); aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234; aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; msg.ROSpec.SpecParameter.Add(aiSpec); MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 3000); if (rsp != null) { textBox2.Text = rsp.ToString(); } else if (msg_err != null) { textBox2.Text = msg_err.ToString(); } else { textBox2.Text = "Command time out!"; } }
////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// #region RO Spec /// <summary> /// Communicates the information of a ROSpec to the Reader. /// </summary> public void Add_RoSpec(ReaderManager.InventoryConfig inventoryconfig, ReaderManager.ReaderConfig readerconfig) { // Create a new message to be sent to the client MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC(); msg.ROSpec = new PARAM_ROSpec(); msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled; // Reader's current state: Disable msg.ROSpec.Priority = 0x00; // specifies the priority of the rospect msg.ROSpec.ROSpecID = 123; //============================== // Start condition msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec(); msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger(); // Null – No start trigger. The only way to start the ROSpec is with a START_ROSPEC from the Client. // 1 Immediate // 2 Periodic // 3 GPI // Note: This ROSpect starts immediatelly msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = inventoryconfig.startTrigger; // Stop condition msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger(); // 0 Null – Stop when all AISpecs are done, or when preempted, or with a STOP_ROSPEC from the Client. // 1 Duration // 2 GPI with a timeout value // DurationTriggerValue: Duration in milliseconds // Trigger 1 msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = inventoryconfig.stopTrigger; //msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.DurationTriggerValue = 1000; // ROReportSpec triger // 0 None // 1 (Upon N TagReportData Parameters or End of AISpec) Or (End of RFSurveySpec) - N=0 is unlimited. // 2 Upon N TagReportData Parameters or End of ROSpec N=0 is unlimited. // N: Unsigned Short Integer. This is the number of TagReportData Parameters used in ROReportTrigger = 1 and 2. // If N = 0, there is no limit on the number of TagReportData Parameters. // This field SHALL be ignored when ROReportTrigger = 0. msg.ROSpec.ROReportSpec = new PARAM_ROReportSpec(); msg.ROSpec.ROReportSpec.ROReportTrigger = inventoryconfig.reportTrigger; msg.ROSpec.ROReportSpec.N = inventoryconfig.reportN; // Report 2 //msg.ROSpec.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec; //msg.ROSpec.ROReportSpec.N = 0; msg.ROSpec.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector(); msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAccessSpecID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAntennaID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableChannelIndex = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnablePeakRSSI = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableROSpecID = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableSpecIndex = true; msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true; msg.ROSpec.SpecParameter = new UNION_SpecParameter(); // Antena inventory operation PARAM_AISpec aiSpec = new PARAM_AISpec(); // 12345 aiSpec.AntennaIDs = new UInt16Array(); //aiSpec.AntennaIDs.Add(0); //0 : applys to all antennae, for (ushort i = 1; i < readerconfig.antennaID.Length + 1; i++) { if (readerconfig.antennaID[i - 1]) { aiSpec.AntennaIDs.Add(i); } } // Stop trigger parameter // 0 Null – Stop when ROSpec is done. // 1 Duration // 2 GPI with a timeout value // 3 Tag observation //if (inventorymode) //{ // TriggerType: Integer // Possible Values: Value Modulation // ------ ------------ // 0 Upon seeing N tag observations, or timeout // 1 Upon seeing no more new tag observations for t ms,or timeout // 2 N attempts to see all tags in the FOV, or timeout if (inventoryconfig.AITriggerType == ENUM_AISpecStopTriggerType.Tag_Observation) { // Antena inventory operation aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Tag_Observation; aiSpec.AISpecStopTrigger.TagObservationTrigger = new PARAM_TagObservationTrigger(); if (inventoryconfig.numAttempts == 0) { // Trigger type 1: works aiSpec.AISpecStopTrigger.TagObservationTrigger.TriggerType = ENUM_TagObservationTriggerType.Upon_Seeing_N_Tags_Or_Timeout; aiSpec.AISpecStopTrigger.TagObservationTrigger.NumberOfTags = inventoryconfig.numTags; aiSpec.AISpecStopTrigger.TagObservationTrigger.Timeout = inventoryconfig.AITimeout; // There is no time out } else { // Trigger type 2 aiSpec.AISpecStopTrigger.TagObservationTrigger.TriggerType = ENUM_TagObservationTriggerType.N_Attempts_To_See_All_Tags_In_FOV_Or_Timeout; aiSpec.AISpecStopTrigger.TagObservationTrigger.NumberOfAttempts = inventoryconfig.numAttempts; aiSpec.AISpecStopTrigger.TagObservationTrigger.Timeout = inventoryconfig.AITimeout; // There is no time out } } else if (inventoryconfig.AITriggerType == ENUM_AISpecStopTriggerType.Duration) { // Antena inventory operation aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Duration; aiSpec.AISpecStopTrigger.DurationTrigger = inventoryconfig.duration; } else if (inventoryconfig.AITriggerType == ENUM_AISpecStopTriggerType.GPI_With_Timeout) { aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger(); aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.GPI_With_Timeout; aiSpec.AISpecStopTrigger.GPITriggerValue.Timeout = inventoryconfig.AITimeout; } //} // Operational parameters for an inventory using a single air protocol. aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1]; aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec(); aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234; aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; msg.ROSpec.SpecParameter.Add(aiSpec); // Add operational parameters to Add_ROSpec msg // Send message to client and get the response MSG_ADD_ROSPEC_RESPONSE rsp = client.ADD_ROSPEC(msg, out msg_err, 3000); if (rsp != null) { //textBox2.Text = rsp.ToString() + "\n"; WriteMessage(rsp.ToString(), "Add_RoSpec"); WriteMessage("Add_RoSpec \n"); } else if (msg_err != null) { WriteMessage("Add_RoSpec " + msg_err.ToString() + "\n"); } else { WriteMessage("Add_RoSpec Command time out!" + "\n"); } }
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); }
static void Main(string[] args) { LLRPClient reader; int i; #region ProcessCommandLine if (args.Length < 1) { usage(); return; } /* get the options. Skip the last one as its the hostname */ for (i = 0; i < args.Length - 1; i++) { if ((args[i] == "-p") && (i < (args.Length - 1))) { i++; m_password = System.Convert.ToUInt32(args[i]); } else if ((args[i] == "-n") && (i < (args.Length - 1))) { i++; m_newPassword = System.Convert.ToUInt32(args[i]); } else if (args[i] == "-t") { m_tid = ENUM_ImpinjSerializedTIDMode.Enabled; } else if (args[i] == "-s") { m_shortRange = ENUM_ImpinjQTAccessRange.Short_Range; } else if ((args[i] == "-v") && (i < (args.Length - 1))) { i++; m_Verbose = System.Convert.ToUInt32(args[i]); } else if ((args[i] == "-q") && (i < (args.Length - 1))) { i++; m_qtmode = System.Convert.ToUInt32(args[i]); } else { usage(); return; } } m_readerName = args[i]; Console.WriteLine( "Impinj C# LTK.NET RFID Application DocSample5 reader - " + m_readerName + "\n"); Console.WriteLine( " qtMode:" + m_qtmode.ToString() + " Verbose:" + m_Verbose.ToString() + " Range:" + m_shortRange.ToString() + " SerializeTID:" + m_tid.ToString() + " OldPassword:"******" NewPassword:"******"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(m_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 = msgID++; // note :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 = msgID++; //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 = msgID++; 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 since some features are not // available on Speedway revolution. 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)) { Console.WriteLine("Could not determine reader model number\n"); reader.Close(); return; } // Need to parse version number strings and compare to make sure // that the reader version is higher than 4.4. Version readerVersion = new Version(dev_cap.ReaderFirmwareVersion); Version minimumVersion = new Version("4.4.0.0"); if (readerVersion < minimumVersion) { Console.WriteLine("Must use Octane 4.4 or later\n"); reader.Close(); return; } } #endregion #region SetReaderConfig { Console.WriteLine("Adding SET_READER_CONFIG n"); // Communicate that message to the reader MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG(); msg.MSG_ID = msgID++; msg.ResetToFactoryDefault = false; // turn off all reports msg.ROReportSpec = new PARAM_ROReportSpec(); msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector(); msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID = false; msg.ROReportSpec.TagReportContentSelector.EnableAntennaID = false; msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex = false; msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp = false; msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = false; msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp = false; msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI = false; msg.ROReportSpec.TagReportContentSelector.EnableROSpecID = false; msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex = false; msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = false; /* report all tags immediately */ msg.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec; msg.ROReportSpec.N = 1; /* turn on serialized TID if we are asked to */ PARAM_ImpinjTagReportContentSelector impinjTagData = new PARAM_ImpinjTagReportContentSelector(); impinjTagData.ImpinjEnableGPSCoordinates = new PARAM_ImpinjEnableGPSCoordinates(); impinjTagData.ImpinjEnableGPSCoordinates.GPSCoordinatesMode = ENUM_ImpinjGPSCoordinatesMode.Disabled; impinjTagData.ImpinjEnablePeakRSSI = new PARAM_ImpinjEnablePeakRSSI(); impinjTagData.ImpinjEnablePeakRSSI.PeakRSSIMode = ENUM_ImpinjPeakRSSIMode.Disabled; impinjTagData.ImpinjEnableRFPhaseAngle = new PARAM_ImpinjEnableRFPhaseAngle(); impinjTagData.ImpinjEnableRFPhaseAngle.RFPhaseAngleMode = ENUM_ImpinjRFPhaseAngleMode.Disabled; impinjTagData.ImpinjEnableSerializedTID = new PARAM_ImpinjEnableSerializedTID(); impinjTagData.ImpinjEnableSerializedTID.SerializedTIDMode = m_tid; msg.ROReportSpec.Custom.Add(impinjTagData); /* report access specs immediately as well */ msg.AccessReportSpec = new PARAM_AccessReportSpec(); msg.AccessReportSpec.AccessReportTrigger = ENUM_AccessReportTriggerType.End_Of_AccessSpec; // set the antenna configuration for all antennas msg.AntennaConfiguration = new PARAM_AntennaConfiguration[1]; msg.AntennaConfiguration[0] = new PARAM_AntennaConfiguration(); msg.AntennaConfiguration[0].AntennaID = 0; /* all antennas */ // use DRM autset mode PARAM_C1G2InventoryCommand c1g2Inv = new PARAM_C1G2InventoryCommand(); c1g2Inv.C1G2RFControl = new PARAM_C1G2RFControl(); c1g2Inv.C1G2RFControl.ModeIndex = 1000; c1g2Inv.C1G2RFControl.Tari = 0; // Use session 1 so we don't get too many reads c1g2Inv.C1G2SingulationControl = new PARAM_C1G2SingulationControl(); c1g2Inv.C1G2SingulationControl.Session = new TwoBits(1); c1g2Inv.C1G2SingulationControl.TagPopulation = 1; c1g2Inv.C1G2SingulationControl.TagTransitTime = 0; // add to the message msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings.Add(c1g2Inv); 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 { string filename; filename = @"..\..\addRoSpec.xml"; FileStream fs = new FileStream(filename, 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; } MSG_ADD_ROSPEC msg = (MSG_ADD_ROSPEC)obj; msg.MSG_ID = msgID++; // 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 ADDAccessSpec { /* This section adds a second accessSpec identical to the * first (except for its ID). This is duplicate code with * the goal of showing an example of how to build LLRP specs * from C# objects rather than XML */ Console.WriteLine("Adding AccessSpec from C# objects \n"); // create the target tag filter spec to perform access only on these tags // This only requires a single filter (LTK/LLRP supports up to 2 ) PARAM_C1G2TargetTag[] targetTag = new PARAM_C1G2TargetTag[1]; targetTag[0] = new PARAM_C1G2TargetTag(); targetTag[0].Match = true; targetTag[0].MB = new TwoBits(1); targetTag[0].Pointer = 16; targetTag[0].TagData = LLRPBitArray.FromHexString(""); targetTag[0].TagMask = LLRPBitArray.FromHexString(""); PARAM_C1G2TagSpec tagSpec = new PARAM_C1G2TagSpec(); tagSpec.C1G2TargetTag = targetTag; PARAM_AccessCommand accessCmd = new PARAM_AccessCommand(); accessCmd.AirProtocolTagSpec = new UNION_AirProtocolTagSpec(); accessCmd.AirProtocolTagSpec.Add(tagSpec); switch (m_qtmode) { case 0: PARAM_C1G2Read readStdTID = new PARAM_C1G2Read(); readStdTID.AccessPassword = 0; readStdTID.MB = new TwoBits(2); readStdTID.OpSpecID = 1; readStdTID.WordCount = 2; readStdTID.WordPointer = 0; accessCmd.AccessCommandOpSpec.Add(readStdTID); break; case 1: PARAM_C1G2Write writePassword = new PARAM_C1G2Write(); writePassword.OpSpecID = 2; writePassword.MB = new TwoBits(0); writePassword.AccessPassword = m_password; writePassword.WordPointer = 2; writePassword.WriteData = new UInt16Array(); writePassword.WriteData.Add((UInt16)((m_newPassword >> 16) & 0x0000ffff)); writePassword.WriteData.Add((UInt16)(m_newPassword & 0x0000ffff)); accessCmd.AccessCommandOpSpec.Add(writePassword); break; case 2: PARAM_C1G2Read readSerializedTID = new PARAM_C1G2Read(); readSerializedTID.AccessPassword = 0; readSerializedTID.MB = new TwoBits(2); readSerializedTID.OpSpecID = 3; readSerializedTID.WordCount = 6; readSerializedTID.WordPointer = 0; accessCmd.AccessCommandOpSpec.Add(readSerializedTID); PARAM_C1G2Read readPublicEPC = new PARAM_C1G2Read(); readPublicEPC.AccessPassword = 0; readPublicEPC.MB = new TwoBits(2); readPublicEPC.OpSpecID = 4; readPublicEPC.WordCount = 6; readPublicEPC.WordPointer = 6; accessCmd.AccessCommandOpSpec.Add(readPublicEPC); PARAM_C1G2Read readUser = new PARAM_C1G2Read(); readUser.AccessPassword = 0; readUser.MB = new TwoBits(3); readUser.OpSpecID = 5; readUser.WordCount = 32; readUser.WordPointer = 0; accessCmd.AccessCommandOpSpec.Add(readUser); break; case 3: PARAM_ImpinjGetQTConfig getQT = new PARAM_ImpinjGetQTConfig(); getQT.OpSpecID = 6; getQT.AccessPassword = m_password; accessCmd.AccessCommandOpSpec.Add(getQT); break; case 4: PARAM_ImpinjSetQTConfig setQTPrivate = new PARAM_ImpinjSetQTConfig(); setQTPrivate.OpSpecID = 7; setQTPrivate.AccessPassword = m_password; setQTPrivate.Persistence = ENUM_ImpinjQTPersistence.Permanent; setQTPrivate.DataProfile = ENUM_ImpinjQTDataProfile.Private; setQTPrivate.AccessRange = m_shortRange; accessCmd.AccessCommandOpSpec.Add(setQTPrivate); break; case 5: PARAM_ImpinjSetQTConfig setQTPublic = new PARAM_ImpinjSetQTConfig(); setQTPublic.OpSpecID = 8; setQTPublic.AccessPassword = m_password; setQTPublic.Persistence = ENUM_ImpinjQTPersistence.Permanent; setQTPublic.DataProfile = ENUM_ImpinjQTDataProfile.Public; setQTPublic.AccessRange = m_shortRange; accessCmd.AccessCommandOpSpec.Add(setQTPublic); break; case 6: PARAM_ImpinjSetQTConfig setQTPeek = new PARAM_ImpinjSetQTConfig(); setQTPeek.OpSpecID = 9; setQTPeek.AccessPassword = m_password; setQTPeek.Persistence = ENUM_ImpinjQTPersistence.Temporary; setQTPeek.DataProfile = ENUM_ImpinjQTDataProfile.Private; setQTPeek.AccessRange = ENUM_ImpinjQTAccessRange.Normal_Range; accessCmd.AccessCommandOpSpec.Add(setQTPeek); PARAM_C1G2Read readSerializedTIDPeek = new PARAM_C1G2Read(); readSerializedTIDPeek.AccessPassword = 0; readSerializedTIDPeek.MB = new TwoBits(2); readSerializedTIDPeek.OpSpecID = 10; readSerializedTIDPeek.WordCount = 6; readSerializedTIDPeek.WordPointer = 0; accessCmd.AccessCommandOpSpec.Add(readSerializedTIDPeek); PARAM_C1G2Read readPrivateEPC = new PARAM_C1G2Read(); readPrivateEPC.AccessPassword = 0; readPrivateEPC.MB = new TwoBits(1); readPrivateEPC.OpSpecID = 11; readPrivateEPC.WordCount = 8; readPrivateEPC.WordPointer = 2; accessCmd.AccessCommandOpSpec.Add(readPrivateEPC); PARAM_C1G2Read readUserPeek = new PARAM_C1G2Read(); readUserPeek.AccessPassword = 0; readUserPeek.MB = new TwoBits(3); readUserPeek.OpSpecID = 12; readUserPeek.WordCount = 32; readUserPeek.WordPointer = 0; accessCmd.AccessCommandOpSpec.Add(readUserPeek); break; case 7: PARAM_C1G2Write writeUser = new PARAM_C1G2Write(); writeUser.AccessPassword = m_password; writeUser.OpSpecID = 13; writeUser.WordPointer = 0; writeUser.MB = new TwoBits(3); writeUser.WriteData = new UInt16Array(); for (int x = 0; x < 32; x++) { writeUser.WriteData.Add((UInt16)m_random.Next(65536)); } accessCmd.AccessCommandOpSpec.Add(writeUser); break; case 8: PARAM_C1G2Write writePubEPC = new PARAM_C1G2Write(); writePubEPC.AccessPassword = m_password; writePubEPC.MB = new TwoBits(2); writePubEPC.OpSpecID = 14; writePubEPC.WordPointer = 6; writePubEPC.WriteData = new UInt16Array(); for (int x = 0; x < 6; x++) { writePubEPC.WriteData.Add((UInt16)m_random.Next(65536)); } accessCmd.AccessCommandOpSpec.Add(writePubEPC); break; case 9: PARAM_C1G2Read readRsvd = new PARAM_C1G2Read(); readRsvd.AccessPassword = m_password; readRsvd.MB = new TwoBits(0); readRsvd.OpSpecID = 15; readRsvd.WordCount = 4; readRsvd.WordPointer = 0; accessCmd.AccessCommandOpSpec.Add(readRsvd); break; } // create the stop trigger for the Access Spec PARAM_AccessSpecStopTrigger stop = new PARAM_AccessSpecStopTrigger(); stop.AccessSpecStopTrigger = ENUM_AccessSpecStopTriggerType.Null; stop.OperationCountValue = 0; // Create and set up the basic accessSpec PARAM_AccessSpec accessSpec = new PARAM_AccessSpec(); accessSpec.AccessSpecID = 24; accessSpec.AntennaID = 0; accessSpec.ROSpecID = 0; accessSpec.CurrentState = ENUM_AccessSpecState.Disabled; accessSpec.ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2; // add the access command and stop trigger to the accessSpec accessSpec.AccessCommand = accessCmd; accessSpec.AccessSpecStopTrigger = stop; // Add the Access Spec to the ADD_ACCESSSPEC message MSG_ADD_ACCESSSPEC addAccess = new MSG_ADD_ACCESSSPEC(); addAccess.MSG_ID = msgID++; addAccess.AccessSpec = accessSpec; // communicate the message to the reader MSG_ERROR_MESSAGE msg_err; MSG_ADD_ACCESSSPEC_RESPONSE rsp = reader.ADD_ACCESSSPEC(addAccess, 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_ACCESSSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region EnableAccessSpec { Console.WriteLine("Enabling AccessSpec\n"); MSG_ENABLE_ACCESSSPEC msg = new MSG_ENABLE_ACCESSSPEC(); msg.MSG_ID = msgID++; MSG_ERROR_MESSAGE msg_err; msg.AccessSpecID = 24; // this better match the ACCESSSPEC we created above MSG_ENABLE_ACCESSSPEC_RESPONSE rsp = reader.ENABLE_ACCESSSPEC(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_ACCESSSPEC Command Timed out\n"); reader.Close(); return; } } #endregion #region EnableRoSpec { Console.WriteLine("Enabling RoSpec\n"); MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC(); msg.MSG_ID = msgID++; 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.MSG_ID = msgID++; 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 // this should be plenty long enough to do these commands Thread.Sleep(3000); #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 = msgID++;; // note 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 " + opSpecCount + " OpSpec Results."); 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); }