Home > Software engineering >  Such as how to read two rs485 sensor data interval?
Such as how to read two rs485 sensor data interval?

Time:09-18

I am write vb program to read two bus connection of RS485 interface sensor data, such as how can alternate between read?
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 2
The 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:

reference Chen8013 reply: 3/f
if you have this sentence: Temp=(Temp + 1) Mod 2
The 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,

That appearance, extensibility, multi-channel acquisition of time as long as the 2 change, plus a few case just a matter of,
But what really multi-channel acquisition using task type will be better, priority allocation, fault equipment upgrade automatically

CodePudding user response:

Since transfer data through the RS485 and can read the data in the MsComm control OnComm event, and then according to the data address to distinguish,
  • Related