Introduction
JDeviceLink is a TCP socket client library written in Java designed for simple communication to devices that will automatically manage connect/reconnect. Devices typically refers to embedded devices that provide an Ethernet (TCP) or RS-232/422 interface such as sensors, digital/analog modules, relay controllers, displays, etc.
Communication Overview
Device communications typically consist of small amounts of data being communicated. The device may provide an embedded server. The device may provide no more than a serial (RS-232/422) interface and a serial to ethernet converter with embedded server built in. Communication with the device may consist of a continuous send, continuous receive, a polling mode, or some combination of.
Example – Continuous send
A sensor may have the capability to continually transmit measurement data. An application needs to continually read this data. If the sensor runs on battery, or communications is intermittent wireless, communication disruption may occur. The application need only display a warning message, and wait for the link to reestablish.
Example – Continuous receive
A display device may need a continuous update of display data (such as sensor data) or the display defaults to an error message. The device is simple and does not respond in any way.
Example – Polling mode
A relay controller designed to flip a relay on command and respond with a confirmation command.
In any of these examples adding extra intelligence to determine device link and availability may be difficult due to device design and installation requirements, or just plain overkill.
Serial vs. TCP
Many of the devices targeted by this library support an RS-232/422 serial interface. Standard Java does not include support for serial communications. However there are additional libraries to make this a simple task such as the Java Communications API, or of coarse RXTX, not to mention several others. These types of libraries provide a standard java interface and a JNI library for supported platforms.
In a serial link (RS-232/422), if the cable is disconnected, the Java serial port object is typically unaffected. However in TCP socket client, if a cable is unplugged for a length of time, the Socket object becomes unusable and must be closed and re-opened before communication can continue. This is the core function that JDeviceLink provides automatically.
Why use TCP at all?