Software Development Kit

Java PakBus® Software Development Kit
clock set/check, data collection, or sending a file. Each has a
corresponding client interface which will receive status notifications as the
transaction progresses and a completion notification when the transaction
is complete. An application initiates transactions by creating specific
transaction objects and addingthem to the appropriate datalogger object.
All of the other classes in the API are designed as helperclasses for the core
classes mentioned above.
2. Setting up the Network
Setting up the API consists of creating an instance of the Network class. This
class has one constructor which requires a PakBus® address, an input stream,
and an output stream. The PakBus® address must uniquely identify your
application in the PakBus® network in which it will participate. The input and
output streams can be derived from an instance of java.net.Socket or of
javax.comm.CommPort. They could also be derived from some other
communications API supported on your platform. The network object will
listen for incoming messages on the input stream object and will write outgoing
messages to the output stream object. Once the network object has been
created, the application must drive it by calling its check_state() method
periodically. All notifications and activity in the network will result from this
call. The following code fragment shows an example of constructing and
driving a network object:
import com.campbellsci.pakbus.*;
import java.net.*;
class Example2
{
private Network network;
private Socket socket;
private boolean complete;
public void run() throws Exception
{
socket = new Socket("192.168.4.225",6785);
network = new Network(
(short)4079,
socket.getInputStream(),
socket.getOutputStream());
complete = false;
while(!complete)
{
network.check_state();
Thread.sleep(100);
}
}
}
The application shown above doesn’t do much of interest to anyone. It will
accept, but not act on most incoming messages. But, at this point, it is pretty
much useless to us. This can be changed somewhat by adding station objects
to the network. Consider the above example expanded:
2