I want to communicate with a Modbus device using a third party ActiveX. I am not sure if I should use OLEContainer or add the ActiveX directly to the project. Since the ActiveX is windowless, I have been working with the latter option.
I added the ActiveX to the project pane. Two entries, Mbaxp and MBAXPLib appear in the contents pane. I then added the following code to a button Action event.
Dim e As Integer
Dim ConnectionStatus As Boolean
Dim Mbaxp1 As MBAXPLib.Mbaxp
Dim conType As MBAXPLib.enumConnection
conType = enumConnection.TCP_IP
Mbaxp1.Connection = conType
Mbaxp1.IPAddr1 = 192
Mbaxp1.IPAddr2 = 168
Mbaxp1.IPAddr2 = 254
Mbaxp1.IPAddr1 = 128
Mbaxp1.TCPIPPort = 502
Mbaxp1.Timeout = 1000
Mbaxp1.ConnectTimeout = 2000
ConnectionStatus = Mbaxp1.OpenConnection
e = Mbaxp1.GetLastError
if e = 0 Then
MsgBox("Connection success")
ElseIf e = 34 Then
MsgBox("Connection timeout")
ElseIf e <> 0 Then
MsgBox("Connection Error")
End
When I run the program, there is no syntax error but when I click the button to which the code is attached, the program stops running at the point shown on the attached image. The object Mbaxp1 retruns a nil value.
Is it that I have not done the correct declarations or I am doing the wrong?