Campbell Scientific LoggerNet-SDK Software Development Kit User Manual

Page 57

Advertising
background image

Section 11. Developing an Application Using the CsiDataSource Control

Now that the interface has been designed, the code can be organized to
accomplish the requirements of the application. The control must connect with
the LoggerNet server using the correct parameters and the

connect()

method.

If the connection succeeds, the onControlReady() event will be called. A basic
example of code used to accomplish this task is listed in the table below:

Private Sub cmdConnect_Click()

'Set connection parameters
DSource.serverName = txtServerAddress
DSource.serverPort = txtServerPort
DSource.logonName = txtUsername
DSource.logonPassword = txtPassword

'Connect to the LoggerNet server. Successful connections will be
'handled by the onControlReady() function. If the control fails,
'the onControlFailure() function will handle these failures
DSource.Connect

End Sub

Once connected to the LoggerNet server, the Advisor can be created by
entering a known datalogger and table in the text fields and calling the
createAdvisor() method. An application may use the CsiBrokerMap to display
all stations and allow the user to select a specific datalogger, table, and column.
However, in this example, the user merely enters the name of a datalogger and
table known to exist in the LoggerNet server network map. An example of the
code used to start an Advisor that will monitor data in all columns of a specific
datalogger and table can be found in the table below:

Private Sub cmdStartAdvisor_Click()
Dim CurrentAdvisor as Advisor
Dim dcc as DataColumnCollection

'Create a new advisor. Make sure a connection is active to the
'LoggerNet server before attempting to start the Advisor.
'Add all columns to the Advisor to simplify the example.
Set CurrentAdvisor = Dsource.createAdvisor

'Set some properties for the advisor
CurrentAdvisor.advisorName = "NewAdvisor"
CurrentAdvisor.stationName = txtDatalogger
CurrentAdvisor.tableName = txtTable

'Add all columns to the advisor.
Set dcc = CurrentAdvisor.columns
dcc.addAll

'Start the Advisor. When started, onAdviseReady and
'onAdviseRecord will activate. If an advisor fails, the
'onAdvisorFailure event will be called.
CurrentAdvisor.start
End

If

End Sub

After starting the Advisor, the onAdviseReady() event will run and begin
watching the specified table and columns for new data. The onAdviseRecord()
event gets called when new records appear in the LoggerNet server data cache
from the specified datalogger table and columns. The following code
illustrates how records are received:

11-3

Advertising