pydnp3 icon indicating copy to clipboard operation
pydnp3 copied to clipboard

Unable to read values from outstation error : erminate called after throwing an instance of 'std::runtime_error' what(): Tried to call pure virtual function "ISOEHandler::Start" Aborted (core dumped) ?

Open Saleem344 opened this issue 4 years ago • 0 comments

Hi, I'm new to dnp3 I made a program to read values from outstation but I'm getting this error can anyone help me?? my code:

`from pydnp3 import asiodnp3, asiopal, opendnp3, openpal import time from visitors import *

FILTERS = opendnp3.levels.NORMAL | opendnp3.levels.ALL_COMMS HOST = "192.168.0.69" LOCAL = "0.0.0.0" PORT = 20000

class TestMaster:

def config_master(self):
    # Callback interface for log messages
    self.handler = asiodnp3.ConsoleLogger().Create()

    # 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 = asiodnp3.PrintingChannelListener().Create()
    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 = 1
    stack_config.link.LocalAddr = 2

    soe_handler = SOEHandler()

    # Add a master to a communication channel
    self.master_application = asiodnp3.DefaultMasterApplication().Create()
    self.master = self.channel.AddMaster("master",
                                        soe_handler,
                                        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 run_master(self, cmd=None):
    self.config_master()
    print('cmd---------------',cmd)

    if cmd == "r":
        # self.master.ScanRange(opendnp3.GroupVariationID(1, 2), 0, 3)
        self.master.ScanRange(opendnp3.GroupVariationID(1, 2),0,3)

    time.sleep(1)
    self.master = Disable()
    self.master = None
    self.channel = Shutdown()
    self.channel = None
    self.manager = Shutdown()

class VisitorIndexedBinaryOutputStatus(opendnp3.IVisitorIndexedBinaryOutputStatus): def init(self): super(VisitorIndexedBinaryOutputStatus, self).init() self.index_and_value = []

def OnValue(self, indexed_instance):
    self.index_and_value.append((indexed_instance.index, indexed_instance.value.value))

class SOEHandler(opendnp3.ISOEHandler): """ Override ISOEHandler in this manner to implement application-specific sequence-of-events behavior.

    This is an interface for SequenceOfEvents (SOE) callbacks from the Master stack to the application layer.
"""

def __init__(self):
    super(SOEHandler, self).__init__()

def Process(self, info, values):
    """
        Process measurement data.

    :param info: HeaderInfo
    :param values: A collection of values received from the Outstation (various data types are possible).
    """
    if (values.Count() == 4 and type(values) == opendnp3.ICollectionIndexedBinaryOutputStatus):
        class BOSVisitor(opendnp3.IVisitorIndexedBinaryOutputStatus):
            def __init__(self):
                super(BOSVisitor, self).__init__()
            def OnValue(self, indexed_instance):
                print(indexed_instance.index, indexed_instance.value.value)
        values.Foreach(BOSVisitor())


def Start(self):
    # This is implementing an interface, so this function
    # must be declared.
    pass

def End(self):
    # This is implementing an interface, so this function
    # must be declared.
    pass

if name == "main": # app = TestMaster().run_master(cmd="i") app = TestMaster().run_master(cmd="r")`

Output: ms(1609309568885) INFO manager - Starting thread (0) channel state change: OPENING ms(1609309568885) INFO tcpclient - Connecting to: 192.168.0.69 cmd--------------- r ms(1609309568889) INFO tcpclient - Connected to: 192.168.0.69 channel state change: OPEN ms(1609309568889) INFO master - Begining task: Disable Unsolicited ms(1609309568889) --AL-> master - C0 15 3C 02 06 3C 03 06 3C 04 06 ms(1609309568889) --AL-> master - FIR: 1 FIN: 1 CON: 0 UNS: 0 SEQ: 0 FUNC: DISABLE_UNSOLICITED ms(1609309568889) --AL-> master - 060,002 - Class Data - Class 1 - all objects ms(1609309568889) --AL-> master - 060,003 - Class Data - Class 2 - all objects ms(1609309568889) --AL-> master - 060,004 - Class Data - Class 3 - all objects ms(1609309568889) --TL-> master - FIR: 1 FIN: 1 SEQ: 0 LEN: 11 ms(1609309568889) --LL-> master - Function: PRI_UNCONFIRMED_USER_DATA Dest: 1 Source: 2 Length: 12 ms(1609309568895) <-LL-- tcpclient - Function: PRI_UNCONFIRMED_USER_DATA Dest: 2 Source: 1 Length: 10 ms(1609309568895) <-TL-- master - FIR: 1 FIN: 1 SEQ: 4 LEN: 4 ms(1609309568895) <-AL-- master - FIR: 1 FIN: 1 CON: 0 UNS: 0 SEQ: 0 FUNC: RESPONSE IIN: [0x10, 0x01] ms(1609309568895) WARN master - Task was explicitly rejected via response with error IIN bit(s): Disable Unsolicited ms(1609309568895) INFO master - Begining task: Startup Integrity Poll ms(1609309568895) --AL-> master - C1 01 3C 02 06 3C 03 06 3C 04 06 3C 01 06 ms(1609309568895) --AL-> master - FIR: 1 FIN: 1 CON: 0 UNS: 0 SEQ: 1 FUNC: READ ms(1609309568895) --AL-> master - 060,002 - Class Data - Class 1 - all objects ms(1609309568895) --AL-> master - 060,003 - Class Data - Class 2 - all objects ms(1609309568895) --AL-> master - 060,004 - Class Data - Class 3 - all objects ms(1609309568895) --AL-> master - 060,001 - Class Data - Class 0 - all objects ms(1609309568895) --TL-> master - FIR: 1 FIN: 1 SEQ: 1 LEN: 14 ms(1609309568895) --LL-> master - Function: PRI_UNCONFIRMED_USER_DATA Dest: 1 Source: 2 Length: 15 ms(1609309568907) <-LL-- tcpclient - Function: PRI_UNCONFIRMED_USER_DATA Dest: 2 Source: 1 Length: 16 ms(1609309568907) <-TL-- master - FIR: 1 FIN: 1 SEQ: 5 LEN: 10 ms(1609309568908) <-AL-- master - FIR: 1 FIN: 1 CON: 0 UNS: 0 SEQ: 1 FUNC: RESPONSE IIN: [0x10, 0x00] ms(1609309568908) <-AL-- master - 010,002 Binary Output - Output Status With Flags, 8-bit start stop [0, 0] terminate called after throwing an instance of 'std::runtime_error' what(): Tried to call pure virtual function "ISOEHandler::Start" Aborted (core dumped)

Thank you for your help.

Saleem344 avatar Dec 30 '20 06:12 Saleem344