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)
def run_master(hang=False): """Demonstrate hanging when channel and master are not deleted prior to manager.Shutdown() """ logger = asiodnp3.ConsoleLogger().Create() manager = asiodnp3.DNP3Manager(1, asiodnp3.ConsoleLogger().Create()) #printing_channel_listener = asiodnp3.PrintingChannelListener().Create() channel = manager.AddTCPClient("tcpclient", FILTERS, asiopal.ChannelRetry(), HOST, LOCAL, PORT, asiodnp3.PrintingChannelListener().Create()) stack_config = asiodnp3.MasterStackConfig() stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2) stack_config.link.RemoteAddr = 10 soe_handler = asiodnp3.PrintingSOEHandler().Create() default_master_app = asiodnp3.DefaultMasterApplication().Create() master = channel.AddMaster("master", soe_handler, default_master_app, stack_config) master.Enable() time.sleep(2) if not hang: #del logger #del printing_channel_listener del channel #del stack_config #del soe_handler #del default_master_app del master print("Shutdown, Hang = {}".format(hang)) manager.Shutdown()
def __init__( self, log_levels=opendnp3.levels.NORMAL | opendnp3.levels.ALL_APP_COMMS, host_ip="127.0.0.1", # presumably outstation local_ip="0.0.0.0", port=20000, log_handler=asiodnp3.ConsoleLogger().Create(), channel_listener=asiodnp3.PrintingChannelListener().Create(), soe_handler=asiodnp3.PrintingSOEHandler().Create(), master_application=asiodnp3.DefaultMasterApplication().Create(), stack_config=None): self.log_levels = log_levels self.host_ip = host_ip self.local_ip = local_ip self.port = port self.log_handler = log_handler self.channel_listener = channel_listener self.soe_handler = soe_handler self.master_application = master_application self.stackConfig = stack_config if not self.stackConfig: # The master config object for a master. self.stackConfig = asiodnp3.MasterStackConfig() self.stackConfig.master.responseTimeout = openpal.TimeDuration( ).Seconds(2) self.stackConfig.link.RemoteAddr = 10 self.manager = None self.channel = None self.master = None
def run_master(): # Root DNP3 object used to create channels and sessions manager = asiodnp3.DNP3Manager(1, asiodnp3.ConsoleLogger().Create()) # Connect via a TCPClient socket to an outstation channel = manager.AddTCPClient("tcpclient", FILTERS, asiopal.ChannelRetry(), HOST, LOCAL, PORT, asiodnp3.PrintingChannelListener().Create()) # Master config object for a master stack_config = asiodnp3.MasterStackConfig() stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2) stack_config.link.RemoteAddr = 10 # Add a master to a communication channel master = channel.AddMaster("master", asiodnp3.PrintingSOEHandler().Create(), asiodnp3.DefaultMasterApplication().Create(), stack_config) # Enable the master. This will start communications. master.Enable() return manager
def config_master(self): # Callback interface for log messages self.handler = LogHandler() # Root DNP3 object used to create channels and sessions self.manager = asiodnp3.DNP3Manager(1, self.handler) # Connect via a TCPClient socket to an outstation self.channel_listener = ChannelListener() self.channel = self.manager.AddTCPClient("tcpclient", FILTERS, asiopal.ChannelRetry(), HOST, LOCAL, PORT, self.channel_listener) # Master config object for a master stack_config = asiodnp3.MasterStackConfig() stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2) stack_config.link.RemoteAddr = 10 # Add a master to a communication channel self.master_application = MasterApplication() self.master = self.channel.AddMaster("master", asiodnp3.PrintingSOEHandler().Create(), self.master_application, stack_config) # Do an integrity poll (Class 3/2/1/0) once per minute self.integrity_scan = self.master.AddClassScan(opendnp3.ClassField().AllClasses(), openpal.TimeDuration().Minutes(1)) # Do a Class 1 exception poll every 5 seconds self.exception_scan = self.master.AddClassScan(opendnp3.ClassField(opendnp3.ClassField.CLASS_1), openpal.TimeDuration().Seconds(2)) # Enable the master. This will start communications. self.master.Enable()
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