meerooo80 Posted April 16, 2014 Share Posted April 16, 2014 I'm trying to control a valve automatically, off for 30 minutes each day at 11pm. I also need to make sure the sequence stays running if the power goes off to the valve. How do I do this? Link to comment Share on other sites More sharing options...
AzeoTech Posted April 16, 2014 Share Posted April 16, 2014 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 More sharing options...
meerooo80 Posted April 21, 2014 Author Share Posted April 21, 2014 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 More sharing options...
AzeoTech Posted April 21, 2014 Share Posted April 21, 2014 That's because you have the first time set to 2h15 which is 2:15am. Judging from the time of your post, I'm guessing you really want 14h15. Link to comment Share on other sites More sharing options...
meerooo80 Posted April 21, 2014 Author Share Posted April 21, 2014 well I have checked it using military time and it is not working either. Link to comment Share on other sites More sharing options...
AzeoTech Posted April 21, 2014 Share Posted April 21, 2014 Look in the comm monitor and see if the command are going out the serial port and if the device is responding. Also look for alerts. Link to comment Share on other sites More sharing options...
meerooo80 Posted April 21, 2014 Author Share Posted April 21, 2014 The valve is responding when I give it commands on the comm monitor, yet not with the code at hand. No alerts. Link to comment Share on other sites More sharing options...
AzeoTech Posted April 21, 2014 Share Posted April 21, 2014 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.