mz-automation / libiec61850

Official repository for libIEC61850, the open-source library for the IEC 61850 protocols
http://libiec61850.com/libiec61850
GNU General Public License v3.0
857 stars 459 forks source link

GOOSE Python code: error assigning values to dstAddress #339

Open kwasibb opened 3 years ago

kwasibb commented 3 years ago

Hello, I tried to write a Python version of the goose_publisher_c in the examples folder but I get an error trying to assign a value to the dstAddress field. I am sure that I am missing something. Kindly assist, thank you. The error and code are below:

Traceback (most recent call last):
  File "/home/gee/python/GOOSETest.py", line 40, in <module>
    goose_tx = GOOSETest(app_id=1000, vlan_id=4, priority=4, address=address)
  File "/home/gee/python/GOOSETest.py", line 7, in __init__
    self._comm_parameters.dstAddress.append(address[0])
TypeError: Attempt to append a non SwigPyObject
import iec61850

class GOOSETest:
    def __init__(self, app_id, vlan_id, priority, address, interface="ens160"):
        self._comm_parameters = iec61850.CommParameters()
        self._comm_parameters.appId = app_id
        self._comm_parameters.dstAddress.append(address[0])
        self._comm_parameters.dstAddress.append(address[1])
        self._comm_parameters.dstAddress.append(address[2])
        self._comm_parameters.dstAddress.append(address[3])
        self._comm_parameters.dstAddress.append(address[4])
        self._comm_parameters.dstAddress.append(address[5])
        self._comm_parameters.vlanId = vlan_id
        self._comm_parameters.vlanPriority = priority
        self._publisher = iec61850.GoosePublisher_create(self._comm_parameters, interface)

    def query(self):
        dataset_values = iec61850.LinkedList_create()
        iec61850.LinkedList_add(dataset_values, iec61850.MmsValue_newIntegerFromInt32(1234))

        if self._publisher:
            iec61850.GoosePublisher_setGoCbRef(self._publisher, "simpleIOGenericIO/LLN0$GO$gcbAnalogValues");
            iec61850.GoosePublisher_setConfRev(self._publisher, 1);
            iec61850.GoosePublisher_setDataSetRef(self._publisher, "simpleIOGenericIO/LLN0$AnalogValues");
            iec61850.GoosePublisher_setTimeAllowedToLive(self._publisher, 500);
            try:
                iec61850.GoosePublisher_publish(self._publisher, dataset_values);
            except:
                print("Error sending message")

            iec61850.GoosePublisher_destroy(self._publisher)
        else:
            print("Failed to create GOOSE publisher. "
                  "Reason can be that the Ethernet interface doesn't exist or root permission are required")

        iec61850.LinkedList_destroyDeep(dataset_values, iec61850.MmsValue_delete)

address = [0x01, 0x0c, 0xcd, 0x01, 0x00, 0x01]
goose_tx = GOOSETest(app_id=1000, vlan_id=4, priority=4, address=address)
goose_tx.query()
mbourhis commented 1 year ago

Have you try this API? : iec61850.CommParameters_setDstAddress();

as the following example:

    gooseCommParameters = iec61850.CommParameters()

    gooseCommParameters.appId = app_id;
    iec61850.CommParameters_setDstAddress(gooseCommParameters,
                                          address[0],
                                          address[1],
                                          address[2],
                                          address[3],
                                          address[4],
                                          address[5])
    gooseCommParameters.vlanId = vlan_id;
    gooseCommParameters.vlanPriority = priority;

    publisher = iec61850.GoosePublisher_create(gooseCommParameters, interface)