CR1000, SerialOut() does not wait for WaitString?
Dear all,
i am trying to set the internal clock of a Grimm EDM164 Dust Monitor using the COM1 Port of a CR1000 logger. By use of the terminal mode in the LoggerNet Connect Screen, it is possible to do this flawlessly. I also managed to download data from the instrument to the logger, so the basic serial communication works.
To set the instruments time, it is necessary to act upon this pseudocode:
Send "T" 'Command to set time
Wait up to 0.5 sec until "T<CRLF>Year 18 :" is received
Send "1" 'send the most significant digit of the year
Wait for Echo "1"
Send "8" 'send the least significant digit of the year
etc.
I wrote a small program to test this functionality, and checked communication with DSO and RS232 monitoring software:
Const GrimmPort = Com1
SetStatus ("USRDriveSize",153600) 'USR: drive in SRAM for Grimm files
Public SetTimeFlag As Boolean
'Define Subroutines
Sub SetGrimmTime 'set Grimm RTC to Logger time, must be called at second 0
Public rTime(9) As Long 'array to store system time
Alias rTime(1) = YY 'assign the alias YY to rTime(1)
Alias rTime(2) = MO 'assign the alias MO to rTime(2)
Alias rTime(3) = DM 'assign the alias DM to rTime(3)
Alias rTime(4) = HO 'assign the alias HO to rTime(4)
Alias rTime(5) = MM 'assign the alias MM to rTime(5)
Alias rTime(6) = Sek 'assign the alias Sek to rTime(6)
Alias rTime(7) = uSek 'assign the alias uSek to rTime(7)
Alias rTime(8) = WDay 'assign the alias WDay to rTime(8)
Alias rTime(9) = DayOfYear 'assign the alias DayOfYear to rTime(9)
Public GrimmInput1 As String * 30 'read buffer for Grimm
Public GrimmInput2 As String * 30 'read buffer for Grimm
Public XX1 As String * 4, XX2 As String * 4 'Buffer for MSM and LSB of RTC values
'SerialOut(GrimmPort,"S","S",1,20) 'send S to stop measurement, wait 0.2s for Echo
SerialFlush(GrimmPort)
RealTime (rTime)
YY -= 2000
Sprintf(XX1,"%1s",Left(YY,1))
Sprintf(XX2,"%1s",Right(YY,1))
SerialOut(GrimmPort,"T",":",1,50) 'continues after first received character
SerialOut(GrimmPort,"",":",1,50) 'wait up to 500ms for ":"
'Delay(1,500,msec)
SerialOut(GrimmPort,XX1,"",1,50) 'send MSB of Year, wait 0.5s for echo
SerialOut(GrimmPort,XX2&Chr(13),"",1,50) 'send LSB of Year, wait 0.5s for echo
EndSub
'Main Program
BeginProg
SerialOpen (GrimmPort,9600,0,0,1000)' for Grimm164, 9600 8N1, 420 bytes/dataset every 10 minutes
SlowSequence
Scan (10,Sec,0,0)'10 sec Loop for Grimm
If SetTimeFlag Then
Call SetGrimmTime
SetTimeFlag = False
End If
NextScan
EndProg
The SerialOut() Instruction sends commands, but does not wait for the incoming string. The command
SerialOut(GrimmPort,"T",":",1,50) 'continues after first received character!
continues after receiving the first character of the string "T<CRLF>Year 18 :" whether i expected that execution is halted until timeout or receiption of ":".
Any ideas what's wrong?
Regards,
Bernhard
Using your program with the following line removed
SerialOut(GrimmPort,"",":",1,50) 'wait up to 500ms for ":"
On a CR1000 running OS 32.02, I saw the program wait for the ":" input. I also ran an exagerated version where the timeout was 50 seconds instead of 0.5 seconds. The logger would stop on the following line of code until I sent back a ":" character. I used RealTerm to send the "T<CRLF>YEAR 18 :" characters. Once the logger received the colon, it would immediately respond with "18<CR>"