• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Switch Solenoids using pulse outputs and polarity changes...

    Scripting general Discussion
    3
    10
    3.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • danD
      dan
      last edited by

      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
      Dan

      Attachment: download link

      1 Reply Last reply Reply Quote 0
      • JoelHaggarJ
        JoelHaggar
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • danD
          dan
          last edited by

          Thanks Joel, I'll put that up shortly..

          Cheers
          Dan

          1 Reply Last reply Reply Quote 0
          • danD
            dan
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • danD
              dan
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • JoelHaggarJ
                JoelHaggar
                last edited by

                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
                      }
                   ]
                }
                
                1 Reply Last reply Reply Quote 0
                • danD
                  dan
                  last edited by

                  Thanks Joel I'll see if I can work through that.

                  Cheers
                  Dan

                  1 Reply Last reply Reply Quote 0
                  • danD
                    dan
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • phildunlapP
                      phildunlap
                      last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post