Ultimately in the application I am working on, I want to read and write to various addresses, but don't need to poll the ModbusRTU device. So I have tried some of the following code.
'**** This works to read one register ****
Dim strValue1 As String
Dim n_strMessage As String
Try
strValue1 = ModbusRTUCom1.Read("42817", 1)(0)
lblReadResult.Text = strValue1
Catch ex As Exception
n_strMessage = "Function frmModbusRTUtest: failed with error: " & vbCrLf & ex.Message
Call ShowMessageBox(clsDisplayMessage.enumDisplayMessageType.Critical, n_strMessage)
End Try
'**** This code fails to read the multiple registers and generates an exception "No Reponse from PLC. Ensure baud rate is correct." ****
Dim strDate As String
Dim strTime As String
Dim strValue1 As String
Dim strValue2 As String
Dim strValue3 As String
Dim strValue4 As String
Dim strValue5 As String
Dim strValue6 As String
Dim n_strMessage As String
Try
strValue1 = ModbusRTUCom1.Read("42817", 1)(0)
strValue2 = ModbusRTUCom1.Read("42818", 1)(0)
strValue3 = ModbusRTUCom1.Read("42819", 1)(0)
strValue4 = ModbusRTUCom1.Read("42820", 1)(0)
strValue5 = ModbusRTUCom1.Read("42821", 1)(0)
strValue6 = ModbusRTUCom1.Read("42822", 1)(0)
strDate = strValue5 & "-" & strValue4 & "-" & strValue6
strTime = strValue3 & "-" & strValue2 & "-" & strValue1
lblReadResult.Text = strDate & " " & strTime
Catch ex As Exception
n_strMessage = "Function frmModbusRTUtest: failed with error: " & vbCrLf & ex.Message
Call ShowMessageBox(clsDisplayMessage.enumDisplayMessageType.Critical, n_strMessage)
End Try
It actually worked one time, but has generated the exception all the other times.
Any suggestions???