Class RFIDReaderComm

java.lang.Object
RFIDReaderComm.RFIDReaderComm

public class RFIDReaderComm
extends java.lang.Object

Appendix C

Low-Level Communications DLL Interface Guide

Class:
public class SensorConnection
Summary:
This class encapsulates the low-level communications interface with the sensor. In addition to providing setup, resetting, and teardown of the TCP socket used to communicate with the sensor, it also packages up the binary protocol that is used in that communication.
Comments:
A detailed description of how this class is used is provided in the "SensArray Programmers Guide".
This class implements an on-demand approach to opening the TCP socket to establish communication the sensor. Consequently, you will not find explicit Connect() or Disconnect() methods. You simply set up the IP address and port number for the socket, then call any of the SendMessage() methods. If the socket has never been opened, or was closed (due to a lost link, for example) the socket will be reopened. Once the application has finished communicating with the sensor, call Shutdown(), which closes the socket and dispose of the object.
It is possible, however, to reuse this class by simply reinitializing it with a new set of IP address/port number values. If these are different from what was previously set up, the existing connection is closed, and a new one is automatically reestablished using these new values.
This class packages up the various commands sent to the sensor to simplify the work that needs to be done at the application level. This packaging includes providing the correct set of header and trailer bytes, providing the correct message length, inserting the command code and data bytes, and finally calculating the checksum for the command. This packaged byte sequence is then sent to the sensor and waits for a response.
The received data is also processed. The header and trailer bytes are verified, the response code is matched against the command code and the checksum is validated before the data length is and the data byte stream are extracted and returned to the caller. If any of these checks fails an Exception is thrown.
One additional comment in order. The RFID reader hardware is a standalone module embedded in the sensor. As a consequence, there are two primary subsystems within the sensor that process commands. One handles the networking and top-level device management commands. The second handles the RFID protocol and reader type commands. At the binary protocol level, these commands are distinguished by having different header bytes. (Other than a different pair of header bytes, the command structures are identical.) The commands sent by the methods of this class need to be able to distinguish between these two subsystems. This is done through the ReaderSubsystem enumeration. This enumeration has two values:
  • ReaderSubsystem.RFID_Controller for commands targeted to the high-level controller (header bytes 0xB9/0x9B),
  • And, ReaderSubsystem.RFID_Module for commands handled by the internal reader module (header bytes 0xA5/0x5A).

Specific details of the commands that are handled by the high-level controller are documented in "SensArray Communications Protocol". The specifics of the RF module's binary protocol are documented in "ALR-M UHF RFID Module Hardware Guide".
Author:
SensThys
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  RFIDReaderComm.RFIDReaderSubsystem  
  • Field Summary

    Fields 
    Modifier and Type Field Description
    java.lang.Boolean clearedToSend  
    int ConnectTimeout  
    int ReceiveTimeout  
  • Constructor Summary

    Constructors 
    Constructor Description
    RFIDReaderComm​(java.lang.String sIpAddress, int iPort)
    Method: RFIDReadercomm(String sIpAddress, int iPort) Summary: Create an instance of the RFIDReaderComm class initialized with the sIpAddress and port number passed in.
  • Method Summary

    Modifier and Type Method Description
    int DoReceive​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte altMessageId)
    Method int DoReceive(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte altMessageId) Summary Wait for formatted binary protocol data replies to be sent from the sensor.
    int DoSendReceive​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] messageData, int dataLength)  
    static int getInfiniteTimeout()  
    int SendMessage​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId)
    Method: int SendMessage(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId) Summary This is a 4 parameter overload of the SendMessage method as documented above where no data needs to be sent to the module (typically a get command)
    int SendMessage​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] sendBuffer, int sendBufferLength)
    Method: int SendMessage(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId) Summary: Send a message to the sensor expecting to receive a response.
    void SendMessageNoReply​(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId)
    Methods void SendMessageNoReply(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId) Summary Send a message to the sensor without expecting a reply.
    void SendMessageNoReply​(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] sendBuffer, int sendBufferLength)
    Methods void SendMessageNoReply(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] messageData, int dataLength) Summary Send a message to the sensor without expecting a reply.
    void SetIPv4CommLink​(java.lang.String sIPv4Address, int portNumber)
    Method: void SetIPv4CommLink(String sIPv4Address, int portNumber) Summary: This method is used after the class has been created to change the IP address or the port number that the class will used to set up the TCP socket.
    void SetIPv6Address​(java.lang.String sIPv6Address)  
    void Shutdown()
    Method: void Shutdown(): Summary: Close and dispose of the underlying TCP socket Exceptions: A System.TimeoutException will be thrown if the socket disconnect process doesn't complete within the disconnect timeout period.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RFIDReaderComm

      public RFIDReaderComm​(java.lang.String sIpAddress, int iPort)
      Method:
      RFIDReadercomm(String sIpAddress, int iPort)
      Summary:
      Create an instance of the RFIDReaderComm class initialized with the sIpAddress and port number passed in.
      Parameters:
      sIpAddress - Input parameter specifying the sIpAddress that will be used to open the socket for communicating with the sensor.
      iPort - Input parameter specifying the TCP port number used when opening the socket for communicating with the sensor.
  • Method Details

    • SetIPv4CommLink

      public void SetIPv4CommLink​(java.lang.String sIPv4Address, int portNumber)
      Method:
      void SetIPv4CommLink(String sIPv4Address, int portNumber)
      Summary:
      This method is used after the class has been created to change the IP address or the port number that the class will used to set up the TCP socket.
      Parameters:
      sIPv4Address - Input parameter specifying the new IP address to assign to this communication channel. This must be in the standard dotted notation, e.g., 192.168.1.150.
      portNumber - Input parameter specifying the new TCP port number to be used when opening up the socket to communicate with the sensor.
      Return:
      This method does not return a value.
      Exceptions:
      A System.FormatException will be thrown if the IP Address string is not a valid dot notation IP Address
      Comments:
      One side-effect of calling this method will be to close the existing socket and setup to reopen the socket if either the IP address or the port number change from what is currently set.
    • SetIPv6Address

      public void SetIPv6Address​(java.lang.String sIPv6Address)
    • Shutdown

      public void Shutdown()
      Method:
      void Shutdown():
      Summary:
      Close and dispose of the underlying TCP socket
      Exceptions:
      A System.TimeoutException will be thrown if the socket disconnect process doesn't complete within the disconnect timeout period.
    • SendMessage

      public int SendMessage​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId) throws java.lang.Exception
      Method:
      int SendMessage(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId)
      Summary
      This is a 4 parameter overload of the SendMessage method as documented above where no data needs to be sent to the module (typically a get command)
      Parameters:
      responseBuffer - Output parameter providing a buffer for the response data in the reply to the message to be returned to the calling code.
      maxResponseLength - Input specifying the maximum number of bytes to be returned in the reply. This should be less than or equal to the number of elements in the ResponseBuffer array
      moduleType - Input parameter which specifies the subsystem that will be handing the command. The ReaderSubsystem usage is described in the Additional Information section of the class overview.
      messageId - Input parameter which specifies the command that is to be sent to the sensor.
      Returns:
      an int value is returned with the length of the data content of the response.
      Throws:
      java.lang.Exception - A System.TimeoutException will be thrown if the connection to the sensor cannot be established or the module doesn't respond.
    • SendMessage

      public int SendMessage​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] sendBuffer, int sendBufferLength) throws java.lang.Exception
      Method:
      int SendMessage(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId)
      Summary:
      Send a message to the sensor expecting to receive a response. The ResponseBuffer parameter will contain any data content returned from the sensor. The specific message ids and the data content of the sent messages are received replies are documented in the Additional Information section of the top-level class description above.
      Parameters:
      responseBuffer - Output parameter providing a buffer for the response data in the reply to the message to be returned to the calling code.
      maxResponseLength - Input specifying the maximum number of bytes to be returned in the reply. This should be less than or equal to the number of elements in the ResponseBuffer array
      moduleType - Input parameter which specifies the subsystem that will be handing the command. The ReaderSubsystem usage is described in the Additional Information section of the class overview.
      messageId - Input parameter which specifies the command that is to be sent to the sensor.
      sendBuffer - Optional Input array comprising the data content of the message to be sent to the sensor. If there is no data content in the outgoing message, this can be eliminated from the method call.
      sendBufferLength - Optional Input specifying the number of bytes in the outgoing message data. If there is no data content to the message, this parameter can be eliminated from the call.
      Returns:
      an int value is returned with the length of the data content of the response.
      Throws:
      java.lang.Exception - A System.TimeoutException will be thrown if the connection to the sensor cannot be established or the module doesn't respond.
      Comments
      The actual binary data stream that is sent to the sensor includes header and trailer bytes, the message length and a checksum along with the command code and data. Similarly on return, the response has a similar structure. This method packages this information appropriately and extracts the returned data removing the need to perform these operations from the application level code.
    • DoSendReceive

      public int DoSendReceive​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] messageData, int dataLength) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • SendMessageNoReply

      public void SendMessageNoReply​(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId) throws java.lang.Exception
      Methods
      void SendMessageNoReply(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId)
      Summary
      Send a message to the sensor without expecting a reply.
      Parameters:
      moduleType - Input parameter which specifies the subsystem that will be handing the command. The ReaderSubsystem usage is described in the Additional Information section of the class overview.
      messageId - Input parameter which specifies the command that is to be sent to the sensor.
      Throws:
      java.lang.Exception - A System.TimeoutException will be thrown if the connection to the sensor cannot be established or the module doesn't respond.
      Comments
      There are only a handful of commands where this method is appropriate. These include rebooting the device and starting a continuous read cycle.
    • SendMessageNoReply

      public void SendMessageNoReply​(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] sendBuffer, int sendBufferLength) throws java.lang.Exception
      Methods
      void SendMessageNoReply(RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte[] messageData, int dataLength)
      Summary
      Send a message to the sensor without expecting a reply.
      Parameters:
      moduleType - Input parameter which specifies the subsystem that will be handing the command. The ReaderSubsystem usage is described in the Additional Information section of the class overview.
      messageId - Input parameter which specifies the command that is to be sent to the sensor.
      sendBuffer - Optional Input array comprising the data content of the message to be sent to the sensor. If there is no data content in the outgoing message, this can be eliminated from the method call.
      sendBufferLength - Optional Input specifying the number of bytes in the outgoing message data. If there is no data content to the message, this parameter can be eliminated from the call.
      Throws:
      java.lang.Exception - A System.TimeoutException will be thrown if the connection to the sensor cannot be established or the module doesn't respond.
      Comments
      There are only a handful of commands where this method is appropriate. These include rebooting the device and starting a continuous read cycle.
    • DoReceive

      public int DoReceive​(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte altMessageId) throws java.lang.Exception
      Method
      int DoReceive(byte[] responseBuffer, int maxResponseLength, RFIDReaderComm.RFIDReaderSubsystem moduleType, byte messageId, byte altMessageId)
      Summary
      Wait for formatted binary protocol data replies to be sent from the sensor. Return the resulting data when a complete message reply has been received.
      Parameters:
      responseBuffer - Input parameter containing the data returned from the sensor.
      maxResponseLength - integer setting the maximum acceptable response length.
      moduleType - Input parameter which specifies the subsystem that will be handing the command. The ReaderSubsystem usage is described in the Additional Information section of the class overview.
      messageId - Input parameter passing in the id corresponding to the outgoing message that corresponds to the expected reply.
      altMessageId - Optional Input parameter passing in the id corresponding to a second message type that might occur while receiving data. If this parameter is left out of call, this method will only return messages corresponding to the primary id set by the MessageId parameter. Other responses will throw an exception. The primary use of this parameter is described in the Additional Information section.
      Returns:
      int value is returned with the length of the data content of the response.
      Throws:
      java.lang.Exception - A System.TimeoutException will be thrown if the connection to the sensor cannot be established or the module doesn't respond.
      Comments
      The primary use for this method is to listen for tag data replies during continuous tag inventory read cycles. The read cycle is initiated by issuing a Start Continuous Inventory command. Tag data is read by receiving tag data in a continuous loop by calling DoReceive(). When the application is ready to stop the continuous inventory cycle, a Stop Continuous Inventory command is issued while continuing to monitor responses using DoReceive() with the primary MessageId being the one for tag reads and the alternative message id (MessageIdAlt) being the one for the Stop Continuous Inventory command.
      Note that in this situation, both the Start Continuous Inventory command and the Stop Continuous Inventory command would be sent using the SendMessageNoReply() method.
    • getInfiniteTimeout

      public static int getInfiniteTimeout()