Switch Solenoids using pulse outputs and polarity changes...
-
Gidday Guys, here is a challenge for you guys...
I have only 3 outputs available on my Moxa unit to use for solenoid switching, I have 3 solenoids to switch to shift water in 3 different directions.
One solenoid must always be open at all times if the pump is running or else the pump will blow the line.The problem is, the solenoids are latching types, so they need a +ve pulse to switch on and -ve pulse to switch off.
So I had a colleague assist with the attached diagram.Now I need to work out how to get Mango to send a pre-selection out to the polarity relays and then send the pulse to the solenoids to do the switching :-P
Any assistance with a script would be great, thankyou, I'm still getting the hang of it.Cheers
DanAttachment: download link
-
I'm not sure this is enough information to really help you. Make a list of the inputs and out puts that will be in Mango. Then write out the logic that you want to happen and we could turn that into a script for you. Maybe if you label this diagram a bit better it will also help. How long does the pulse need to be?
Thanks,
Joel. -
Thanks Joel, I'll put that up shortly..
Cheers
Dan -
ok, here go's.
I'm not sure how to address the outputs.. I've attached a screenshot of the outputs as their listed in Mango.
I've marked up on the original diagram which outputs are connected to the solenoid matrix.
The input marked STATUS (DI0) tells us when the pump is running either via Mango or via the Bypass switch (it just reads the status of the mains relay running the pump)
I've also attached a couple of other photos. Hope this helps.Cheers
Attachment: download link
-
The logic part...
So on my graphical overview there is a branch where the user can select one of 3 solenoids to switch. They are currently 3 red T's shown, they turn green when pressed with the following script and directly set the output to 1. This worked with the old solenoids where they were momentary, so flow was on when there was power there. The new solenoids are toggle pulse.
var s = ""; s += "<a href='#' onclick='mango.view.setPoint("+ point.id +", \""+ pointComponent.id +"\", \""+ !value +"\");return false;'>"; if (value) s += "<img onclick='mango.view.setPoint("+ point.id +", \""+ pointComponent.id +"\", \"false\");return false;'/ style='cursor:pointer;' src='modules/sstGraphics/web/graphics/Valves/ValveOn.png'>"; else s += "</><img style='cursor:pointer;' src='modules/sstGraphics/web/graphics/Valves/ValveOff.png'>"; s += "</a>"; return s;
Each one will turn on that direction solenoid and switch off the others, which should happen within the relay control logic.
The output pulse should only be about a second.Hope I've explained everything.
Attachment: download link
-
From what I can tell anytime a valve is set to on you just need to turn it off.
Here is some JSON you can import for the Scripting Data Source that has a simple example of this. There is a data point called valve-1. Add this point to a watch list and set it to open. You'll see it open and then turn off again. If you replace the valve-1 data point with the actual datapoint the same thing will happen any time it turns on. The script runs every 5 seconds which could probably reduce if you need to.
{ "dataSources":[ { "xid":"DS_168518", "name":"Pulse Test Script", "enabled":true, "type":"SCRIPTING", "alarmLevels":{ "SCRIPT_ERROR":"URGENT", "DATA_TYPE_ERROR":"URGENT", "LOG_ERROR":"URGENT" }, "purgeType":"YEARS", "context":[ ], "logLevel":"NONE", "cronPattern":"0\/5 * * * * ?", "executionDelaySeconds":0, "historicalSetting":false, "script":"if (valve1.value == true)\n{\nvalve1.set(false)\n}", "purgeOverride":true, "purgePeriod":1 } ], "dataPoints":[ { "xid":"DP_185394", "name":"valve-1", "enabled":true, "loggingType":"ON_CHANGE", "intervalLoggingPeriodType":"MINUTES", "intervalLoggingType":"INSTANT", "purgeType":"YEARS", "pointLocator":{ "dataType":"BINARY", "settable":true, "varName":"valve1" }, "eventDetectors":[ ], "plotType":"STEP", "unit":"", "chartColour":"", "chartRenderer":{ "type":"TABLE", "limit":10 }, "dataSourceXid":"DS_168518", "defaultCacheSize":1, "deviceName":"Pulse Test Script", "discardExtremeValues":false, "discardHighLimit":0.0, "discardLowLimit":0.0, "intervalLoggingPeriod":15, "intervalLoggingSampleWindowSize":0, "overrideIntervalLoggingSamples":false, "purgeOverride":true, "purgePeriod":1, "textRenderer":{ "type":"BINARY", "oneColour":null, "oneLabel":"Open", "zeroColour":null, "zeroLabel":"Closed" }, "tolerance":0.0 } ] }
-
Thanks Joel I'll see if I can work through that.
Cheers
Dan -
Hey Guys, I couldn't the script to work the way I intended.
I've attached a logical sort of script hopefully this makes more sense?//OUTPUT 1 - WEST/NORTH //OUTPUT 2 - SOUTH //OUTPUT 3 - PULSE ON/OFF //OUTPUT 4 - PUMP RUN/STOP //INPUT 1 - NORTH TANK LEVEL 1 //INPUT 2 - SOUTH TANK LEVEL 2 //INPUT 3 - PUMP RUN/STOP INDICATION IF NORTH SOLENOID IMAGE IS CLICKED{ CHECK IF PUMP IS ALREADY DOING SOMETHING ELSE{ SWITCH OUTPUT 1 ON PULSE OUTPUT 3 IF INPUT 3 OFF{ WHILE INPUT 1 LEVEL < 100%{ SWITCH OUTPUT 4 ON } } } } IF SOUTH SOLENOID IMAGE IS CLICKED{ CHECK IF PUMP IS ALREADY DOING SOMETHING ELSE{ SWITCH OUTPUT 2 ON PULSE OUTPUT 3 IF INPUT 2 OFF{ WHILE INPUT 2 LEVEL < 100%{ SWITCH OUTPUT 4 ON } } } }
I would have on the graphical view either a virtual point to set to kick each solenoid change off, or maybe just set the script?
I'd like ideally to have a queue type setup where each of the tanks in the system could be in an appropriate order?The main thing I can't work out is the correct syntax for this type of scripting in Mango.
Cheers
Dan -
Hi Dan,
Currently the only supported scripting engine is JavaScript. On top of that there are hooks for the Mango functions to get and manipulate point values. This documentation can be found in the meta point properties help dialogue, or here: http://wiki.infiniteautomation.com/doku.php?id=meta_data_properties starting at the 'Scripts' header.