- renamed README to README.md and now using markdown syntax
- added pyiec61850 tutorial and example thanks to Cédric Boudinetpull/11/head
parent
412e0b8da8
commit
9dc1a36568
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python
|
||||
import os,sys
|
||||
import iec61850
|
||||
if __name__=="__main__":
|
||||
hostname = "localhost";
|
||||
tcpPort = 102
|
||||
if len(sys.argv)>1:
|
||||
hostname = sys.argv[1]
|
||||
if len(sys.argv)>2:
|
||||
port = sys.argv[2]
|
||||
con = iec61850.IedConnection_create()
|
||||
error = iec61850.IedConnection_connect(con, hostname, tcpPort)
|
||||
if (error == iec61850.IED_ERROR_OK):
|
||||
[deviceList, error] = iec61850.IedConnection_getLogicalDeviceList(con)
|
||||
device = iec61850.LinkedList_getNext(deviceList)
|
||||
while device:
|
||||
LD_name=iec61850.toCharP(device.data)
|
||||
print("LD: %s" % LD_name)
|
||||
[logicalNodes, error] = iec61850.IedConnection_getLogicalDeviceDirectory(con, LD_name)
|
||||
logicalNode = iec61850.LinkedList_getNext(logicalNodes)
|
||||
while logicalNode:
|
||||
LN_name=iec61850.toCharP(logicalNode.data)
|
||||
print(" LN: %s" % LN_name)
|
||||
[LNobjects, error] = iec61850.IedConnection_getLogicalNodeVariables(con, LD_name+"/"+LN_name)
|
||||
LNobject = iec61850.LinkedList_getNext(LNobjects)
|
||||
while LNobject:
|
||||
print(" DO: %s" % iec61850.toCharP(LNobject.data))
|
||||
LNobject = iec61850.LinkedList_getNext(LNobject)
|
||||
iec61850.LinkedList_destroy(LNobjects)
|
||||
logicalNode = iec61850.LinkedList_getNext(logicalNode)
|
||||
iec61850.LinkedList_destroy(logicalNodes)
|
||||
device = iec61850.LinkedList_getNext(device)
|
||||
iec61850.LinkedList_destroy(deviceList)
|
||||
iec61850.IedConnection_close(con)
|
||||
else:
|
||||
print("Failed to connect to %s:%i\n"%(hostname, tcpPort))
|
||||
iec61850.IedConnection_destroy(con)
|
@ -0,0 +1,50 @@
|
||||
# Building
|
||||
Before building you should install swig and python.
|
||||
To build python bindings you have to turn on the BUILD\_PYTHON\_BINDINGS flag in CMake from cmake-gui or in command line:
|
||||
```sh
|
||||
$ cmake -DBUILD_PYTHON_BINDINGS=ON .
|
||||
```
|
||||
Then compile the library and install it. CMake and swig will automatically detect your python version and install the python library in python library directories.
|
||||
|
||||
pyiec61850 library is to be imported calling
|
||||
```python
|
||||
import iec61850
|
||||
```
|
||||
# Client tutorial
|
||||
|
||||
The python bindings works similarly to the basic C library. However there are some differences:
|
||||
|
||||
* a specific function is to be called to cast variables from one type to another
|
||||
* arguments passed by pointer are to be removed from arguments and append to the return list
|
||||
|
||||
|
||||
For example to create a connection, call:
|
||||
```python
|
||||
con = iec61850.IedConnection_create()
|
||||
error = iec61850.IedConnection_connect(con, "localhost", 102)
|
||||
if (error == iec61850.IED_ERROR_OK):
|
||||
# Do some work
|
||||
iec61850.IedConnection_close(con)
|
||||
iec61850.IedConnection_destroy(con)
|
||||
```
|
||||
|
||||
To iterate over a list of logical devices, the code becomes:
|
||||
```python
|
||||
[deviceList, error] = iec61850.IedConnection_getLogicalDeviceList(con)
|
||||
device = iec61850.LinkedList_getNext(deviceList)
|
||||
|
||||
while device:
|
||||
print("LD: %s" % iec61850.toCharP(device.data))
|
||||
[logicalNodes, error] = iec61850.IedConnection_getLogicalDeviceDirectory(
|
||||
con, iec61850.toCharP(device.data))
|
||||
device = iec61850.LinkedList_getNext(device)
|
||||
iec61850.LinkedList_destroy(deviceList)
|
||||
```
|
||||
|
||||
Reading and writing operations can be performed using this syntax:
|
||||
```python
|
||||
[floatValue, error] = iec61850.IedConnection_readFloatValue(con,
|
||||
"simpleIOGenericIO/GGIO1.AnIn1.mag.f", iec61850.IEC61850_FC_MX)
|
||||
err = iec61850.IedConnection_writeFloatValue(con,
|
||||
"simpleIOGenericIO/GGIO1.AnIn1.mag.f", iec61850.IEC61850_FC_MX, 10.0)
|
||||
```
|
Loading…
Reference in New Issue