I’m trying to read some holding registers from a PLC using this active X.
I can connect to the PLC (using some code found in the forum!) but I cannot get the value of the specified register.
I think I’m missing something…could you help?
regards
Dim e As Integer
Dim ConnectionStatus As Boolean
Dim Mbaxpi As New MBAXPLib.Mbaxp
Dim conType As MBAXPLib.enumConnection
conType = enumConnection.TCP_IP
Mbaxp1.Connection = conType
Mbaxp1.IPAddr1 = 192
Mbaxp1.IPAddr2 = 168
Mbaxp1.IPAddr3 = 1
Mbaxp1.IPAddr4 = 247
Mbaxp1.TCPIPPort = 502
Mbaxp1.Timeout = 1000
Mbaxp1.ConnectTimeout = 10000
ConnectionStatus = Mbaxp1.OpenConnection
e = Mbaxp1.GetLastError
'break
if e = 0 Then
MsgBox("Connection success")
dim result as Boolean
dim valore as Int16
result=Mbaxp1.ReadHoldingRegisters(1, 1, 0, 1, 1000)
result=Mbaxp1.UpdateEnable(1)
valore=Mbaxp1.Register(1, 0)
'MsgBox(Mbaxp1.Register(1, 0))
break
ElseIf e = 34 Then
MsgBox("Connection timeout")
ElseIf e <> 0 Then
MsgBox("Connection Error")
End
I do Modbus, but have never used this Active-X control. Make sure both your control and your PLC talk Modbus RTU or Modbus TCP. If they are not the same, it won’t work.
I also have not used this Active-X control but I am using a github project called libplctag https://github.com/libplctag/libplctag which works quite well with Rockwell PLC’s and some Modbus TCP devices I have needed to interface with.
From the Github project page:
High Level Features
EtherNet/IP and Modbus TCP support.
Open source licensing under the MPL 2.0 or LGPL 2+.
Pure C library for portability across Linux, Windows and macOS as well as 32-bit and 64-bit.
Support for x86, ARM and MIPS, and probably others.
Very stable API with almost no changes other than feature additions since 2012.
Low memory use and very high performance and capacity. Uses protocol-specific features to increase performance.
Simple API with minimal use of language-specific data to enable easy wrapping in other languages.
Extensive example programs showing use of all library features.
Wrappers for higher level languages like C#/.Net, Julia etc.
Free!
Compiled Windows 32-bit and 64-bit dll’s (and probably other platforms) are available for download. I have a module with constant definitions and external method declarations for the dll. Not sure how I can distribute that if you are interested.