Hello,
Please forgive me if this is not the proper forum for such questions, but I
have recently had responsibility for a .NET application assigned to me. I am a
longtime user of LTK-Java with good success, however, I am fairly new to .NET
and this version has me stumped. After connecting to the reader, I add a
callback to the client's OnRoAccessReportReceived property (after connecting,
setting config, and adding and enabling a ROSpec). I can send messages to the
reader just fine, and I have a Wireshark trace that shows that I do get a
RO_ACCESS_REPORT back after the reader has finished. However, my callback is
not invoked. I'm using C# on .NET 4 in Windows 7. What am I misunderstanding?
Here's the source (Please excuse any poor formatting):
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices;
using System.Threading;
using System.IO;
using Org.LLRP.LTK.LLRPV1;
using LTKD = Org.LLRP.LTK.LLRPV1.DataType;
namespace ReaderDemo
{
class Reader
{
private LLRPClient _llrpClient = null;
private MSG_ERROR_MESSAGE msg_err;
private string readerIP;
static void Main(string[] args)
{
string readerIP = "172.30.0.9";
if (args.Length > 0)
{
readerIP = args[0];
}
int port = 5084;
if (args.Length > 1)
{
port = Int32.Parse(args[1]);
}
Reader r = new Reader(readerIP, port);
r.Start();
}
public Reader(string readerIP, int port)
{
this.readerIP = readerIP;
_llrpClient = new LLRPClient(port);
}
public void Start()
{
ENUM_ConnectionAttemptStatusType status;
bool isConnected = _llrpClient.Open(readerIP, 5000, out status);
if (isConnected && status ==
ENUM_ConnectionAttemptStatusType.Success)
{
SetReaderConfig();
AddRoSpec();
EnableRoSpec();
_llrpClient.OnRoAccessReportReceived += new
delegateRoAccessReport(showROAccessReport);
}
Console.WriteLine("To quit, type \"q\" and enter. To perform a
4-second read and dump the XML to the console, type \"r\".");
string cmd = "r";
while ("q" != cmd)
{
StartROSpec();
cmd = Console.ReadLine();
}
_llrpClient.OnRoAccessReportReceived -= new
delegateRoAccessReport(showROAccessReport);
DeleteRoSpecAll();
_llrpClient.Close();
}
void reader_OnRoAccessReportReceived(MSG_RO_ACCESS_REPORT msg)
{
delegateRoAccessReport del = new
delegateRoAccessReport(showROAccessReport);
del.Invoke(msg);
}
void showROAccessReport(MSG_RO_ACCESS_REPORT msg)
{
Console.WriteLine(msg.ToString());
}
public MSG_ADD_ROSPEC_RESPONSE AddRoSpec()
{
MSG_ADD_ROSPEC_RESPONSE result = null;
MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC();
msg.ROSpec = new PARAM_ROSpec();
msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled;
msg.ROSpec.ROSpecID = 1;
msg.ROSpec.Priority = 0x00;
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 =
4000;
msg.ROSpec.SpecParameter = new UNION_SpecParameter();
PARAM_AISpec aiSpec = new PARAM_AISpec();
aiSpec.AntennaIDs = new LTKD.UInt16Array();
aiSpec.AntennaIDs.Add(0);
aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger();
aiSpec.AISpecStopTrigger.AISpecStopTriggerType =
ENUM_AISpecStopTriggerType.Null;
aiSpec.AISpecStopTrigger.DurationTrigger = 0;
aiSpec.InventoryParameterSpec = new PARAM_InventoryParameterSpec[1];
aiSpec.InventoryParameterSpec[0] = new
PARAM_InventoryParameterSpec();
aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 2;
aiSpec.InventoryParameterSpec[0].ProtocolID =
ENUM_AirProtocols.EPCGlobalClass1Gen2;
msg.ROSpec.SpecParameter.Add(aiSpec);
result = _llrpClient.ADD_ROSPEC(msg, out msg_err, 3000);
return result;
}
private MSG_DELETE_ROSPEC_RESPONSE DeleteRoSpecAll()
{
MSG_DELETE_ROSPEC_RESPONSE result;
MSG_DELETE_ROSPEC msg = new MSG_DELETE_ROSPEC();
msg.ROSpecID = 0;
result = _llrpClient.DELETE_ROSPEC(msg, out msg_err, 3000);
return result;
}
private MSG_ENABLE_ROSPEC_RESPONSE EnableRoSpec()
{
MSG_ENABLE_ROSPEC_RESPONSE result;
MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC();
msg.ROSpecID = 1;
result = _llrpClient.ENABLE_ROSPEC(msg, out msg_err, 3000);
return result;
}
private MSG_START_ROSPEC_RESPONSE StartROSpec()
{
MSG_START_ROSPEC_RESPONSE result;
MSG_START_ROSPEC msg = new MSG_START_ROSPEC();
msg.ROSpecID = 1;
result = _llrpClient.START_ROSPEC(msg, out msg_err, 3000);
return result;
}
private MSG_SET_READER_CONFIG_RESPONSE SetReaderConfig()
{
MSG_SET_READER_CONFIG_RESPONSE result;
MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();
msg.ResetToFactoryDefault = true;
SetROReportSpec(ref msg);
result = _llrpClient.SET_READER_CONFIG(msg, out msg_err, 3000);
return result;
}
private void SetROReportSpec(ref MSG_SET_READER_CONFIG msg)
{
msg.ROReportSpec = new PARAM_ROReportSpec();
msg.ROReportSpec.N = 0;
msg.ROReportSpec.ROReportTrigger =
ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;
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 = true;
msg.ROReportSpec.TagReportContentSelector.EnableROSpecID = false;
msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex = false;
msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true;
}
}
}
--Jeffrey Haugsness, Developer
[email protected]
jhaugsne | google talk
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
llrp-toolkit-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/llrp-toolkit-devel