2 receiving a file, Receiving a file – Campbell Scientific Java PakBus Software Development Kit User Manual
Page 21

Java PakBus® Software Development Kit
network.add_station(my_cr1000);
// the file sent will be the source file for this program
my_cr1000.add_transaction(
new SendFileTran(
this,
new FileInputStream("Example.java"),
"USR:Example.java"));
// 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_progress(
SendFileTran transaction,
int bytes_to_send,
int bytes_sent)
{ return true; }
public void on_complete(
SendFileTran transaction,
int outcome) throws Exception
{
if(outcome == SendFileTran.outcome_success)
System.out.println("send file succeeded");
else
System.out.println("send file failed");
complete = true;
}
}
6.2 Receiving a File
A file can be retrieved from one of the datalogger file systems using the
GetFileTran class. This class starts a file receive transaction with the
datalogger and delivers fragments of the file to the application as they are
received using
GetFileClient.on_fragment(com.campbellsci.pakbus.GetFileTran, byte[]).
The following example demonstrates this process:
import com.campbellsci.pakbus.*;
import java.net.*;
import java.io.*;
class Example6_2 implements GetFileClient
{
private Network network;
private Socket socket;
private boolean complete;
private Datalogger my_cr1000;
private OutputStream output;
13