AsmaaSalem

I am trying to read 32-bit analog output values from OpenPLC using DNP3 protocol with Python. OpenPLC is running on virtual machine and python is running on ubuntu 20.02. I am using %MD0 to %MD4 (double word 32 bits float) addresses on PLC and group 40 for analog output with variations number 3 (single-precision floating point), but I am not able to get it to read from the PLC and I am not sure where is the problem, the same OpenPLC program worked well using Modbus and we configured OpenPLC to use DNP3 on the OpenPLC settings.

I am attaching my code and would appreciate any help!

 

from pydnp3 import opendnp3, openpal, asiopal, asiodnp3

import time

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.0.10', '0.0.0.0', 20000, listener)

class VisitorIndexedAnalog(opendnp3.IVisitorIndexedAnalog):

    def __init__(self):

        super(VisitorIndexedAnalog, 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):

    def __init__(self):

        super(SOEHandler, self).__init__()    

    def Process(self, info, values):

        if (values.Count() == 6 and type(values) == opendnp3.ICollectionIndexedAnalog):

            class BOSVisitor(opendnp3.IVisitorIndexedAnalog):

                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):

        pass

    def End(self):

        pass

soe_handler = SOEHandler()

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()

group_variation = opendnp3.GroupVariationID(40, 3)

master.ScanRange(group_variation, 0, 5)

master.Disable(

master = None

channel.Shutdown()

channel = None

manager.Shutdown()

 

Reply 1 0
Reply