GetVariables (Retrieve Variables)

The GetVariables instruction is used to retrieve one or more values from a variable or variable array in a data table of a source PakBus device and store them into a variable or variable array in a destination PakBus datalogger.

Syntax

GetVariables ( ResultCode, ComPort, NeighborAddr, PakBusAddr, Security, TimeOut, "TableName", "FieldName", Variable, Swath )

Remarks

The TableName and FieldName parameters, along with the Swath parameter, are used to determine what values are retrieved from the source datalogger. The first value to be retrieved is defined with TableName and Fieldname, and the number of values is specified by Swath. If Swath is greater than 1, Fieldname must be an array and Variable must be an array. The most recent variable(s) stored in the table are retrieved.

GetVariables can also be used to get values from data stored into LoggerNet's data cache. The device name used in LoggerNet's network map is used to specify which datalogger the values should be retrieved from. The syntax used is DeviceName.TableName in the TableName argument of the GetVariables instruction.

If security is enabled in the source datalogger, it must be unlocked to level 3 for this instruction to be successful. The source and destination dataloggers must have unique PakBus addresses.

Note that multiple GetVariable instructions in a program will increase the time for the program to execute its scan. All GetVariable instructions are handled with one communication task and, thus, cannot be processed concurrently.

If ClosedPakBus PakBus® is a proprietary communication protocol developed by Campbell Scientific to facilitate communications between Campbell Scientific devices. Similar in concept to IP (Internet Protocol), PakBus is a packet-switched network protocol with routing capabilities. A registered trademark of Campbell Scientific, Inc. encryption is enabled in the datalogger, by default the datalogger will encrypt the communications sent using this instruction. To disable encryption for one or more Pakbus addresses, use the EncryptExempt instruction. This is useful if a remote device does not support encryption (such as a CR200 or an AVW200).

Parameters

ResultCode (Response Code)

The variable in which a response code for the transmission will be stored. A zero indicates a successful transaction. A positive value indicates that there was no response to the request from the remote. A negative value indicates some other type of error occurred. The codes that can be returned are:

Code Description
0 Successful.
-1 Response received but permission denied.
-16 Table name and/or field name not present in the source datalogger, or the field is read only in the destination datalogger.
-17 Data type not supported.
-18 Array in the source datalogger is not dimensioned large enough to accommodate the values to be sent or array in the destination datalogger is not large enough to accommodate values received
-20  Out of Comms memory.
-21 Failed to route packet when routing is set to auto-discover and route is not yet known.
-22 Communication port buffer exceeded.
-27 DialSequence/EndDialSequence returned False so communication did not occur.
1, 2..n The number of timeouts waiting for a response. The value will increment with each successive failure. After a 0 or negative response, the value will start over at 1.

Type: Variable

ComPort (Communications Port)

The communications port that will be used by the instruction. Right-click to display a list. Options vary depending on the instruction.

Alphanumeric Description
ComRS232 RS232 port of the datalogger
ComUSB USB of the datalogger
ComME Datalogger CS I/O port; modem enabled
Com310 Datalogger CS I/O port; COM310 modem
Com320 Datalogger CS I/O port; COM320 modem
ComSDC7 Datalogger CS I/O port; SDC7
ComSDC8 Datalogger CS I/O port; SDC8
ComSDC10 Datalogger CS I/O port; SDC10
ComSDC11 Datalogger CS I/O port; SDC11
ComC1 Datalogger control terminals 1 & 2
ComC3 Datalogger control terminals 3 & 4
ComU1 Universal terminal pair U1 (TX) & U2 (RX)
ComU3 Universal terminal pair U3 (TX) & U4 (RX)
ComU5 Universal terminal pair U5 (TX) & U6 (RX)
ComU7 Universal terminal pair U7 (TX) & U8 (RX)
ComU9 Universal terminal pair U9 (TX) & U10 (RX)
ComU11 Universal terminal pair U11 (TX) & U12 (RX)
ComRF Integrated radio communication

Type: Constant. For all instructions except SerialOpen, this parameter can also be a variable.

If a negative value is entered for the ComPort, the datalogger will not wait on a response from the destination device before proceeding to the next instruction. If autodiscovery is enabled (NeighborAddr=non-valid PakBus ID), this parameter is ignored.

When communicating over TCP/IP, use the variable returned by the TCPOpen function for the ComPort. If PakBusTCPServer setting is being used rather than TCPOpen, use the Route(-PakBusAddr ) instruction for the ComPort parameter.

If 0 is used for the ComPort in a datalogger not set up as a router and a neighbor address is specified, the datalogger will use that PakBus device as a router.

NeighborAddr (PakBus Address to Neighbor Datalogger)

Used to specify a static route to the destination datalogger (for example, the ClosedPakBus PakBus® is a proprietary communication protocol developed by Campbell Scientific to facilitate communications between Campbell Scientific devices. Similar in concept to IP (Internet Protocol), PakBus is a packet-switched network protocol with routing capabilities. A registered trademark of Campbell Scientific, Inc. address of a "neighbor" datalogger that the host can go through to communicate with the destination datalogger). Note that the datalogger will attempt to use this route only until it "learns" a dynamic route to the destination datalogger.

If 0 is entered, the destination device is assumed to be a neighbor (i.e., the host datalogger can communicate with the destination directly). If a non-valid PakBus address is entered (a negative number or a number greater than 4094), the route to the destination device will be "autodiscovered" by other means in the PakBus network (such as beaconing or a Hello messages). If the instruction has a ResultCode parameter, an error code is returned until the route is discovered. When autodiscovery is used, the COMPort parameter is ignored.

Type: Integer between 1 and 4094

NOTE: By default, Campbell Scientific software uses the following PakBus addresses: LoggerNet 4094, VisualWeather 4094, PC400 4093, PC200W 4092, PConnect/PConnectCE 4091, RTDAQ 4090, Device Configuration Utility 4089.

Note that if the datalogger is configured as a Closedleaf node The degree to which the result of a measurement, calculation, or specification conforms to the correct value or a standard. (as opposed as a Closedrouter A device configured as a router is able to forward PakBus packets from one port to another. To perform its routing duties, a datalogger configured as a router maintains its own list of neighbors and sends this list to other routers in the PakBus network. It also obtains and receives neighbor lists from other routers. Routers maintain a routing table, which is a list of known nodes and routes. A router will only accept and forward packets that are destined for known devices. Routers pass their lists of known neighbors to other routers to build the network routing system.), setting the NeighborAddr to autodiscover should be used with care. A leaf node is aware only of its direct neighbors but has no knowledge of the rest of the PakBus network; therefore, it is not capable of "autodiscovering" a route to a destination datalogger that is not a direct neighbor. If the direct neighbors it can communicate with are not routers themselves, any communication packets sent will fail. Communication packets from the leaf node to the rest of the network also will fail if its direct router is no longer in the network.

When a leaf node is set to autodiscover it will attempt to communicate any time it is aware of a neighbor that is a router.  This will result in an incrementing result code if that neighbor router is not aware of the destination address. If the leaf node's neighbor is not a router or if the leaf node has no neighbors, communication will not be attempted and a -21 is returned.

PakBusAddr (PakBus Address)

The ClosedPakbus PakBus® is a proprietary communication protocol developed by Campbell Scientific to facilitate communications between Campbell Scientific devices. Similar in concept to IP (Internet Protocol), PakBus is a packet-switched network protocol with routing capabilities. A registered trademark of Campbell Scientific, Inc. address of the device that will be contacted as a result of this instruction. Each PakBus device in the network must have a unique address.

If PakBus encryption is enabled in the datalogger, by default the datalogger will encrypt the communications sent using PakBus communication. To disable encryption for one or more Pakbus addresses, use the EncryptExempt instruction. This is useful if a remote device does not support encryption (such as a CR200 or an AVW200).

Type: Integer between 1 and 4094

NOTE: By default, Campbell Scientific software uses the following PakBus addresses: LoggerNet 4094, VisualWeather 4094, PC400 4093, PC200W 4092, PConnect/PConnectCE 4091, RTDAQ 4090, Device Configuration Utility 4089, Konect GDS a value in the range of 4000 – 4050. 4095 is a broadcast address that can be used in a limited number of instructions.

Security

The security code of the remote datalogger. 0 is entered for this parameter if no security is set in the destination datalogger.

Type: Integer

If security is enabled, it must be unlocked to level 3.

NOTE: If other data logger security settings, such as TCP password and PakBus Encryption are set, these must also match between remote and local data loggers for successful data logger to data logger communications to occur.

TimeOut (Wait Time)

The amount of time, in 0.01 seconds, that the datalogger should wait for a response before considering the instruction to have failed. The datalogger waits for the TimeOut period to expire before proceeding to the next instruction.

If 0 is entered for this parameter, then the datalogger will use a time based on its known route to the destination device.

Type: Constant

NOTE: In RF400 communication, the timeout should be sufficiently long to avoid collisions (the default of 0 should accomplish this, or use at least 500 ms).

"TableName" (Table Name)

The name of the DataTable which contains the values to retrieve (GetVariables) or the table to which values will be sent (SendVariables). TableName must be entered as a string (enclosed in quotes).

NOTE: Values can only be sent to or retrieved from an input location in an Edlog-programmed PakBus datalogger (CR10XPB, CR510PB, or CR23XPB). The TableName to be used is "Inlocs" (or "Public") and the FieldName is the input location label.

Type: String or Variable that evaluates as a String

"Fieldname" (Field Name)

Used to specify the name of the variable(s) in the destination datalogger for (SendVariables) or retrieve from (GetVariables). If Swath is greater than 1, FieldName must be an array. FieldName must be entered as a string (enclosed in quotes). If the variable in the source datalogger has been assigned an Alias, the alias must be used for Fieldname unless the value requested is from the Public table. In this case, either the original name or the Alias name can be used (the exception is CR200 series dataloggers; they require that the Alias be used). If the requested Fieldname is from an output table of a CRBasic datalogger, and the output is something other than a sample, the output type suffix must be added to the variable name (for example, Temp_Avg). For more information, see CRBasic Program Structure.

Type: String or Variable that evaluates as a string

Variable

GetVariable: The array in which the variable(s) retrieved from the destination datalogger should be stored.

SendVariable: The variable(s) that should be sent to the destination datalogger.

The Variable parameter must be dimensioned equal to or greater than the Swath parameter.

Type: Variable or Variable Array

For the GetVariables instruction, the Variable parameter must be dimensioned equal to or greater than the Swath retrieved from the source datalogger.

Swath (Number of Variables Sent/Received)

The number of variables that will be retrieved from or sent to the datalogger.

Type: Constant (or expression that evaluates as a constant)

NOTE: Only Public variables can be retrieved from CR2xx dataloggers. SendData can be used to push data from a CR2xx to another datalogger.

Only input locations can be retrieved from Edlog-programmed PakBus dataloggers (CR10XPB, CR510PB, or CR23XPB). The TableName to use is "Inlocs" (or "Public") and the FieldName is the input location label. The TableName and FieldName are case sensitive when retrieving values from these datalogger types.