C# Example – Nova Antenna Muxing and Select Tag Looping Documentation Category

This page contains documentation, downloads, firmware, and support materials for this product or topic.

Choose a different product/topic



More Info

SkyeTek Nova API Example: Antenna Muxing & Tag Selecting

An Introduction into System Parameters and Tag Selecting with the C# SkyTek API

Note: As of July 2016 we will be moving forward with updating our C# wrapper. This page will remain up for historical reference, however we will not be offering any further support on this method. Please refer to our open-source repository at https://www.jadaktech.com/documentation/rfid/software-and-api/ for the latest releases.

In this example, we will be demonstrating how to read and write system parameters to control our output antenna, as well as how to Select a Tag in a loop. Before we go any further, please know this code is for educational use only, and carries no warranty if used directly on your own modules. Please be sure your Nova module is working correctly and responding to SkyWare over RS-232 (Serial Port) before running this code. 

First, we need a way to talk to the Nova

SerialDevice outputDevice = new SerialDevice();
outputDevice.Address = “COM3”;
outputDevice.BaudRate = 38400;

Here, we are declaring that we will use the serial port at COM3 for our Nova and run at a baud rate of the default 38400. Check your individual system configuration to figure out which serial port you use.

Next, Swap the Ports

Don’t worry. While it looks like a big function, It’s actually just sending and receiving a command 3 separate times. Each command needs to be ‘built’ with the SkyeTek API before it’s ‘issued’ to the reader. The first chunk of code verifies the Serial Port it was provided can be opened and used, while the rest of the code handles the reading and writing of the Antenna Port System Parameter. This code would be called in your main function to grab the new port to write to.

private static int SwapPorts(SerialDevice outputSerialDevice)
{

// Check if serial device is available
if (!outputSerialDevice.IsOpen)
{
try
{
outputSerialDevice.Open();
}
catch
{
Console.Out.WriteLine(“Could not open Serial Device: ” + outputSerialDevice.Address + “. Check output port and availability.”);
return -1;
}
Console.Out.WriteLine(“Opened Serial Device: ” + outputSerialDevice.Address);
}

// Serial Device should be open here, so we need to send a command to read System Parameter 0x000A
// Declare the request and response objects
STPv3Request _request;
STPv3Response _response;

// Build the read request
_request = new STPv3Request();
_request.Command = STPv3Commands.READ_SYSTEM_PARAMETER;
_request.Address = 0x00A;
_request.Blocks = 1;

// Issue the request to the output device
_request.Issue(outputSerialDevice);
_response = _request.GetResponse();

// Grab the response from the request object after it’s been issued
// NOTE: The Nova will be unresponsive if it’s waiting for the host to read back a response (you’ll see a holding green LED in this case)
int oldPort;
if (_response == null || !_response.Success)
{
Console.Out.WriteLine(“Could not get response from Nova on ” + outputSerialDevice.Address);
return -1;
}
else
{
oldPort = _response.Data[0];
Console.Out.WriteLine(“Old Active Port: ” + oldPort);
}

// Build the write request
_request = new STPv3Request();
_request.Command = STPv3Commands.WRITE_SYSTEM_PARAMETER;
_request.Address = 0x00A;
_request.Blocks = 1;
byte _newValue = (byte)(oldPort ^ 0x01);
_request.Data = new byte[1];
_request.Data[0] = _newValue;

// Issue the request to the output device
_request.Issue(outputSerialDevice);
_response = _request.GetResponse();

// Grab the response from the request object after it’s been issued
// NOTE: The Nova will be unresponsive if it’s waiting for the host to read back a response (you’ll see a holding green LED in this case)
if (_response == null || !_response.Success)
{
Console.Out.WriteLine(“Could not get response from Nova on ” + outputSerialDevice.Address);
return -1;
}

// Build the new read request
_request = new STPv3Request();
_request.Command = STPv3Commands.READ_SYSTEM_PARAMETER;
_request.Address = 0x00A;
_request.Blocks = 1;

// Issue the request to the output device
_request.Issue(outputSerialDevice);
_response = _request.GetResponse();

// Grab the response from the request object after it’s been issued
// NOTE: The Nova will be unresponsive if it’s waiting for the host to read back a response (you’ll see a holding green LED in this case)
int newPort;
if (_response == null || !_response.Success)
{
Console.Out.WriteLine(“Could not get response from Nova on ” + outputSerialDevice.Address);
return -1;
}
else
{
newPort = _response.Data[0];
Console.Out.WriteLine(“New Active Port: ” + newPort);
}

// Return the new port to the calling function
return newPort;

}

Finally, Select some Tags

This part of the code is run in the main loop to call the SelectTag function we will build below. It calls this function 5 times and outputs the results on each run.

// Run Select Tag Loop
Console.Out.WriteLine(“Connect Antenna to correct port and press Enter to Scan.”);
Console.In.ReadLine();
int i = 0;
while (i <= 5)
{
byte[] _tagId = SelectTag(outputDevice);
System.Threading.Thread.Sleep(333);

if (_tagId.Length > 0)
{
Console.Out.WriteLine(“Found: ” + BitConverter.ToString(_tagId));
}
else
{
Console.Out.WriteLine(“Found: none”);
}
i++;
}

This is the definition of our SelectTag function. Like the System Parameter API calls above, we also need to build our SelectTag command too. Unlike the above command though, any Tag-based operation will require the use of a ‘SkyeTek.Tags.Tag’ object placed inside the request as well. An example of this can be seen below with the ‘_tag’ variable.

private static byte[] SelectTag(SerialDevice outputDevice)
{
// Declare the request and response
STPv3Request _request;
STPv3Response _response;

// Create the Tag object to Select
Tag _tag = new Tag();
_tag.Type = TagType.AUTO_DETECT;

// Build the SelectTag request
_request = new STPv3Request();
_request.Command = STPv3Commands.SELECT_TAG;
_request.Tag = _tag;

// Issue the request to the output device
_request.Issue(outputDevice);
_response = _request.GetResponse();

// Grab the response from the request object after it’s been issued
if (_response == null || !_response.Success)
{
//Console.Out.WriteLine(“No Tag Found”);
return new byte[0];
}
else
{
return _response.TID;
}

}

With all these pieces, you should now be able to modify the Nova reader’s System Parameters, as well as successfully Select Tags in your readers range. If you’re having trouble communicating and debugging, the best source of info will be looking at the binary command raw inside VS while your execution is paused. The object explorer will provide any info on SkyeTek API exceptions that may indicate you might have mis-set some option. Using the SkyeWare software is also invaluable for comparing what a command should look like going to your reader. For more help, please don’t hesitate to read our API guides or contact support!

Program.cs






← Return to Documentation Search