Как запустить 5 или более таймеров или потоков для чтения значений внешних устройств (шкал) одновременно, не застревая, в VB или c#.net
I tried to read a value with one timer. It worked well. But I used 4 timers to read 4 scale values, it was not working well, it was delayed to display values, numbering series is wrong highly. Eg: Want to show increasing or decreasing values such as : 1-2-3-4-5-6 But it show as : 1--- delayed few second--- 50 --- delayed few second--- 120
Что я уже пробовал:
С одним таймером и считыванием только одного значения
------------------------------------------------------
Public Class Form4 Dim intR() As Short, blnX() As Boolean Delegate Sub SetTextCallback2() Dim f_err As Fatek_Error_Code = New Fatek_Error_Code Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load f_Plc = New FatekNet.FatekPLCNet("192.168.1.3", 500) f_Plc.Connect() : Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() CountNo() Timer1.Start() End Sub Private Sub CountNo() 'ByVal intValue As Integer If Label1.InvokeRequired Then Dim d As New SetTextCallback2(AddressOf CountNo) Label1.Invoke(d) ', New Object() {intValue}) ' Else Label1.Text = 1 : Call ReadServices() End If End Sub Private Sub ReadServices() Try intR = f_Plc.Read_Continuous(Fatek_Register_Area.HR, 1, 52, Fatek_Data_Type.Short, f_err) TextBox1.Text = intR(0) Catch ex As Exception End Try End Sub End Class
----------------------------------------------------
Код проблемы таков
--------------------------------------------------
Public Class Form5 Dim shtR1(), shtR2(), shtR3(), shtR4() As Short Delegate Sub SetTextCallback2() Dim f_err As Fatek_Error_Code = New Fatek_Error_Code Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load f_Plc = New FatekNet.FatekPLCNet("192.168.1.3", 500) f_Plc.Connect() Timer1.Enabled = True : Timer2.Enabled = True : Timer3.Enabled = True : Timer4.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() CountNo1() Timer1.Start() End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Timer2.Stop() CountNo2() Timer2.Start() End Sub Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick Timer3.Stop() CountNo3() Timer3.Start() End Sub Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick Timer4.Stop() CountNo4() Timer4.Start() End Sub Private Sub CountNo1() 'ByVal intValue As Integer If Label1.InvokeRequired Then Dim d As New SetTextCallback2(AddressOf CountNo1) Label1.Invoke(d) ', New Object() {intValue}) ' Else Label1.Text = 1 : Call ReadServices1() End If End Sub Private Sub CountNo2() 'ByVal intValue As Integer If Label1.InvokeRequired Then Dim d As New SetTextCallback2(AddressOf CountNo2) Label1.Invoke(d) ', New Object() {intValue}) ' Else Label1.Text = 1 : Call ReadServices2() End If End Sub Private Sub CountNo3() 'ByVal intValue As Integer If Label1.InvokeRequired Then Dim d As New SetTextCallback2(AddressOf CountNo3) Label1.Invoke(d) ', New Object() {intValue}) ' Else Label1.Text = 1 : Call ReadServices3() End If End Sub Private Sub CountNo4() 'ByVal intValue As Integer If Label1.InvokeRequired Then Dim d As New SetTextCallback2(AddressOf CountNo4) Label1.Invoke(d) ', New Object() {intValue}) ' Else Label1.Text = 1 : Call ReadServices4() End If End Sub Private Sub ReadServices1() Try shtR1 = f_Plc.Read_Continuous(Fatek_Register_Area.HR, 1, 52, Fatek_Data_Type.Short, f_err) TextBox1.Text = shtR1(0) Catch ex As Exception End Try End Sub Private Sub ReadServices2() Try shtR2 = f_Plc.Read_Continuous(Fatek_Register_Area.HR, 1, 60, Fatek_Data_Type.Short, f_err) TextBox2.Text = shtR2(0) Catch ex As Exception End Try End Sub Private Sub ReadServices3() Try shtR3 = f_Plc.Read_Continuous(Fatek_Register_Area.HR, 1, 56, Fatek_Data_Type.Short, f_err) TextBox3.Text = shtR3(0) Catch ex As Exception End Try End Sub Private Sub ReadServices4() Try shtR4 = f_Plc.Read_Continuous(Fatek_Register_Area.HR, 1, 42, Fatek_Data_Type.Short, f_err) TextBox4.Text = shtR4(0) Catch ex As Exception End Try End Sub End Class