Communicate with a controller using Modbus-RTU with VB

Dear all friends:
I want to write a program us VB to read the value from my contrller that use MODBUS-RTU protocol, can you tell me the mistake from my program as follow. Thank!

Private Sub Command1_Click()
Dim result As String
For k = 1 To 5
'' *** Use RXMOD.DLL & read_hold_reg can get the value,but REGISTRY ADDRESS limit to 12
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If

result = read_hold_reg(k, 1, 1, 9600, 0)
TimeDelay (500)
Debug.Print "result" & k & " = "; result
Text2.Text = result

'' *** my program source code as follow that cann't get the value, WHY????
MSComm1.PortOpen = True
MSComm1.Output = Chr(&H0) & Chr(&H1) & Chr(&H0) & Chr(&H3) & Chr(&H0) & Chr(&H1) & Chr(&H0) & Chr(&H0) & Chr(&H0) & Chr(&H0) & Chr(&H0) & Chr(&H1) & Chr(&H85) & Chr(&F6)
TimeDelay (500)
Label2.Caption = MSComm1.Input

Debug.Print "MSCOMM1.InBufferCount";MSComm1.InBufferCount

Debug.Print "MSCOMM1.INPUT";MSComm1.Input
Next

MSComm1.PortOpen = False

End Sub
 
This is the hard way to get the job done. Consider using an ActiveX control to do the Modbus/RTU work. Check out SMRX at "www.sapia-inc.com":http://www.sapia-inc.com . You can download the fully functioning demo that contains a detailed VB example. You'll have your application running in minutes rather than days (or perhaps weeks). Good luck with this otherwise.
 
The PC that uses SMRX must be MODBUS MASTER. Is there a similar OCX that lets it be MODBUS SLAVE? I need a way for a PC to talk MODBUS/RTU to a DCS which insists on being the MASTER.
 
Top