Campbell Scientific Java PakBus Software Development Kit User Manual
Page 26

Java PakBus® Software Development Kit
An application can start a User I/O transaction by creating an object of class
UserIoTran. The application will be expected to provide a client object that
implements the
UserIoClient interface. Once the transaction has been started,
the application can send bytes for the terminal emulation process by calling
send_data() and will receive bytes sent by the datalogger in the
on_bytes_received() method. The user I/O transaction will keep focus until it
is
closed or until an error occurs.
import com.campbellsci.pakbus.*;
import java.net.*;
import java.io.*;
public class TestUserIo implements UserIoClient, Runnable
{
public TestUserIo() throws IOException
{
socket = new Socket("192.168.4.225",6785);
network = new Network(
(short)4079,
socket.getInputStream(),
socket.getOutputStream());
complete = false;
} // constructor
/**
* @param args
*/
public static void main(String[] args)
{
try
{
TestUserIo tester = new TestUserIo();
tester.run();
}
catch(Exception e)
{
System.out.println("An exception interrupted the transaction:");
System.out.println(e);
}
} // main
public void run()
{
try
{
// we need to add the station and the transaction
Datalogger station = new Datalogger((short)1085);
network.add_station(station);
station.start_manage_comms();
io_tran = new UserIoTran(this);
station.add_transaction(io_tran);
// we can now wait while the transaction runs to completion.
int active_links_count = 0;
byte[] in_buff = new byte[1024];
while(!complete || active_links_count > 0)
18