Campbell Scientific LoggerNet Server SDK User Manual

Page 39

Advertising
background image

Section 7. Developing an Application Using the CsiBrokerMap Control

Now that the interface has been designed, the code can be organized to
accomplish the requirements of the application. The control must be started
using the correct parameters to connect with a LoggerNet server. A basic
example of code used to accomplish this task is listed in the table below:

Private Sub cmdConnect_Click()

'Assign the connection parameters
BrokerMap.serverName = txtServerAddress.Text
BrokerMap.serverPort = txtServerPort.Text
BrokerMap.serverLogonName = txtUsername.Text
BrokerMap.serverLogonPassword = txtPassword.Text

'Start the BrokerMap control using the variables above
'The onAllStarted() event will be activated if a connection
'occurs or the onFailure() event will be activated if the
'connection fails
BrokerMap.start

End Sub

If the connection succeeds, the

onAllStarted()

event gets triggered.

Otherwise, the

onFailure()

event gets called. The

onAllStarted()

event

should contain code that iterates through the stations and displays the
appropriate values in a window on the user interface. Example code for the

onAllStarted()

event is listed in the table below:

Private Sub BrokerMap_onAllStarted()

Dim n As Node
Dim b As Broker
Dim t As Table
Dim c As Column

'After the broker map starts, ignore any changes such as additions
'or deletions of brokers or tables from the broker map.
BrokerMap.finish

'Clear out the tree view for a fresh network map
tvwDisplay.Nodes.Clear

'Set the root node
Set n = tvwDisplay.Nodes.Add(, , "Root", "Broker Map")

'Read in the checkboxes to determine the names of the stations,
'tables and columns that will populate the TreeView object.
If chkStations.Value = 1 Then
For Each b In BrokerMap.Brokers
Debug.Print b.Name & " " & b.Type

'Display the Broker Names if checked
Set n = tvwDisplay.Nodes.Add("Root", tvwChild, b.Name, b.Name)

'If Tables are checked, get all of the tables in that Broker
If chkTables.Value = 1 Then
For Each t In b.Tables
'Display the table names
Set n = tvwDisplay.Nodes.Add(b.Name, tvwChild, b.Name & "." & t.Name, t.Name)
'If Columns checked, get all of the columns in the tables
If chkColumns.Value = 1 Then
For Each c In t.Columns
'Display the column names
Set n = tvwDisplay.Nodes.Add(b.Name & "." & t.Name, tvwChild, b.Name & _

7-3

Advertising