Command Line Client
This section explains how to implement the Example Entry/Exit Recipes in a command line client.
The following screenshot shows the command line application running. It reads an IP address and port number from the command line, and listens for connections at that IP/port combination.
The reader connects to the listening program and communicates the entry/exit protocol to it. The program only prints out a report for each protocol event it receives.
In this example, the program was started before the recipe 0/0 was defined. When the reader connected, it sent a session start event and then an entry event for the two tags in recipe 1/0. Then recipe 0/0 was created, and the reader 00:11:CE:01:0A:66 was added to it.
When a reader's set of recipes changes, it disconnects all its current devices and starts new sessions, and this is what we see in the trace; 0/0 initially has the same ranges as 1/0, so it has the same tags in it. After this, while 0/0 is being tuned, its angle ranges are changed and some tags leave and enter it again. These events are therefore raised in the program and printed out.
The code to implement this program has only a few lines (in Program.cs).
The main program:
- Reads and parses the IP address and port number from the command line.
- Creates a protocol object and adds event handlers to it.
- Uses the protocol object to create a server, and then runs the server.

#region Main program static void Main(string[] args) { // Read a valid address and port from the command line IPAddress address = null; ushort port = 0; bool valid_arguments = (args.Length == 2); valid_arguments &= IPAddress.TryParse(args[0], out address); valid_arguments &= ushort.TryParse(args[1], out port); if (!valid_arguments) { System.Console.WriteLine("Failed to parse address / port from command line"); return; } // Create a protocol object EntryExitProtocol protocol = new EntryExitProtocol(); // Add protocol event handlers protocol.OnEntry += new EntryExitProtocol.ProtocolEntryOrExitHandler(protocol_OnEntry); protocol.OnExit += new EntryExitProtocol.ProtocolEntryOrExitHandler(protocol_OnExit); protocol.OnSessionStart += new EntryExitProtocol.ProtocolEventHandler(protocol_OnSessionStart); protocol.OnSessionStop += new EntryExitProtocol.ProtocolEventHandler(protocol_OnSessionStop); // Create a server EntryExitServer server = new EntryExitServer(address, port, protocol); // Run the server server.Start(); // Wait forever while (true) System.Threading.Thread.Sleep(1000); } #endregion
The event handlers just print a message when each protocol event occurs.

#region Event handlers static void protocol_OnEntry(ushort id1, ushort id2, List<ulong> tags) { System.Console.WriteLine("Entry " + id1.ToString() + "/" + id2.ToString() + ": " + tags.Count + " tag" + (tags.Count > 1 ? "s" : "")); foreach (var tag in tags) System.Console.WriteLine(" {0:X}", tag); } static void protocol_OnExit(ushort id1, ushort id2, List<ulong> tags) { System.Console.WriteLine("Exit " + id1.ToString() + "/" + id2.ToString() + ": " + tags.Count + " tag" + (tags.Count > 1 ? "s" : "")); foreach (var tag in tags) System.Console.WriteLine(" {0:X}", tag); } static void protocol_OnSessionStart() { System.Console.WriteLine("Session start"); } static void protocol_OnSessionStop() { System.Console.WriteLine("Session stop"); } #endregion
|