Connecting ActiveX to Wialon

To connect to ActiveX COM server, you have to construct the object WialonActiveX.WialonConnection that implements IWialonConnection interface.

Here is an example of a code on Visual Basic. It contains comments but does not contain error check.

        ' The main component of the system that provides connection to Wialon
        Dim Wialon As Object
        ' The collection of available units
        Dim Units As Object
        ' A certain unit 
        Dim Unit As Object
        ' Wialon error string
        Dim ErrStr As String
        ' The collection of messages from a unit
        Dim Msgs As Object
        ' Counter
        Dim i As Long
        ' The number of units in the collection
        Dim CountOfUnits As Long
 
        ' Creating an object to connect to Wialon (for 64-bit applications -- WialonActiveX64)
        Wialon = CreateObject("WialonActiveX.WialonConnection")
        ' Connection check
        If Wialon Is Nothing Then
            ' In case of error, the alert is generated
            MsgBox("No Object")
            Return
        End If
 
        ' Adjusting connection settings through
        Wialon.SetProxyMode "ProxyHost", 8080, "Login:Passw"
        ' Getting all units available to the "user" with the "passw" from the server
	' "https://activex.gurtam.com" (prefix is required for secure connection) 
	' at 443 port without proxy server 
        Units = Wialon.Login("https://activex.gurtam.com", 443, "user", "passw")
        ' Check for available units
        If Units Is Nothing Then
            ' If units are not available, ActiveX error is reported as well as Wialon error
            MsgBox("Error = " + Err.Number.ToString() + ": " + Err.Source.ToString() + " (" + Err.Description.ToString() + ")")
            ' Getting error from Wialon server
            ErrStr = Wialon.GetLastError()
            MsgBox("Wialon error: " + ErrStr)
            Return
        End If
 
        ' Getting the number of available units
        CountOfUnits = Units.Count
        ' Displaying a message box with the number of available units
        MsgBox("Units = " + CountOfUnits.ToString())
 
        ' Starting the cycle for units search
        For i = 1 To CountOfUnits
            ' Getting a unit from the collection
            Unit = Units.Item(i)
            ' Check if the unit is available
            If Unit Is Nothing Then
                ' If the unit is not available, report the error
                MsgBox("Not unit")
                Return
            End If
            ' Adjusting the flag to get addresses by coordinayed. False -- without addresses (fast). True -- with addresses (slow).
 	    Unit.ResolveLocations (False)
            ' Getting messages from a unit for the indicated period (time in UNIX format)
            Msgs = Unit.GetMessages(1255112326, 1256312326)
            ' Check for messages availability
            If Msgs Is Nothing Then
                ' If there are no messages, display the alert
                MsgBox("No messages for unit: " + Unit.Name)
            Else
                ' Display the number of messages found
                MsgBox("Messages = " + Msgs.Count.ToString())
		' Decrement the reference count for the given invoked environment frame CLR
		' (if explicit memory release is needed after using an object)
		System.Runtime.InteropServices.Marshal.ReleaseComObject(Msgs)
                ' Releasing unit with messages
                Msgs = Nothing
            End If
            ' Decrement the reference count for the given invoked environment frame CLR
            ' (if explicit memory release is needed after using an object)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(Unit)
            ' Releasing unit with unit :)
            Unit = Nothing
        Next i
        ' Decrement the reference count for the given invoked environment frame CLR
        ' (if explicit memory release is needed after using an object)
	System.Runtime.InteropServices.Marshal.ReleaseComObject(Units)
        ' This is the end of the program, we're not going to work with these objects anymore, releasing
        Units = Nothing
        Wialon = Nothing
        ' End
        MsgBox("End")

More detailed example is available in Excel file delivered with ActiveX.

Follow us on Facebook Gurtam Wialon Twitter Gurtam Wialon info@gurtam.com   |   Copyright © 2002-2018 Gurtam