3 sending a datalogger program, Sending a datalogger program – Campbell Scientific Java PakBus Software Development Kit User Manual

Page 22

Advertising
background image

Java PakBus® Software Development Kit


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 will try to get a file from the USR drive
output = new FileOutputStream("test.java");
my_cr1000.add_transaction(
new GetFileTran(
"USR:Example.java",
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 boolean on_fragment(
GetFileTran transaction,
byte[] buff) throws Exception
{
output.write(buff);
return true;
}


public void on_complete(
GetFileTran transaction,
int outcome) throws Exception
{
output.close();
if(outcome == GetFileTran.outcome_success)
System.out.println("get file succeeded");
else
System.out.println("get file failed");
complete = true;
}
}

6.3 Sending a Datalogger Program

The datalogger program can be changed using a combination of

class

SendFileTran and class FileControlTran objects. The following example

illustrates this process:

14

Advertising