beautypg.com

Campbell Scientific 0871LH1 Freezing Rain Sensor User Manual

Page 17

background image

14

'update the byte count

Old_Byte_Count = LH1_Byte_Count

'reset and start the timer

Timer (1,mSec,2)

'Received at least one byte start checking for a blank time

CheckForBlankTime = True
EndIf

'Obtain the time from the last byte.

TimeSinceLastByte = Timer (1,mSec,4)

If CheckForBlankTime = True Then

'If no characters occur within 100 msec of last byte then assume end of packet.

If TimeSinceLastByte > 100 Then Stay_In_Loop = False
EndIf

'Exit regardless if more than 3 seconds elapse

If TimeSinceLastByte > 3000 Then
LH1_Serial_Error = True
Stay_In_Loop = False
EndIf

Wend

If LH1_Serial_Error = False Then
'Flush the buffer
SerialFlush (LH1_comport)

'Wait a mximum of 2 seconds

If Timer (2,mSec,4) > 2000 Then
LH1_Serial_Error = TRUE
Stay_In_Loop = False
EndIf

Wend

'Obtain a CheckSum and convert All Binary Values
LH1_CHECKSUM = 0
'Convert all the BINARY Values
For LoopCounter=1 To 24 Step 1
LH1_Byte(LoopCounter) = ASCII (LH1_Raw_In_Buff(1,1,LoopCounter))

If LoopCounter <> 24
LH1_CHECKSUM = LH1_CHECKSUM + LH1_Byte(LoopCounter)
EndIf
Next
LH1_CHECKSUM = LH1_CHECKSUM AND &B11111111
If LH1_CHECKSUM <> LH1_Byte(LoopCounter) Then LH1_Serial_Error = TRUE
EndIf

If LH1_Serial_Error = TRUE Then
Call LH1_Error_State
Else
'For LH1 Byte 1
'BIT 0 - Status Output
If (LH1_Byte(1) AND &B00000001) <> 0 Then
LH1_Status_Output = "Fail"
Else
LH1_Status_Output = "OK"
EndIf