J
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
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