Exemplo n.º 1
0
    def __init__(
            self,
            log_handler=asiodnp3.ConsoleLogger().Create(),
            listener=asiodnp3.PrintingChannelListener().Create(),
            soe_handler=asiodnp3.PrintingSOEHandler().Create(),
            master_application=asiodnp3.DefaultMasterApplication().Create(),
            stack_config=None):

        _log.debug('Creating a DNP3Manager.')
        self.log_handler = log_handler
        self.manager = asiodnp3.DNP3Manager(1, self.log_handler)

        _log.debug('Creating the DNP3 channel, a TCP client.')
        self.retry = asiopal.ChannelRetry().Default()
        self.listener = listener
        self.channel = self.manager.AddTCPClient("tcpclient", FILTERS,
                                                 self.retry, HOST, LOCAL, PORT,
                                                 self.listener)

        _log.debug('Configuring the DNP3 stack.')
        self.stack_config = stack_config
        if not self.stack_config:
            self.stack_config = asiodnp3.MasterStackConfig()
            self.stack_config.master.responseTimeout = openpal.TimeDuration(
            ).Seconds(2)
            self.stack_config.link.RemoteAddr = 10

        _log.debug('Adding the master to the channel.')
        self.soe_handler = soe_handler
        self.master_application = master_application
        self.master = self.channel.AddMaster(
            "master",
            asiodnp3.PrintingSOEHandler().Create(), self.master_application,
            self.stack_config)

        _log.debug('Configuring some scans (periodic reads).')
        # Set up a "slow scan", an infrequent integrity poll that requests events and static data for all classes.
        self.slow_scan = self.master.AddClassScan(
            opendnp3.ClassField().AllClasses(),
            openpal.TimeDuration().Minutes(30),
            opendnp3.TaskConfig().Default())
        # Set up a "fast scan", a relatively-frequent exception poll that requests events and class 1 static data.
        self.fast_scan = self.master.AddClassScan(
            opendnp3.ClassField(opendnp3.ClassField.CLASS_1),
            openpal.TimeDuration().Minutes(1),
            opendnp3.TaskConfig().Default())

        self.channel.SetLogFilters(
            openpal.LogFilters(opendnp3.levels.ALL_COMMS))
        self.master.SetLogFilters(openpal.LogFilters(
            opendnp3.levels.ALL_COMMS))

        _log.debug(
            'Enabling the master. At this point, traffic will start to flow between the Master and Outstations.'
        )
        self.master.Enable()
        time.sleep(5)
Exemplo n.º 2
0
 def do_write_time(self, line):
     """Write a TimeAndInterval to the Outstation. Command syntax is: write_time"""
     millis_since_epoch = int(
         (datetime.now() - datetime.utcfromtimestamp(0)).total_seconds() *
         1000.0)
     self.application.master.Write(
         opendnp3.TimeAndInterval(opendnp3.DNPTime(millis_since_epoch), 100,
                                  opendnp3.IntervalUnits.Seconds),
         0,  # index
         opendnp3.TaskConfig().Default())
Exemplo n.º 3
0
 def do_disable_unsol(self, line):
     """Perform the function DISABLE_UNSOLICITED. Command syntax is: disable_unsol"""
     headers = [
         opendnp3.Header().AllObjects(60, 2),
         opendnp3.Header().AllObjects(60, 3),
         opendnp3.Header().AllObjects(60, 4)
     ]
     self.application.master.PerformFunction(
         "disable unsolicited", opendnp3.FunctionCode.DISABLE_UNSOLICITED,
         headers,
         opendnp3.TaskConfig().Default())
Exemplo n.º 4
0
    def send_select_and_operate_command_set(
        self,
        command_set,
        callback=asiodnp3.PrintingCommandCallback.Get(),
        config=opendnp3.TaskConfig().Default()):
        """
            Select and operate a set of commands

        :param command_set: set of command headers
        :param callback: callback that will be invoked upon completion or failure
        :param config: optional configuration that controls normal callbacks and allows the user to be specified for SA
        """
        self.master.SelectAndOperate(command_set, callback, config)
Exemplo n.º 5
0
    def send_direct_operate_command(
        self,
        command,
        index,
        callback=asiodnp3.PrintingCommandCallback.Get(),
        config=opendnp3.TaskConfig().Default()):
        """
            Direct operate a single command

        :param command: command to operate
        :param index: index of the command
        :param callback: callback that will be invoked upon completion or failure
        :param config: optional configuration that controls normal callbacks and allows the user to be specified for SA
        """
        self.master.DirectOperate(command, index, callback, config)
Exemplo n.º 6
0
 def test_default_constructors(self):
     """
         Create the class object with default values for instance variable and test if the object is not empty.
     """
     assert asiodnp3.ConsoleLogger() is not None
     assert asiodnp3.DefaultListenCallbacks() is not None
     assert asiodnp3.DefaultMasterApplication() is not None
     assert asiodnp3.MasterStackConfig() is not None
     assert asiodnp3.PrintingChannelListener is not None
     assert asiodnp3.PrintingSOEHandler() is not None
     assert asiodnp3.UpdateBuilder() is not None
     assert asiopal.ChannelRetry() is not None
     assert asiopal.ResourceManager() is not None
     assert asiopal.SerialSettings() is not None
     assert asiopal.steady_clock_t() is not None
     assert opendnp3.AnalogCommandEvent() is not None
     assert opendnp3.AnalogOutputInt16() is not None
     assert opendnp3.AnalogOutputInt32() is not None
     assert opendnp3.AnalogOutputFloat32() is not None
     assert opendnp3.AnalogOutputDouble64() is not None
     assert opendnp3.BinaryCommandEvent() is not None
     assert opendnp3.ClassField() is not None
     assert opendnp3.ControlRelayOutputBlock() is not None
     assert opendnp3.DNPTime() is not None
     assert opendnp3.Flags() is not None
     assert opendnp3.GroupVariationID() is not None
     assert opendnp3.IndexedBinary() is not None
     assert opendnp3.IndexedDoubleBitBinary() is not None
     assert opendnp3.IndexedAnalog() is not None
     assert opendnp3.IndexedCounter() is not None
     assert opendnp3.IndexedFrozenCounter() is not None
     assert opendnp3.IndexedBinaryOutputStatus() is not None
     assert opendnp3.IndexedAnalogOutputStatus() is not None
     assert opendnp3.IndexedOctetString() is not None
     assert opendnp3.IndexedTimeAndInterval() is not None
     assert opendnp3.IndexedBinaryCommandEvent() is not None
     assert opendnp3.IndexedAnalogCommandEvent() is not None
     assert opendnp3.IndexedSecurityStat() is not None
     assert opendnp3.IndexedControlRelayOutputBlock() is not None
     assert opendnp3.IndexedAnalogOutputInt16() is not None
     assert opendnp3.IndexedAnalogOutputInt32() is not None
     assert opendnp3.IndexedAnalogOutputFloat32() is not None
     assert opendnp3.IndexedAnalogOutputDouble64() is not None
     assert opendnp3.Binary() is not None
     assert opendnp3.DoubleBitBinary() is not None
     assert opendnp3.BinaryOutputStatus() is not None
     assert opendnp3.Analog() is not None
     assert opendnp3.Counter() is not None
     assert opendnp3.FrozenCounter() is not None
     assert opendnp3.AnalogOutputStatus() is not None
     assert opendnp3.TimeAndInterval() is not None
     assert opendnp3.OctetData() is not None
     assert opendnp3.OctetString() is not None
     assert opendnp3.SecurityStat() is not None
     assert opendnp3.LinkHeaderFields() is not None
     assert opendnp3.LinkStatistics() is not None
     assert opendnp3.CommandSet() is not None
     assert opendnp3.HeaderInfo() is not None
     assert opendnp3.StartStopRangeUint8() is not None
     assert opendnp3.StartStopRangeUint16() is not None
     assert opendnp3.CountUint8() is not None
     assert opendnp3.CountUint16() is not None
     assert opendnp3.HeaderUnion() is not None
     assert opendnp3.Header() is not None
     assert opendnp3.MasterParams() is not None
     assert opendnp3.RestartOperationResult() is not None
     assert opendnp3.TaskConfig() is not None
     assert opendnp3.ApplicationIIN() is not None
     assert opendnp3.DatabaseSizes() is not None
     assert opendnp3.EventBufferConfig() is not None
     assert opendnp3.OutstationConfig() is not None
     assert opendnp3.OutstationParams() is not None
     assert opendnp3.StaticTypeBitField() is not None
     assert opendnp3.StackStatistics() is not None
     assert opendnp3.IINField() is not None
     assert openpal.ArrayBinaryConfig() is not None
     assert openpal.ArrayDoubleBitBinaryConfig() is not None
     assert openpal.ArrayAnalogConfig() is not None
     assert openpal.ArrayCounterConfig() is not None
     assert openpal.ArrayFrozenCounterConfig() is not None
     assert openpal.ArrayBOStatusConfig() is not None
     assert openpal.ArrayAOStatusConfig() is not None
     assert openpal.ArrayTimeAndIntervalConfig() is not None
     assert openpal.ArrayBuffer() is not None
     assert openpal.ArrayViewBinaryConfig() is not None
     assert openpal.ArrayViewDoubleBitBinaryConfig() is not None
     assert openpal.ArrayViewAnalogConfig() is not None
     assert openpal.ArrayViewCounterConfig() is not None
     assert openpal.ArrayViewFrozenCounterConfig() is not None
     assert openpal.ArrayViewBOStatusConfig() is not None
     assert openpal.ArrayViewAOStatusConfig() is not None
     assert openpal.ArrayViewTimeAndIntervalConfig() is not None
     assert openpal.ArrayViewBuffer() is not None
     assert openpal.Buffer() is not None
     assert openpal.RingBuffer16() is not None
     assert openpal.RSlice() is not None
     assert openpal.SecureBuffer() is not None
     assert openpal.SettableRSlice() is not None
     assert openpal.SettableWSlice() is not None
     assert openpal.StaticBuffer4() is not None
     assert openpal.StaticBuffer14() is not None
     assert openpal.StaticBuffer100() is not None
     assert openpal.StaticBuffer292() is not None
     assert openpal.WSlice() is not None
     assert openpal.MonotonicTimestamp() is not None
     assert openpal.TimeDurationBase() is not None
     assert openpal.TimeDuration() is not None
     assert openpal.UTCTimestamp() is not None
     assert openpal.LogFilters() is not None
     assert openpal.Logger() is not None
     assert openpal.SerializerBinary() is not None
     assert openpal.SerializerDoubleBitBinary() is not None
     assert openpal.SerializerBinaryOutputStatus() is not None
     assert openpal.SerializerAnalog() is not None
     assert openpal.SerializerCounter() is not None
     assert openpal.SerializerFrozenCounter() is not None
     assert openpal.SerializerAnalogOutputStatus() is not None
     assert openpal.SerializerTimeAndInterval() is not None
     assert openpal.SerializerAnalogOutputInt16() is not None
     assert openpal.SerializerAnalogOutputInt32() is not None
     assert openpal.SerializerAnalogOutputFloat32() is not None
     assert openpal.SerializerAnalogOutputDouble64() is not None
Exemplo n.º 7
0
 def open(self):
     
     self._master.Enable()
     self._master.AddClassScan(opendnp3.ClassField().AllClasses(),
                                                       openpal.TimeDuration().Minutes(30),
                                                       opendnp3.TaskConfig().Default())
Exemplo n.º 8
0
# Create the manager for DNP3. This is always the first thing you
# need to do for OpenDNP3.
log_handler = asiodnp3.ConsoleLogger().Create()
manager = asiodnp3.DNP3Manager(1, log_handler)
retry = asiopal.ChannelRetry().Default()
listener = asiodnp3.PrintingChannelListener().Create()
channel = manager.AddTCPClient('client', opendnp3.levels.NOTHING, retry,
                               '192.168.69.166', '0.0.0.0', 20000, listener)

soe_handler = SOEHandler()
soe_handler.values = values

master_application = asiodnp3.DefaultMasterApplication().Create()
stack_config = asiodnp3.MasterStackConfig()
stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2)
stack_config.link.RemoteAddr = 10
master = channel.AddMaster('master', soe_handler, master_application,
                           stack_config)
master.Enable()

time.sleep(SLEEP_SECONDS)

while (1):
    time.sleep(10)
    master.AddClassScan(opendnp3.ClassField().AllClasses(),
                        openpal.TimeDuration().Minutes(30),
                        opendnp3.TaskConfig().Default())
    values = soe_handler.values
    print(
        f"Analog Value Count: {len(values['analog'])}  Binary: {len(values['binary'])}"
    )
Exemplo n.º 9
0
 def do_scan_range(self, line):
     """Do an ad-hoc scan of a range of points (group 1, variation 2, indexes 0-3). Command syntax is: scan_range"""
     self.application.master.ScanRange(opendnp3.GroupVariationID(1, 2), 0,
                                       3,
                                       opendnp3.TaskConfig().Default())
Exemplo n.º 10
0
 def do_scan_all(self, line):
     """Call ScanAllObjects. Command syntax is: scan_all"""
     self.application.master.ScanAllObjects(opendnp3.GroupVariationID(2, 1),
                                            opendnp3.TaskConfig().Default())