Using transactions – Campbell Scientific Java PakBus Software Development Kit User Manual
Page 12

Java PakBus® Software Development Kit
3. Using Transactions
Up to this point, we have built the network and added stations to it. These
steps, by themselves, still do not lead to much functionality except that we can
now create transaction objects and “add” these to the stations. The transactions
will perform most of the work for our application. Let’s extend the above
example to retrieve table definitions and other meta-data from the datalogger:
import com.campbellsci.pakbus.*;
import java.net.*;
class Example3 implements GetTableDefsClient
{
private Network network;
private Socket socket;
private boolean complete;
private Datalogger my_cr1000;
private Datalogger my_other_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);
my_other_cr1000 = new Datalogger((short)1084,(short)1085);
network.add_station(my_cr1000);
network.add_station(my_other_cr1000);
my_other_cr1000.set_round_trip_time(10000);
// start getting table definitions
my_cr1000.add_transaction(new GetTableDefsTran(this));
// now drive the network
complete = false;
while(!complete)
{
network.check_state();
Thread.sleep(100);
}
}
public void on_complete(
GetTableDefsTran transaction,
int outcome)
{
if(outcome == GetTableDefsTran.outcome_success)
System.out.println("Got table definitions");
else
System.out.println("Get table defs failed");
}
}
4