Sequenc Stops Running


williamlynn

Recommended Posts

I have a sequence that is a continuous loop,(contains while(1) and endwhile). The loop runs for a short time and then stops. DAQFactory is running under VISTA and the problems occurs when screen saver starts. I have set all other "saver" functions to remain running, i.e. the hard drive, cpu etc do not shut down.

The logging function continues to log data but the continuous loop does not read incoming data. The incoming data is read from a file that is updated from another program.

Help appreciated.

Thanks

Bill

Link to comment
Share on other sites

There are no alarms or messages.

The script is:

while (1)
Private FileHandle = File.Open("C:\WEATHER_STATION_DATA\WJLDATA_40_TEST.TXT",1,0,0,1)
Private string strIn
   strIn = File.Read(FileHandle)
   // This checks for an empty string
   ? strIn
   if(strIn == "")
   // Breaks out if empty string
	  break
   endif
   // This code Parses the String and sets the output channel
   APRS_SPEED.AddValue(StrToDouble(Parse(strIn,0," ")))
   //? APRS_speed
   APRS_GUST.AddValue(StrToDouble(Parse(strIn,1," ")))
   //? APRS_gust
   APRS_DIR.AddValue(StrToDouble(Parse(strIn,2," ")))
   //? APRS_dir
   APRS_LIGHTNING.AddValue(StrToDouble(Parse(strIn,7," ")))
   //? APRS_LIGHTNING
   APRS_RAIN.AddValue(StrToDouble(Parse(strIn,6," ")))
   //? APRS_RAIN
   SCP_BAR.AddValue(StrToDouble(Parse(strIn,3," ")))
   ? SCP_BAR
   SCP_TEMP.AddValue(StrToDouble(Parse(strIn,4," ")))
   ? SCP_TEMP
   APRS_HUMIDITY.AddValue(StrToDouble(Parse(strIn,5," "))) 
   //? APRS_HUMIDITY
   // Reads 1 second at a time
   delay (1)
   // Closes the file
   File.Close(FileHandle)

Private FileHandle = File.Open("C:\WEATHER_STATION_DATA\WJLDATA_30_TEST.TXT",1,0,0,1)
Private string strIn
   strIn = File.Read(FileHandle)
   // This checks for an empty string
   ? strIn
   if(strIn == "")
   // Breaks out if empty string
	  break
   endif
   // This code Parses the String and sets the output channel
   AAG_TEMP.AddValue(StrToDouble(Parse(strIn,3," ")))
   ? AAG_TEMP
   AAG_SPEED.AddValue(StrToDouble(Parse(strIn,0," ")))
   //?AAG_SPEED
   AAG_GUST.AddValue(StrToDouble(Parse(strIn,1," ")))
   //? AAG_GUST
   AAG_DIR.AddValue(StrToDouble(Parse(strIn,2," ")))
   //? AAG_DIR
   // Reads 1 second at a time
   delay (1)

   // Closes the file
   File.Close(FileHandle)

Private FileHandle = File.Open("C:\WEATHER_STATION_DATA\WJLDATA_10_TEST.TXT",1,0,0,1)
Private string strIn
   strIn = File.Read(FileHandle)
   // This checks for an empty string
   ? strIn
   if(strIn == "")
   // Breaks out if empty string
	  break
   endif
   // This code Parses the String and sets the output channel
   INDOOR_BAR.AddValue(StrToDouble(Parse(strIn,2," ")))
   ? INDOOR_BAR
   INDOOR_HUM.AddValue(StrToDouble(Parse(strIn,1," ")))
   //?INDOOR_HUM
   INDOOR_TEMP.AddValue(StrToDouble(Parse(strIn,0," ")))
   //? INDOOR_TEMP
   // Reads 1 second at a time
   // delay (1)

   // Closes the file
   File.Close(FileHandle)
   delay (1)
endwhile

The length of time the script runs will vary and I have not been able to track down what causes it to stop!!! I stated in my first post that it seems to happen sometime after the screen goes into sleep mode but I cannot confirm how long after!

Thanks for the help!!

Link to comment
Share on other sites

The screen saver is likely a coincidence. You do have exits in your code that are probably triggering:

   if(strIn == "")
	 // Breaks out if empty string
	  break
   endif

This is in several places. You might want to a debugging line to see if its occuring:

   if(strIn == "")
	  // Breaks out if empty string
	  ? "strIn was empty"
	  break
   endif

Maybe make that ? statement slightly different for each of the 3 spots that break occurs.

The ? will print the string to the Command/Alert window.

Link to comment
Share on other sites

Yes; the breaks were causing the problem. I carried these over from the example in the manual.

Found another glitch; page 256 has an example of creating a new file each day. The example says to use delay(1m) which I assume is a typo; it should be delay(60).

Another question; Do you have code to find the last minute of the last day of a month or year so I can capture the data on that point and use it to calculate totals for the next month, year??

Your product is great and your service is the best I have found; keep up the good work.

Thanks Bill

Link to comment
Share on other sites

Thanks for pointing out the typo and your compliment.

Day/hour etc are easy because you can just use % 86400 or % 3600, but a particular day of the week, and of course month/year are harder since they are even multiples. I usually use the formatdatetime() function to figure out when the beginning of the month/year/week occurs. Typically I use this in a channel event. So, for example, to capture the value of a channel to a global variable at the end of the month, you would do:

if (formatdatetime("%m",mychan.time[0]) != formatdatetime("%m",mychan.time[1]))
   mycaptureddata = mychannel[1]
endif

Basically what I did was create a string containing just the month number for both the most recent and the next most recent data point of mychan. If they are different, then the month just ticked over, so I capture the next most recent data point (which is the last data point of last month). Of course I could capture the first data point of the current month by doing [0] in the assignment. Mycapturedata is presumably declared global elsewhere.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.