15
« on: September 26, 2019, 06:52:05 PM »
I only wrote the select case but when I ran the program I realized the timeout and comm broken problems. Since you mentioned it, i just write a sample code for people who wants to have a look:
Private Sub PLC_Read_Timer_Tick(sender As Object, e As EventArgs) Handles PLC_Read_Timer.Tick
'100mS Timer
PLC_Scan = IIf(PLC_Scan >= 9, 0, PLC_Scan + 1)
Try
Select Case PLC_IO_Scan
Case 0
'
Case 1
ModbusTCPCom1.BeginRead("40001", 32)
Case 2
ModbusTCPCom1.BeginRead("43001", 32)
Case 3
ModbusTCPCom1.BeginRead("43101", 32)
Case 4
ModbusTCPCom1.BeginRead("40001", 32)
Case 5
ModbusTCPCom1.BeginRead("43001", 32)
Case 6
ModbusTCPCom1.BeginRead("43101", 32)
Case 7
ModbusTCPCom1.BeginRead("40001", 32)
Case 8
ModbusTCPCom1.BeginRead("43001", 32)
Case 9
ModbusTCPCom1.BeginRead("43101", 32)
Case Else
'
End Select
Catch ex As Exception
‘MessageBox.Show("Alarm: PLC Cannot be read!!")
End Try
End Sub
Private Sub ModbusTCPCom1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles ModbusTCPCom1.DataReceived
Dim ind As Integer = 0
Comm_WatchDog_Timer.Enabled = False
Select Case e.PlcAddress
Case "40001"
‘MessageBox.Show("PLC_Address = 40001”)
Case "43101"
For ind = 0 To 31
PC_Array(ind) = CInt(e.Values(ind))
Next
Case "43133"
‘MessageBox.Show("PLC_Address = 40001”)
Case Else
‘MessageBox.Show("PLC_Error”)
End Select
Comm_WatchDog_Timer.Enabled = True
End Sub
Private Sub Comm_WatchDog_Timer_Tick(sender As Object, e As EventArgs) Handles Comm_WatchDog_Timer.Tick
'5000mS Timer
‘MessageBox.Show("Comm Timeout”)
End Sub