Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Serial I/O in a subroutine... Help!


MilfordRoadNewZealand Jan 28, 2009 04:18 AM

Hi folks,

I have tried to put the serial I/O instructions from the following sample of code into a subroutine, (in a CR1000) (as I have had to repeat this code about 25 times because of all of the different pager messages required). BUT when the programme breaks out to the subroutine to execute the serial instructions it never comes back to the main programme and the programme execution just stalls. As you can imagine it would be a lot tidier if I could put the common serial I/O stuff in a single subroutine and just populate the required variables in the main programme. The code works perfectly in the main scan. Am I missing something here?

If WL1Level1Alarm = -1 Then 'Do some alarm stuff as desired at WL1_LevelTrigger1...
WL1PagerCOM1String1_Reply = "" 'Set WL1PagerCOM1String1_Reply to null so that if no reply from pager router then last reply doesn't show.
WL1PagerCOM1String1_Send = "CA0000100 1 WL1Level1Alarm River Level " & Round(WL1_AvRunCurrent_30s,1) & "m. RateChange = " & Round(WL1RateChange1NonABS*2,3) & "m/minute. " & Round(CR1000_Batt_Volts,1) & "V. " & Time_DateAndTime_2
SerialOut (Com1,WL1PagerCOM1String1_Send+CHR(13),"",0,0) ''PagerTXT1_SEND = ""
SerialIn (WL1PagerCOM1String1_Reply,Com1,30,"",100)
WL1PagerCOM1String1_Reply_Left9 = Left (WL1PagerCOM1String1_Reply,9) 'Remove da non-printing characters at da end of da pager reply.
WL1PagerActivity1 = 1
CallTable CleddauRiver1_Alarm1
WL1PagerActivity1 = 0
WL1Level1Alarm = 0
If WL1PagerCOM1String1_Reply_Left9 <> WL1PagerCOM1String2_Reply_Page_Sent Then
WL1Level1Alarm = -1 'Re-enable WL1Level0Alarm if no ""Page Sent"" reply from da pager router.
WL1Level1AlarmRetryCounter = WL1Level1AlarmRetryCounter + 1
EndIf
EndIf

Thanks in advance, first time using the forum, what an excellent idea.
Cheers
Stewart

* Last updated by: MilfordRoadNewZealand on 1/27/2009 @ 9:44 PM *


Dana Jan 28, 2009 07:36 PM

Is there something in this code that keeps the program from exiting the sub?

If WL1PagerCOM1String1_Reply_Left9 <> WL1PagerCOM1String2_Reply_Page_Sent Then
WL1Level1Alarm = -1 'Re-enable WL1Level0Alarm if no ""Page Sent"" reply from da pager router.
WL1Level1AlarmRetryCounter = WL1Level1AlarmRetryCounter + 1
EndIf


How/where is WL1PagerCOM1String2_Reply_Page_Sent getting set?

To troubleshoot, change the IF statement condition above to something you can control, such as "If Flag(1) = True", then see if the program exits when False and stays in the loop if you Toggle the flag True. Also, monitor WL1Level1Alarm to see if/when it goes to 0 (and thus should exit the subroutine).

Dana

Log in or register to post/reply in the forum.