Modbus dll Free Open source works well.Tried in vb2008. Is the bomb.

Suresoft

Member
Join Date
Jul 2009
Location
Location
Posts
28
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
On Error GoTo errorhandler
TextBox1.Text = Nothing
Using port As New SerialPort("COM2")
' configure serial port
port.BaudRate = 9600
port.DataBits = 7
port.Parity = Parity.Even
port.StopBits = StopBits.One
port.Open()

' create modbus master
Dim master As modbus.Device.IModbusSerialMaster = modbus.Device.ModbusSerialMaster.CreateAscii(port)

Dim slaveID As Byte = 1
Dim startAddress As UShort = 4546 'read address starting at D450
Dim numRegisters As UShort = 20

' read five registers
Dim registers As UShort() = master.ReadHoldingRegisters(slaveID, startAddress, numRegisters)

For i As Integer = 0 To numRegisters - 1
TextBox1.Text = TextBox1.Text & registers(i) & vbCrLf
Next
End Using
Exit Sub
errorhandler:
Dim rseponse As MsgBoxResult
rseponse = MsgBox(ErrorToString, MsgBoxStyle.OkCancel, "Fault Intercepted")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
On Error GoTo errorhandler
TextBox1.Text = Nothing
Using port As New SerialPort("COM2")
' configure serial port
port.BaudRate = 9600
port.DataBits = 7
port.Parity = Parity.Even
port.StopBits = StopBits.One
port.Open()

' create modbus master
Dim master As modbus.Device.IModbusSerialMaster = modbus.Device.ModbusSerialMaster.CreateAscii(port)

Dim slaveID As Byte = 1
Dim startAddress As UShort = 1024 'read address starting at X0
Dim numRegisters As UShort = 20

' read five registers
Dim registers As Boolean() = master.ReadInputs(slaveID, startAddress, numRegisters)

For i As Integer = 0 To numRegisters - 1
TextBox1.Text = TextBox1.Text & registers(i) & vbCrLf
Next
End Using
Exit Sub
errorhandler:
Timer1.Enabled = False
Dim rseponse As MsgBoxResult
rseponse = MsgBox(ErrorToString, MsgBoxStyle.OkCancel, "Fault Intercepted")
If rseponse = MsgBoxResult.Ok Then
Timer1.Enabled = True
End If

End Sub
 
Last edited:
hi little problem

hi, i'm new of this site :)
i have just a question, i have try your sw and when i push the button vb replace a exception ( Modbus.IO.ModbusAsciiTransport )

where do you copy the dll? in system 32?
i've need to register whit regsrv32?
sorry but i'm new in vb2008, can you help me?
thanks
 
hi all thanks for that dll
but i want to ask about how do you convert D450 => 4546 and X0 => 1024
and what is the outher data map
 

Similar Topics

Somebody knows where can I get a dll?, I´m learning to comunicate with plc and I need the bigest help than you can give me. Sorry for my English...
Replies
2
Views
5,272
Hello, fellow PLC enthusiasts, I’m a newbie in PLC and am currently on a project that involves connecting an Omron CP1E (CP1W-CIF11) PLC to an...
Replies
2
Views
44
I am new to this forum and would need your help. I am looking for the Modbus FBs for the S5 95U for communication with the CP521. These FBs...
Replies
0
Views
21
Hello Everyone, I am using a raC_Opr_NetModbusTCPClient AOI module, as below,. So, I need some assistance to restrict in reducing the poling...
Replies
2
Views
152
I want to communicate my Q series PLC with Factory IO using GX works 2 software, I want to use modbus as server and the ips are as follows plc...
Replies
0
Views
104
Back
Top Bottom