Setting or checking a datalogger clock – Campbell Scientific Java PakBus Software Development Kit User Manual

Page 14

Advertising
background image

Java PakBus® Software Development Kit

4. Setting or Checking a Datalogger Clock

The current value of a datalogger’s real time clock can be read or adjusted

using the

ClockSetTran transaction. In order to use this transaction, the

application will be expected to furnish an object that implements the

ClockSetClient interface. This transaction is probably the simplest supported

by the API in that it consists of only one message being sent to the datalogger

and one response coming back. Both the command and the response messages

are fixed, short sizes. Because of this, the clock check transaction is a popular

choice to periodically test datalogger communications. The following example

demonstrates the use of the clock check transaction:

import com.campbellsci.pakbus.*;
import java.net.*;

class Example4 implements ClockSetClient
{
private Network network;
private Socket socket;
private boolean complete;
private Datalogger my_cr1000;

public void run() throws Exception
{
// create the connection and the network
socket = new Socket("192.168.4.225",6785);
network = new Network(
(short)4079,
socket.getInputStream(),
socket.getOutputStream());

// create the station
my_cr1000 = new Datalogger((short)1085);
network.add_station(my_cr1000);

// start a clock check. If the clock is to be changed,
// we would send a non-zero value for the second parameter.
my_cr1000.add_transaction(new ClockSetTran(this,0L));

// now drive the network
int active_links = 0;
complete = false;
while(!complete || active_links > 0)
{
active_links = network.check_state();
Thread.sleep(100);
}
}


public void on_complete(
ClockSetTran transaction,
int outcome)
{
if(outcome == ClockSetTran.outcome_checked ||
outcome == ClockSetTran.outcome_set)
{
System.out.println("Logger time was " +
transaction.get_logger_time());

6

Advertising