How To Get Daqfactory To Resume A Valve In The Event Of Power Outage?


meerooo80

Recommended Posts

Here's the code:

 

//valve position "3000" is the open position, PILS sample
//valve position "0" is the closed position, background sample
device.Three_way_valve.Write("100r" + chr(13))
device.Three_way_valve.Write("3000g" + chr(13))
//valve position opened for 23.5 hrs/day
//valve position closed for 30min/day
 
private nexttime = 23h00
if (systime() > nexttime)
   nexttime += 86400
endif
// open valve
private offTime = 1800 // 30 min /day off time
private loopTime = 86400 // once a day
device.Three_way_valve.Write("3000g" + chr(13))
private mode = 1  // 1 = open, 0 = closed
device.Three_way_valve.Purge()
while(1)
   try
      if (systime() > nexttime)
         if (mode == 1)
            try
               // close the valve
               device.Three_way_valve.Purge()
               device.Three_way_valve.Write("0g" + chr(13))
               device.Three_way_valve.Read(4)
               mode = 0
               nexttime += offTime
            catch()
               ? strLastError
            endcatch
         else
            try
               // open the valve
               device.Three_way_valve.Purge()
               device.Three_way_valve.Write("3000g" + chr(13))
               device.Three_way_valve.Read(4)
               mode = 1
               nexttime += loopTime - offTime
            catch()
               ? strLastError
            endcatch
         endif
      endif
   catch()
      ? strLastError
   endcatch
   delay(1)
endwhile

I use the nexttime variable to control when the next time an event should occur (open or closing of the valve), and the mode variable to keep track of whether I need to open or close the valve.  The internal try/catch blocks ensure that things happen even if the power goes off.  Note that if the power is off when an event occurs and stays off until the next event time (i.e. power is off from 10:59pm to 11:31pm), the sequence will do both events in rapid (1 second) succession once the power is restored.

Link to comment
Share on other sites

Here is the code I am using for testing the valve.

 

 
private nexttime = 02h15   // first time to switch
if (systime() > nexttime)
   nexttime += 10
endif
// open valve
private offTime = 20 // how long valve is off for,  30 min /day off time
private loopTime = 30   // total loop time (off + on time).  On time = looptime - offtime.  86400 = one day
device.Three_way_valve.Write("3000g" + chr(13))
private mode = 1  // 1 = open, 0 = closed
device.Three_way_valve.Purge()
while(1)
   try
      if (systime() > nexttime)
         if (mode == 1)
            try
               // close the valve
               device.Three_way_valve.Purge()
               device.Three_way_valve.Write("0g" + chr(13))
               device.Three_way_valve.Read(4)
               mode = 0
               nexttime += offTime
            catch()
               ? strLastError
            endcatch
         else
            try
               // open the valve
               device.Three_way_valve.Purge()
               device.Three_way_valve.Write("3000g" + chr(13))
               device.Three_way_valve.Read(4)
               mode = 1
               nexttime += loopTime - offTime
            catch()
               ? strLastError
            endcatch
         endif
      endif
   catch()
      ? strLastError
   endcatch
   logging.Three_way_valve_log.strFileName = "c:\DAQFactoryData\Three_way_valve_" + formatDateTime("%m.%d.%y", systime ()) + ".csv"
   position1=mode
   delay(1)
endwhile
Link to comment
Share on other sites

Do the commands appear at all in the comm monitor when the sequence is running?

 

nexttime += 10 really should stay as nexttime += 86400.  The way you have it, if its any time after 2:15am when you start the sequence you are basically going to have the valve switch back and forth every second until it catches up.

Link to comment
Share on other sites

Archived

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