Campbell Scientific LoggerNet-SDK Software Development Kit User Manual
Page 45
Section 9. Developing an Application Using the Datalogger 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
serverConnect()
method. A basic example of code used to accomplish this task is listed in the
table below:
Private Sub cmdConnect_Click()
'Set the connection parameters
DataLogger.serverName = txtServerAddress
DataLogger.serverPort = txtServerPort
DataLogger.serverLogonName = txtUsername
DataLogger.serverLogonPassword = txtPassword
'Connect to the LoggerNet server
DataLogger.serverConnect
End Sub
If the connection succeeds, the
onServerConnectStarted()
event is
triggered. Otherwise, the
onServerConnectFailure()
event is called.
Next, set the name of the specific datalogger to be managed. An application
can use the CsiBrokerMap control to display all stations and allow the user to
select a specific datalogger from the network map. However, in this example,
the user merely enters the name of a datalogger known to exist in the
LoggerNet server network map. In this example, the user changes the
datalogger to manage by entering a new datalogger name. However, if
communication is in progress between the LoggerNet server and the
datalogger, the user will not be able to change the datalogger name. An
example of the code used to set the datalogger name can be found in the table
below:
Private Sub txtDataloggerName_Change()
'Make sure a datalogger connection is not active
If DataLogger.loggerConnected Then
MsgBox "Connection Active. Can't change datalogger
name."
TxtDataloggerName = DataLogger.loggerName
Else
DataLogger.loggerName = txtDataloggerName
End
If
End Sub
After setting the datalogger name, the managerial functions can be called to
access the datalogger. The
loggerConnectStart()
method can be used to
create a persistent connection between the LoggerNet server and the
datalogger. The
onLoggerConnnectStarted()
event gets called if the
connection succeeds. Otherwise, the
onLoggerConnectFailed()
event gets
called if the connection fails. A persistent connection allows multiple
transactions to occur without the need to connect and disconnect across the
network to the datalogger. The following code illustrates the use of the
loggerConnectStart() method:
9-3