Hi, from the command wiki
In pipeline mode, measurement tasks and processing tasks are handled separately (in a "measurement task sequencer" and a "processing task sequencer") and executed concurrently
It's not clear to me if in this code SerialOut is always executed before SerialIn or not:
SerialOpen(ComC3,38400,3,0,138,4)
Scan (50,mSec,100,0)
SerialOut (ComC3,"?Q",&H02,0,2) 'open poll request
SerialInRecord (ComC3,row2,&H02,0,&H0D0A,n2,01)
SerialOut (ComC3,"!","",0,0) 'close poll request
NextScan
In the terminal I see the commands in the following order: ?Q, ! , row2. And 20 ms between ?Q and row2. The data is still collected correctly.
I don't understand why with the modified code like this:
SerialOpen(ComC3,38400,3,0,138,4)
Scan (50,mSec,100,0)
SerialOut (ComC3,"?Q","",0,0)
SerialInRecord (ComC3,row2,&H02,0,&H0D0A,n2,01) '2 and 3 ascii char or &H02
NextScan
I continue to see the command ?Q and 20 ms after the Row2 response. Why exactly 20ms if I have not set any delay or timeout?
If SerialOut and SerialIn are considered one Process and the other Measure, how is sequentiality maintained in pipelinemode?
Thanks
To pair with SerialInRecord, use SerialOutBlock. With the right conditions, both run in the digital measurement task. There are notes in the CRBasic help for those instructions.
Do note that neither SerialOutBlock nor SerialInRecord delay the task. You would want a Delay in between them set to the digital task. The length of the delay depends on the response time of the sensor.
With the right conditions
What are these right conditions? I read the Serial Note but I can't find a distinction between pipeline and sequential mode.
If I run this program in sequential mode I obatin all data, with no row1 = NAN, as I want:
SequentialMode 'string: Q,-000.061,+000.049,+000.039,M,+024.73,00,04 BeginProg SerialOpen(ComC3,38400,3,0,512,4) Scan(50,mSec,1,0) SerialOutBlock (ComC3,"?Q",2) 'start polled mode Delay (0,25,mSec) '20ms from terminal emulator W' SerialInRecord (ComC3,row1,&H02,0,&H0D0A,n1,01) ChkSumF_1=HexToDec(Mid(row1,44,2)) Eqv CheckSum(row1,9,42) If ChkSumF_1 Then u_1 = Mid(row1,3,8) v_1 = Mid(row1,12,8) w_1 = Mid(row1,21,8) Ts_1 = Mid(row1,32,8) SS_1 = Mid(row1,40,2) EndIf SerialOutBlock (ComC3,"!",1) 'stop polled mode CallTable Sonic NextScan EndProg
Output terminal:
10:40:34.220 R .Q,-000.037,-000.023,+000.010,M,+023.51,00,.01 10:40:34.230 T ! 10:40:34.250 T ?Q 10:40:34.270 R .Q,-000.039,-000.021,+000.006,M,+023.49,00,.03 10:40:34.280 T ! 10:40:34.300 T ?Q 10:40:34.320 R .Q,-000.040,-000.022,+000.004,M,+023.47,00,.02 10:40:34.330 T ! 10:40:34.350 T ?Q 10:40:34.370 R .Q,-000.040,-000.021,+000.003,M,+023.49,00,.08 10:40:34.380 T !
If I run the same code in PipelineMode, I obtain lot of records with row1 = NAN and a terminal output like this:
10:30:00.900 R .Q,-000.056,-000.004,+000.038,M,+023.47,0 10:30:00.903 R 0,.0E 10:30:00.933 T ?Q 10:30:00.935 T ! 10:30:00.950 R .Q,-000.056,-000.002,+000.036,M,+023.49,0 10:30:00.953 R 0,.08 10:30:00.983 T ?Q 10:30:00.985 T ! 10:30:01.000 R .Q,-000.059,-000.001,+000.035,M,+023.46,0 10:30:01.003 R 0,.08 10:30:01.033 T ?Q 10:30:01.035 T ! 10:30:01.050 R .Q,-000.058,+000.004,+000.035,M,+023.51,0 10:30:01.053 R 0,.0C 10:30:01.083 T ?Q 10:30:01.085 T ! 10:30:01.100 R .Q,-000.058,+000.007,+000.035,M,+023.49,0 10:30:01.103 R 0,.06
I need Pipelinemode beacuse the whole program includes other measurements and operations, the tests above are done with only the code you see.
Try option 2 in the Delay() instruction.
I don't think you need the second SerialOutBlock(). There isn't a reason to tell the sensor to turn off polled mode.
With Delay(2,,) the commands are in the correct order, but I have upgraded my code because with Gill Windmaster
the response to the poll request would be sent within 50ms
So I need at least 50ms between "?Q" and read the response. Now I read row1 that I requested with “?Q” in the previous scan (code at the bottom).
With two serial (comC1 and comC3) a problem appears.
The first comC1 works great! Com3 occasionally receives incorrect strings, like this at 17:00:08.276
17:00:08.224 R .Q,-000.658,+003.750,+002.057,M,+021.95,00,.03 17:00:08.257 T ?Q 17:00:08.262 T ! 17:00:08.276 R Q...r...bZ...r...bZ...r...b+021.88,00,.03 17:00:08.307 T ?Q 17:00:08.312 T ! 17:00:08.326 R Q,-001.170,+002.637,+001.957,M,+021.97,00,.06 17:00:08.357 T ?Q 17:00:08.362 T ! 17:00:08.376 R Q,-001.287,+001.995,+001.782,M,+021.97,00,.0F 17:00:08.407 T ?Q 17:00:08.412 T ! 17:00:08.426 R Q,-001.405,+003.069,+002.259,M,+022.03,00,.05 17:00:08.458 T ?Q 17:00:08.463 T !
but in the Sonic table I find more than one row with NAN values, as if there were a delay in restoring the correct reading.
"17:00:08.25",6436,-4.464,0.632,-1.268,22.34,"00",-1,-0.658,3.75,2.057,21.95,"00",-1 "17:00:08.3",6437,-4.103,0.323,-1.337,22.58,"00",-1,"NAN","NAN","NAN","NAN","NAN",0 "17:00:08.35",6438,-4.102,0.167,-1.084,22.51,"00",-1,"NAN","NAN","NAN","NAN","NAN",0 ... All NAN in middle ... "17:00:11.55",6502,-4.007,0.336,-1.265,22.38,"00",-1,"NAN","NAN","NAN","NAN","NAN",0 "17:00:11.6",6503,-3.891,0.409,-1.33,22.45,"00",-1,-1.326,3.157,2.438,21.85,"00",-1
How can I solde? Thanks
Program used:
PipeLineMode
BeginProg SerialOpen(ComC1,38400,3,0,138,4) 'buffer size (45 +1 char) * 3 SerialOpen(ComC3,38400,3,0,138,4) Scan (50,mSec,100,0) SerialInRecord (ComC1,row1,&H02,0,&H0D0A,n1,01) 'read previous row SerialInRecord (ComC3,row2,&H02,0,&H0D0A,n2,01) SerialOutBlock (ComC1,"?Q",2) 'start polled mode for next scan SerialOutBlock (ComC3,"?Q",2) 'start polled mode for next scan SerialOutBlock (ComC1,"!",1) 'stop polled mode SerialOutBlock (ComC3,"!",1) 'stop polled mode ChkSumF_2=HexToDec(Mid(row2,44,2)) Eqv CheckSum(row2,9,42) If ChkSumF_2 Then u_2 = Mid(row2,3,8) v_2 = Mid(row2,12,8) w_2 = Mid(row2,21,8) Ts_2 = Mid(row2,32,8) SS_2 = Mid(row2,40,2) Else u_2 = NAN v_2 = NAN w_2 = NAN Ts_2 = NAN SS_2 = NAN EndIf ChkSumF_1=HexToDec(Mid(row1,44,2)) Eqv CheckSum(row1,9,42) If ChkSumF_1 Then u_1 = Mid(row1,3,8) v_1 = Mid(row1,12,8) w_1 = Mid(row1,21,8) Ts_1 = Mid(row1,32,8) SS_1 = Mid(row1,40,2) Else u_1 = NAN v_1 = NAN w_1 = NAN Ts_1 = NAN SS_1 = NAN EndIf CallTable Sonic NextScan