Working with user i/o – Campbell Scientific Java PakBus Software Development Kit User Manual

Page 25

Advertising
background image

Java PakBus® Software Development Kit

// start the send transaction
File prog_info = new File(args[3]);

program_name = "CPU:" + prog_info.getName();
datalogger.add_transaction(
new SendFileTran(
this,
new FileInputStream(args[3]),
program_name));

// keep the network going until the task is complete
int tran_count = 1;
while(tran_count > 0 && !complete)
{
tran_count = network.check_state();
if(reopen_delay != 0)
{
// the re-open delay is set to a non-zero value
// when file control returns and the logger
// resets. During this interval, we need to close
// out direct TCP connection to the logger
// and allow it time to reboot before
// reconnecting.
network.set_io_streams(null,null);
socket.close();
socket = null;
System.out.println("Waiting for " + reopen_delay +
" msec for the logger to reboot.");
Thread.sleep(reopen_delay);
System.out.println("Re-opening the connection and
getting program stats");
socket = new Socket(args[0],Integer.parseInt(args[1]));
network.set_io_streams(
socket.getInputStream(),
socket.getOutputStream());
datalogger.add_transaction(new GetProgStatsTran(this));
reopen_delay = 0;
}
else
Thread.sleep(100);
}
} // run


private Socket socket;
private Network network;
private Datalogger datalogger;
private boolean complete;
private String program_name;
private int reopen_delay;
}

7. Working with User I/O

The User I/O transaction allows an application to engage in terminal I/O with

the datalogger the same that can be done with a telnet connection with the

datalogger. The most significant difference between the user I/O transaction

and telnet is that the user I/O messages can be routed across the PakBus®

network and can therefore be used against any datalogger in the PakBus®

network.

17

Advertising