4 an example of data collection, An example of data collection – Campbell Scientific Java PakBus Software Development Kit User Manual

Page 17

Advertising
background image

Java PakBus® Software Development Kit

DataCollectModeRecordNoToNewest

Specifies that all of the records on or after the specified beginning record

number up the newest record in the table should be collected.

5.4 An Example of Data Collection

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


class Example5_4 implements DataCollectClient, GetTableDefsClient
{
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);

// we first need the table definitions. We'll wait to query
// until the table definitions have been read
my_cr1000.add_transaction(new GetTableDefsTran(this));

// 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(
GetTableDefsTran transaction,
int outcome) throws Exception
{
if(outcome == GetTableDefsTran.outcome_success)
{
// start the data collection transaction
my_cr1000.add_transaction(
new DataCollectTran(
"one_sec", this, new DataCollectModeMostRecent(1)));
}
else
{
System.out.println("get table defs failed");

9

Advertising