Thanks for getting back so fast
I exposed a function in ModbusBase.vb:
#Region "Public Methods"
Public Sub SetResponseWait(imSec As Integer)
Try
'default = 300 (3sec)
'1 tick = 10msec (i.e. 100 ticks per second)
MaxTicks = Convert.ToInt32(imSec / 10)
Catch ex As Exception
End Try
End Sub
#End Region
Test1:
I only have one device on test at ID 123, if I do read requests on id=123 for 1000 times before I start the discovery method (below) I get valid read responses,
but then inside the discovery method even id=123 does not respond to a read()
Test 2:
restart program
If however I call modbus id 1-122 (non of which exist) and then follow by calling modbus id 123 (exists) , even 123 does not respond and generates an exception from the Read() call (same exception as though it doesn't exist "No Response from the PLC, Ensure driver settings are correct."
Must be something residual, between changing modbus id, and successive reads that needs top be reset
(unfortunately, cant find a similar forum thread dealing with this, as generally modbus id is hard coded, unless in a redundancy situation, when need to fail-over to another modbus plc)
Baud rate is 115200, which gets back pretty fast when talking to the device
My Discovery Code:
Private Sub BtnFindModbusId_Click(sender As Object, e As EventArgs) Handles Button4.Click
Try
'adress 1-254
Dim bFound As Boolean = False
Timer1.Enabled = True
For id As Byte = 1 To 254
ModbusRTUComFind.StationAddress = id
ModbusRTUComFind.SetResponseWait(50) ' 500msec, must set every timeout, as base code sets to 100, after a timeout
Try
sTestingId = String.Format("Try Modbus ID={0}", id)
Application.DoEvents()
Dim sVal() As String = ModbusRTUComFind.Read("40001", 1)
'if unable to read generates exception here ^^^
bFound = True
tbFoundId.Text = id.ToString()
Exit For
Catch ex As Exception
'not read from device, so try next
Thread.Sleep(100)
End Try
Thread.Sleep(50)
Next
Timer1.Enabled = False
ModbusRTUComFind.SetResponseWait(300) 'return to default
Catch ex As Exception
End Try
End Sub