Tag Archive: relay outputs

You can easily pulse an output using Tasker.  From an open Workspace you will click + Add Action… to get the Add Action dialog.  From there you will select Pulse Relay (channel, duration).

Once the action has been added you will need to configure the correct channel and duration.

Series 4 JNIORs have a varying amount of inputs and outputs depending on what model you have. The 410 has 8 inputs and 8 outputs, the 412 and 412DMX have 4 inputs and 12 outputs, and the 414 has 12 inputs and 4 outputs. Each relay contact rating is 1A @ 24VDC and the voltage source must be in the range of 5 – 30V AC or DC. The JNIOR uses a 2-piece terminal connector system for all power and I/O wiring connections allowing for easy installation and/or removal of the JNIOR.

Controlling Relay Outputs

When controlling the JNIOR’s I/O, the JANOS class can be used to get/manipulate their statuses. In the following example the JANOS class is used to pulse outputs, get the output states mask, check the status of an output, and check an outputs usage meter.

View on GitHub

I put the built jar file of this example application into the JNIOR’s flash folder and ran it from the Web UI’s console tab. As you can see it displays different data about the outputs at the time of the application running.

Getting Outputs from the IO Log

Another way to interact with the I/O on the JNIOR is via the Iolog Monitor. The Iolog Monitor is an object that can be checked for I/O events that have occurred on the JNIOR. There is the IoEvent class and Iolog class. An IoEvent is when an input or output state changed on the JNIOR, and the Iolog is an object that contains all the IoEvents from a certain timestamp. The example below pulses an output, and then shows how the Iolog has recorded that output pulse as an IoEvent.

View on GitHub

I put the built jar file of this example application into the JNIOR’s flash folder and ran it from the Web UI’s console tab. As you can see it recorded the output change where output 8 turned on and again when it turned back off.

When the JNIOR Boots up we may want to define an initial state.  Sure, the JNIOR WebUI gives you a way to configure this for the Internal Outputs.  Setting a value of ZERO causes the relay to get close while a value greater than ZERO is the number of milliseconds to pulse the relay for.

But what about the Outputs on the External Modules?

An application like this is extremely easy to write.  You can set the states for up to 16 outputs using the .setOutputStates(bits, mask) in the JANOS Runtime Library.

How do we know what outputs to set you ask?  Well we will take an argument that supplies a mask containing which outputs to close.  The mask can be represented as HEX or DECIMAL.  To specify the mask in HEX we must prefix the value with 0x.  For example, flash/closeoutputsonboot 0x7 will close outputs 1, 2, and 3 when the application executes.

Here is the code for this application.

package closeoutputsonboot;

import com.integpg.system.JANOS;
import java.io.IOException;

public class CloseOutputsOnBoot {

    public static void main(String[] args) throws IOException {
        // make sure one argument was supplied
        if (1 != args.length) {
            // print the usage string to the stdout.  This isnt useful when the 
            // application is executed on boot.  So we will also log it to the 
            // syslog in case the argument is not supplied in the run key.   Then
            // exit with -1 indicating an error occurred.
            String usage = "MUST supply an argument that contains the "
                    + "MASK of OUTPUTS that should be closed.";
            System.out.println(usage);
            JANOS.syslog(usage);
            System.exit(-1);
        }

        // get the binary mask and set the ALL of the output states.  we 
        // allow the mask to be specified in HEX or DECIMAL
        int binaryMask;
        if (args[0].startsWith("0x")) {
            // HEX representation
            binaryMask = Integer.valueOf(args[0].substring(2), 16);
        } else {
            // DECIMAL representation
            binaryMask = Integer.valueOf(args[0]);
        }

        JANOS.setOutputStates(binaryMask, 0xffff);
    }

}

To get this application to run on boot we set a run key. My run key will close output 13 on boot. I chose to specify the mask in hexadecimal. This will cause the application to execute on boot for a brief period of time while is reads the mask argument and sets the outputs. Once that has been completed the application will finish.

The JAR file below can be loaded into the flash/ directory on the JNIOR.

Name Version Release Date Size MD5
CloseOutputsOnBoot.jar v1.0 Jul 01 2021 2.0 KB 774c7b1cb6a7dda818ee02c2242ada13

This application will monitor the digital inputs.  The corresponding output is set when an input pulsed.  That output remains active until a different input is pulsed.  This application effectively latches the output to represent the last input that transitioned from low to high.

package com.integ.latchrelays;

import com.integpg.system.IoEvent;
import com.integpg.system.Iolog;
import com.integpg.system.JANOS;
import java.io.IOException;
import java.util.Date;

/**
 * This application will monitor the digital inputs. The corresponding output is set
 * when an input pulsed. That output remains active until a different input is pulsed.
 * This application effectively latches the output to represent the last input that
 * transitioned from low to high.
 */
public class LatchRelaysMain {

    public static void main(String[] args) throws InterruptedException, IOException {

        // create an Iolog instance and a timestamp representing the last time an 
        // event occurred.  we will start with a value of zero indicating only new events
        Iolog iolog = new Iolog();
        long timestamp = 0;

        // loop forever
        while (true) {

            // refresh the oilog with the timestamp of the last input event
            iolog.refresh(timestamp);
            IoEvent[] inputEvents = iolog.getInputEvents();

            // only process if there are events
            if (0 != inputEvents.length) {
                System.out.println("inputEvents.length = " + inputEvents.length);

                // loop through the input events
                for (int i = 0; i < inputEvents.length; i++) {
                    IoEvent inputEvent = inputEvents[i];
                    timestamp = inputEvent.timestamp;
                    System.out.println("timestamp = " + new Date(timestamp));
                    int highTransitions = inputEvent.mask & inputEvent.states;
                    boolean isTransitionHigh = (0 != highTransitions);
                    System.out.println("isTransitionHigh = " + isTransitionHigh);

                    // if the event was a transition high then set the outputs to 
                    // represent the state of the inputs that transitioned from 
                    // low to high.  we will use all outputs here
                    if (isTransitionHigh) {
                        JANOS.setOutputStates(highTransitions, 0xff);

                        // we are only looking to process the most recent inpput 
                        // transition from low to high.  so once we find one we 
                        // can abort the loop.
                        break;
                    }
                }
            }

            // sleep for a little bit of time to not monopolize the CPU
            Thread.sleep(50);
        }

    }

}

At some point you may want your JNIOR to always have an output close or pulse, and when you reboot a JNIOR, they get reset. This post will show you how to have your JNIOR automatically close outputs from startup. If you’re looking for different information on the DCP, or don’t know how to access it, you can look here.

To start, make sure you are able to access the DCP (Dynamic Configuration Page) of your JNIOR. Then you’ll want to go to the Configuration tab of the DCP. Here we will be accessing the outputs section.

Configuration tab in JNIOR Web Page

Here is where you can close or pulse outputs on startup. Simply add a zero to the Initial Action section for whichever channel you wish to close, and it will now always close that input on startup. To pulse the output on startup, simply add any positive value and it will pulse for that many milliseconds instead.

This sample shows you how to pulse multiple outputs and a single output. The method must take two binary masks. One describing the desired states during the pulse and the other describing which channels will be pulsed.

package com.integpg;
import com.integpg.system.JANOS;
public class PulseOutputs {
    public static void main(String[] args) {
        // to get the states of the outputs use the JANOS class and the getOutputStates method
        int outputStates = JANOS.getOutputStates();
        //print the Output States through telnet (console) connection.
        System.out.println("Output States are: " + outputStates);
        //Pulse 8 Relay Outputs On for 5 seconds (5000 milliseconds) after which outputs will return to previous state.
        //All channels (1111 1111b)
        JANOS.setOutputPulsed(255, 255, 5000);
        //Sleep 10 seconds to so that there is a noticable difference between on and off states.
        try {
            Thread.sleep(10000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
        int counter = 0;
        while(counter&lt;5){
        //Pulse Channel 5 Relay Output On for 5 seconds (5000 milliseconds) after which output will return to previous state.
        //Channels   8765 4321
        //Channel 5 (0001 0000b)
        JANOS.setOutputPulsed(16, 16, 5000);
            try {
                Thread.sleep(10000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            counter++;
            System.out.println("Counter: " + counter);
        }
    }
}

Write Outputs

Sometimes you want to control the outputs. The outputs may be wired to things like lights, sirens, valves and maybe fans. (Note: You may need our Power 4 Relay Output Module for high loads).  This example will show you how to set the output states programmatically.

package com.integpg;
import com.integpg.system.JANOS;
public class WriteOutputs {
    public static void main(String[] args) {

        // to get the states of the outputs use the JANOS class and the getOutputStates method
        int outputStates = JANOS.getOutputStates();

        //print the Output States through telnet (console) connection.
        System.out.println("Output States are: " + outputStates);

        //set output relay for channel 5 (channel n-1) and true top turn the relay on, false to turn relay off.
        JANOS.setOutputRelay(4 , true);

        //Relay Output 5 should now be on.
        //print the Output States through telnet (console) connection.
        System.out.println("Output States are: " + outputStates);
    }
}