INSTRUCTION MANUAL Java PakBus® Software Development Kit 7/14 C o p y r i g h t © 2 0 1 4 C a m p b e l l S c i e n t i f i c , I n c .
Campbell Scientific, Inc. Software SDK End User License Agreement (EULA) NOTICE OF AGREEMENT: Please carefully read this EULA. By installing or using this software, you are agreeing to comply with the terms and conditions herein. If you do not want to be bound by this EULA, you must promptly return the software, any copies, and accompanying documentation in its original packaging to Campbell Scientific or its representative.
ii. class Datalogger - This class represents the state of a datalogger in the PakBus® network. It stores the routing information needed to reach that datalogger as well as meta-data for that station. The application can operate on the “real” datalogger by initiating transactions through instances of this class. iii. Transactions - Transactions are concrete objects derived from class TransactionBase.
Campbell Scientific warrants that the software itself will perform substantially in accordance with the specifications set forth in the instruction manual when properly installed and used in a manner consistent with the published recommendations, including recommended system requirements. Campbell Scientific does not warrant that the software will meet licensee’s requirements for use, or that the software or documentation are error free, or that the operation of the software will be uninterrupted.
Table of Contents PDF viewers: These page numbers refer to the printed version of this document. Use the PDF reader bookmarks tab for links to specific sections. 1. Introduction ................................................................. 1 2. Setting up the Network ............................................... 2 3. Using Transactions..................................................... 4 4. Setting or Checking a Datalogger Clock .................. 6 5. Data Collection ..............................
Java PakBus® Software Development Kit 1. Introduction NOTE The purpose of this document is to provide prospective developers with a general overview of the Java PakBus® SDK and its application. The primary classes are discussed and example implementations are provided. This document is not intended as a programmers guide or reference.
Java PakBus® Software Development Kit clock set/check, data collection, or sending a file. Each has a corresponding client interface which will receive status notifications as the transaction progresses and a completion notification when the transaction is complete. An application initiates transactions by creating specific transaction objects and “adding” them to the appropriate datalogger object. All of the other classes in the API are designed as “helper” classes for the core classes mentioned above. 2.
Java PakBus® Software Development Kit import com.campbellsci.pakbus.*; import java.net.*; class Example2 { private Network network; private Socket socket; private boolean complete; private Datalogger my_cr1000; private Datalogger my_other_cr1000; public void run() throws Exception { // create the connection and its network socket = new Socket("192.168.4.225",6785); network = new Network( (short)4079, socket.getInputStream(), socket.
Java PakBus® Software Development Kit 3. Using Transactions Up to this point, we have built the network and added stations to it. These steps, by themselves, still do not lead to much functionality except that we can now create transaction objects and “add” these to the stations. The transactions will perform most of the work for our application. Let’s extend the above example to retrieve table definitions and other meta-data from the datalogger: import com.campbellsci.pakbus.*; import java.net.
Java PakBus® Software Development Kit In this version, the class declaration was changed so that class Example was made to implement the GetTableDefsClient interface and a new on_complete() was added. We also added the line that adds a new instance of GetTableDefsTran. When the newly added transaction has completed its work, the client’s on_complete() notification will be invoked. There is a common pattern here used for all transactions: 1. The application adds a new transaction object to a station.
Java PakBus® Software Development Kit 4. Setting or Checking a Datalogger Clock The current value of a datalogger’s real time clock can be read or adjusted using the ClockSetTran transaction. In order to use this transaction, the application will be expected to furnish an object that implements the ClockSetClient interface. This transaction is probably the simplest supported by the API in that it consists of only one message being sent to the datalogger and one response coming back.
Java PakBus® Software Development Kit System.out.println("The round trip time was " + transaction.get_round_trip_time() + " msec"); } else System.out.println("clock check/set failed"); complete = true; } } Note that our example has become somewhat of a boiler-plate. We replaced the GetTableDefsTran with a new ClockSetTran. We also made a few modifications so that the run() method will exit after the complete flag is set and the low level links are shut down.
Java PakBus® Software Development Kit 5.2 Managing Table Definitions In order for data collection to be able to work, a client to the datalogger must have an up-to-date copy of the datalogger’s table definitions so that the binary record objects can be properly interpreted. This can be done by using the GetTableDefsTran transaction. The result of this transaction will be in storing a “raw table definitions” buffer in the Datalogger object which can be accessed using the get_raw_table_defs() method.
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.
Java PakBus® Software Development Kit complete = true; } } public boolean on_records( DataCollectTran transaction, List records) { for(Record record: records) { System.out.print(record.get_time_stamp().format("\"%y%m-%d %H:%M:%S%x\",")); System.out.print(record.get_record_no()); for(ValueBase value: record.get_values()) System.out.print("," + value.format()); System.out.
Java PakBus® Software Development Kit { if(outcome == GetValuesTran.outcome_success) System.out.println("Test succeeded: " + values.get_value(0)); else System.out.println("Test failed: " + outcome); complete = true; } // on_complete public static void main(String[] args) { try { Example5_5 test = new Example5_5(); test.run(args); } catch(Exception e) { System.out.
Java PakBus® Software Development Kit 6. Datalogger File Management The CR1000, CR3000, and CR800 series dataloggers implement file systems in flash (CPU drive), memory protected RAM (USR drive), and, optionally, in compact flash cards (CRD drive). These file systems are used to hold program files as well as other files that are created or used by the datalogger program. In order to manage these files, the following transactions are provided: 6.
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.
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 PakBus® Software Development Kit import java.io.IOException; import com.campbellsci.pakbus.*; import java.io.*; import java.net.*; public class Example6_3 implements SendFileClient, FileControlClient, GetProgStatsClient { public Example6_3( String[] args) throws Exception { if(args.length < 4) throw new Exception("Not enough arguments"); complete = false; } // constructor public void on_complete(SendFileTran transaction, int outcome) throws Exception { if(outcome == SendFileTran.
Java PakBus® Software Development Kit // specified by hold_off before we continue System.out.println("File control succeeded"); reopen_delay = hold_off * 1000; } else { System.out.println("File control failed: " + outcome); complete = true; } } // on_complete public void on_complete( GetProgStatsTran transaction, int outcome) throws IOException { if(outcome == GetProgStatsTran.outcome_success) { System.out.println("Program compilation complete:"); System.out.println(" Program Name: " + datalogger.
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.
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.
Java PakBus® Software Development Kit { int available = System.in.available(); while(available > 0) { int bytes_read = System.in.read(in_buff); if(bytes_read > 0) io_tran.send_data(in_buff, bytes_read); available = System.in.available(); } active_links_count = network.check_state(); Thread.sleep(100); } } catch(Exception e) { System.out.println("An exception interrupted the transaction:"); System.out.
Java PakBus® Software Development Kit /** * reference to the user I/O transaction object */ UserIoTran io_tran; } 8. Attribution PakBus is a registered trademark of Campbell Scientific, Inc.
Campbell Scientific Companies Campbell Scientific, Inc. (CSI) 815 West 1800 North Logan, Utah 84321 UNITED STATES www.campbellsci.com • info@campbellsci.com Campbell Scientific Centro Caribe S.A. (CSCC) 300 N Cementerio, Edificio Breller Santo Domingo, Heredia 40305 COSTA RICA www.campbellsci.cc • info@campbellsci.cc Campbell Scientific Africa Pty. Ltd. (CSAf) PO Box 2450 Somerset West 7129 SOUTH AFRICA www.csafrica.co.za • cleroux@csafrica.co.za Campbell Scientific Ltd.