Why I read through the timer control, the time interval of two sensors, read the first normal, read the second one is slow, about three times time,
Pray god to solve,
CodePudding user response:
My time control program:Private Sub Timer4_Timer ()
Temp=temp + 1
If temp=1 Then
T2. Text=""
Call hexSend1
End the If
If temp=2 Then
T4. Text=""
Call hexSend2
End the If
If temp & gt; 2 Then temp=0
End the If
End Sub
CodePudding user response:
Private Sub Timer4_Timer ()
The Static Temp As Integer
Timer4. Enabled=False
The Select Case Temp
Case 0
T2. Text=""
Call hexSend1
Case 1
T4. Text=""
Call hexSend2
In Case the Else
'...
End the Select
Temp=(Temp + 1) Mod 2
Timer4. Enabled=True
End Sub
1. Timer4_Timer the execution time of the event functions may exceed Timer4. The time Interval of the Interval, so start with Enabled interrupt, such time space more even some
2. The data back to read in the OnComm event, you are still in HexSend function, OnComm event, there may be the trigger condition setting problems, such as MSComm control RThreshold value problems setting up the values, and stick the data package, such as two send two packets, but data read it once only to parse a data loss,
3. Read and display separation as far as possible, the program just read and display program just, a lot of times the requirements of data acquisition is the sooner the better, rather than of time intervals, such as display processing of what is contained in the same code, will make the code appears cluttered and debugging difficulty, as far as possible separation,
CodePudding user response:
If you have this sentence: Temp=(Temp + 1) Mod 2The Temp value is only 0 or 1,
So, did not need to Select, use the If... The Else... Line;
And Temp=(Temp + 1) Mod 2 operation efficiency is "low", use Temp=1 Xor Temp,
Or in the If... The Else... The branch of direct assignment 1 and 0 respectively,
CodePudding user response: