Connecting to an RFID Reader \ Pixie module
This is the first step to talk to an RFID Reader\Pixie module over the Generic Reader Interface. The root class for the rfidApi is RFIDReader. It is possible to use the API to connect to RFID Reader while is acting as LLRP Server as well as LLRP Client.
RFID Reader acts in LLRP Server Mode - The RFIDReader class instance takes host name or IP address of the RFID-reader to connect, the port number and the response timeout. The default LLRP port number is 5084 and the default response time out is 5 seconds. Specifying zero for port number and timeout uses default values.
For Host-based readers, hostname shall be the IP address of the RFID Reader.
// Establish connection to the RFID Reader
string hostname = "157.235.208.20";
RFIDReader rfidApi = new RFIDReader(hostname, 0, 0);
rfidApi.Connect();
RFID Reader acts in LLRP Client Mode – The .NET Application can create a socket and wait for connection from the connection request from Reader as shown beneath. This can be done from the Reader’s web-console or using the RM method InitiateFromReader.
Socket m_ListeningSocket = null;
Socket m_AcceptedSocket = null;
m_ListeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint iplocal = new IPEndPoint(IPAddress.Any, 5084);
m_ListeningSocket.Bind(iplocal);
m_ListeningSocket.Listen(1);
// Initiate LLRP Connection from the RM interface
m_ReaderSocket = m_ListeningSocket.Accept();
rfidApi.AcceptConnection(m_ReaderSocket);
The timeout value is also used for configuring the Keep-Alive mechanism which helps in determining if the connection to the reader is alive or not. If the connection to the reader was inactive (i.e. no keep-alive message from the Reader) for a time greater than 10 times the timeout, DISCONNECTION_EVENT will be triggered to the application if the application has registered for the same.
Secured Connection
Secure LLRP mode allows encrypted and optionally authenticated connection to use LLRP service on the reader using SSL/TLS. Please refer “Configure LLRP Settings” and “Certificates” chapter in Reader Integrator Guide for configuring reader in Secure LLRP mode.
RFID API3 can internally manage secure connection to LLRP service and clients using RFID API3 can enable secure connection by setting options in SecureConnectionInfo property of RFIDReader object (or LLRPConnectionConfig.SecureModeConfig in case of server mode) before calling Connect or AcceptConnection method (in case of Reader configured in LLRP client mode)
Please refer Reader Integrator Guide for documentation on generation of certificates for reader as well as client use. The example below illustrates use of SecureConnectionInfo property to establish a secure to connection to a reader which is configured to operate in Secure LLRP mode.
// Establish secure connection to the RFID Reader
string hostname = "157.235.208.20";
RFIDReader rfidApi = new RFIDReader(hostname, 0, 0);
// Secure Connection to the reader
SecureConnectionInfo secureLLRPConnection = new SecureConnectionInfo();
secureLLRPConnection.SecureMode = true;
secureLLRPConnection.ValidatePeerCert = false;
secureLLRPConnection.ClientCertBuff = System.IO.File.ReadAllText(@"C:\myCertificates\client_crt.pem");
secureLLRPConnection.ClientKeyBuff = System.IO.File.ReadAllText(@"C:\myCertificates\client_key.pem");
secureLLRPConnection.PhraseBuff = "abcd12345";
secureLLRPConnection.RootCertBuff = System.IO.File.ReadAllText(@"C:\myCertificates\cacert.crt");
rfidApi.SecureConnectionInfo = secureLLRPConnection;
rfidApi.Connect();
Connect to a PIXIE module using comport - The RFIDReader class instance takes comport and baudrate to connect to a Pixie module.
User can discover all the available comports.
// Discover all the available comports
const int BAUDRATE = 921600;
List<string> COMPorts = RFIDReader.GetAvailableCOMPorts(BAUDRATE);
Console.WriteLine("Available COMP Ports:");
if (COMPorts != null)
{
foreach (var com in COMPorts)
{
Console.WriteLine(com);
}
}
else
{
Console.WriteLine("No Comports are available.\n");
}
// Establish connection to the Pixie Module
string comport = "COM1";
int baudrate = 921600;
RFIDReader rfidApi = new RFIDReader(comport, baudrate);
rfidApi.Connect();