Search in sources :

Example 1 with Slf4jChannelListener

use of net.solarnetwork.dnp3.util.Slf4jChannelListener in project solarnetwork-node by SolarNetwork.

the class OutstationDemo method run.

public static void run(DNP3Manager manager) throws Exception {
    // Create a tcp channel class that will connect to the loopback
    Channel channel = manager.addTCPServer("client", LogMasks.NORMAL | LogMasks.APP_COMMS, ServerAcceptMode.CloseNew, "127.0.0.1", 20000, new Slf4jChannelListener());
    // Create the default outstation configuration
    OutstationStackConfig config = new OutstationStackConfig(DatabaseConfig.allValues(5), EventBufferConfig.allTypes(50));
    // Create an Outstation instance, pass in a simple a command handler that responds successfully to everything
    Outstation outstation = channel.addOutstation("outstation", SuccessCommandHandler.getInstance(), DefaultOutstationApplication.getInstance(), config);
    outstation.enable();
    // all this stuff just to read a line of text in Java. Oh the humanity.
    String line = "";
    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);
    int i = 0;
    while (true) {
        System.out.println("Enter something to update a counter or type <quit> to exit");
        line = in.readLine();
        if (line.equals("quit"))
            break;
        else {
            OutstationChangeSet set = new OutstationChangeSet();
            set.update(new Counter(i, (byte) 0x01, 0), 0);
            outstation.apply(set);
            ++i;
        }
    }
}
Also used : Slf4jChannelListener(net.solarnetwork.dnp3.util.Slf4jChannelListener) Outstation(com.automatak.dnp3.Outstation) Counter(com.automatak.dnp3.Counter) InputStreamReader(java.io.InputStreamReader) OutstationChangeSet(com.automatak.dnp3.OutstationChangeSet) Channel(com.automatak.dnp3.Channel) OutstationStackConfig(com.automatak.dnp3.OutstationStackConfig) BufferedReader(java.io.BufferedReader)

Example 2 with Slf4jChannelListener

use of net.solarnetwork.dnp3.util.Slf4jChannelListener in project solarnetwork-node by SolarNetwork.

the class MasterDemo method run.

static void run(DNP3Manager manager) throws Exception {
    // Create a tcp channel class that will connect to the loopback
    Channel channel = manager.addTCPClient("client", LogMasks.NORMAL | LogMasks.APP_COMMS, ChannelRetry.getDefault(), "127.0.0.1", "0.0.0.0", 20000, new Slf4jChannelListener());
    // You can modify the defaults to change the way the master behaves
    MasterStackConfig config = new MasterStackConfig();
    // Create a master instance, pass in a simple singleton to print received values to the console
    Master master = channel.addMaster("master", PrintingSOEHandler.getInstance(), DefaultMasterApplication.getInstance(), config);
    // do an integrity scan every 2 seconds
    // master.addPeriodicScan(Duration.ofSeconds(2), Header.getIntegrity());
    master.enable();
    // all this cruft just to read a line of text in Java. Oh the humanity.
    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);
    while (true) {
        System.out.println("Enter something to issue a command or type <quit> to exit");
        String line = in.readLine();
        switch(line) {
            case ("quit"):
                return;
            case ("crob"):
                ControlRelayOutputBlock crob = new ControlRelayOutputBlock(ControlCode.LATCH_ON, (short) 1, 100, 100, CommandStatus.SUCCESS);
                master.selectAndOperateCROB(crob, 0).thenAccept(// asynchronously print the result of the command operation
                (CommandTaskResult result) -> System.out.println(result));
                break;
            case ("scan"):
                master.scan(Header.getEventClasses());
                break;
            default:
                System.out.println("Unknown command: " + line);
                break;
        }
    }
}
Also used : MasterStackConfig(com.automatak.dnp3.MasterStackConfig) Master(com.automatak.dnp3.Master) Slf4jChannelListener(net.solarnetwork.dnp3.util.Slf4jChannelListener) InputStreamReader(java.io.InputStreamReader) CommandTaskResult(com.automatak.dnp3.CommandTaskResult) Channel(com.automatak.dnp3.Channel) BufferedReader(java.io.BufferedReader) ControlRelayOutputBlock(com.automatak.dnp3.ControlRelayOutputBlock)

Aggregations

Channel (com.automatak.dnp3.Channel)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 Slf4jChannelListener (net.solarnetwork.dnp3.util.Slf4jChannelListener)2 CommandTaskResult (com.automatak.dnp3.CommandTaskResult)1 ControlRelayOutputBlock (com.automatak.dnp3.ControlRelayOutputBlock)1 Counter (com.automatak.dnp3.Counter)1 Master (com.automatak.dnp3.Master)1 MasterStackConfig (com.automatak.dnp3.MasterStackConfig)1 Outstation (com.automatak.dnp3.Outstation)1 OutstationChangeSet (com.automatak.dnp3.OutstationChangeSet)1 OutstationStackConfig (com.automatak.dnp3.OutstationStackConfig)1