gurux-dlms


Namegurux-dlms JSON
Version 1.0.148 PyPI version JSON
download
home_pagehttps://github.com/gurux/gurux.dlms.python
SummaryGurux DLMS library for Python.
upload_time2024-01-02 12:59:05
maintainer
docs_urlNone
authorGurux Ltd
requires_python
licenseGPLv2
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            See An [Gurux](http://www.gurux.org/ "Gurux") for an overview.

Join the Gurux Community or follow [@Gurux](https://twitter.com/guruxorg "@Gurux") for project updates.

gurux_dlms library is a high-performance Python component that helps you to read you DLMS/COSEM compatible electricity, gas or water meters. We have try to make component so easy to use that you do not need understand protocol at all.

For more info check out [Gurux.DLMS](http://www.gurux.fi/index.php?q=Gurux.DLMS "Gurux.DLMS").

We are updating documentation on Gurux web page. 

Read should read [DLMS/COSEM FAQ](http://www.gurux.org/index.php?q=DLMSCOSEMFAQ) first to get started. Read Instructions for making your own [meter reading application](http://www.gurux.org/index.php?q=DLMSIntro) or build own 
DLMS/COSEM [meter/simulator/proxy](http://www.gurux.org/index.php?q=OwnDLMSMeter).

If you have problems you can ask your questions in Gurux [Forum](http://www.gurux.org/forum).

You can use any connection (TCP, serial, PLC) library you want to.
Gurux.DLMS classes only parse the data.

Before start
=========================== 

If you find an issue, please report it here:
https://www.gurux.fi/project/issues/gurux.dlms.python


Simple example
=========================== 
First you need to install the library:

```bash
pip install gurux_dlms
```

Before use you must set following device parameters. 
Parameters are manufacturer spesific.

```bash
# First import gurux_dlms. 
from gurux_dlms import *

# All default parameters are given in constructor.
# Is used Logican Name or Short Name referencing.
client = GXDLMSClient(True)

```

HDLC addressing
=========================== 

Each meter has own server address. Server address is divided to Logical address and Physical address.
Usually you can use value 1 for meter address. You can count server address from serial number of the meter.
You can use GetServerAddress method for that.

```bash
# Count server address from serial number.
serverAddress = GXDLMSClient.getServerAddressFromSerialNumber(Serial number)
# Count server address from logican and physical address.
serverAddress = GXDLMSClient.getServerAddress2(logical Address, physical Address, Address size in bytes);
```

If you are using IEC handshake you must first send identify command and move to mode E.

```bash
Support for serial port is added later.
```

After you have set parameters you can try to connect to the meter.
First you should send SNRM request and handle UA response.
After that you will send AARQ request and handle AARE response.


```bash
reply = GXReplyData()
data = self.client.snrmRequest()
if data:
    self.readDLMSPacket(data, reply)
    self.client.parseUAResponse(reply.data)
    size = self.client.hdlc.maxInfoTX + 40
    self.replyBuff = bytearray(size)
reply.clear()
self.readDataBlock(self.client.aarqRequest(), reply)
self.client.parseAareResponse(reply.data)
reply.clear()
if self.client.authentication.value > Authentication.LOW.value:
    for it in self.client.getApplicationAssociationRequest():
        self.readDLMSPacket(it, reply)
    self.client.parseApplicationAssociationResponse(reply.data)
```

If parameters are right connection is made.
Next you can read Association view and show all objects that meter can offer.

```bash
# Read Association View from the meter.
reply = GXReplyData()
self.readDataBlock(self.client.getObjectsRequest(), reply)
objects = self.client.parseObjects(reply.data, True)
converter = GXDLMSConverter.GXDLMSConverter()
converter.updateOBISCodeInformation(objects)

```
Now you can read wanted objects. After read you must close the connection by sending
disconnecting request.

```bash

self.readDLMSPacket(self.client.disconnectRequest(), reply)
#Close media.

```

```bash
def readDLMSPacket2(self, data, reply):
    if not data:
        return
    notify = GXReplyData()
    reply.error = 0
    succeeded = False
    rd = GXByteBuffer()
    if not reply.isStreaming():
        self.writeTrace("TX: " + self.now() + "\t" + GXByteBuffer.hex(data), TraceLevel.VERBOSE)
        self.media.sendall(data)
    msgPos = 0
    count = 100
    pos = 0
    try:
        while not self.client.getData(rd, reply, notify):
            if notify.data.size != 0:
                if not notify.isMoreData():
                    t = GXDLMSTranslator(TranslatorOutputType.SIMPLE_XML)
                    xml = t.dataToXml(notify.data)
                    print(xml)
                    notify.clear()
                    msgPos = rd.position
                continue
            rd.position = msgPos
            rd.set(self.media.recv(100))
        if pos == 3:
            raise ValueError("Failed to receive reply from the device in given time.")
        if pos != 0:
            print("Data send failed.  Try to resend " + str(pos) + "/3")
        ++pos
    except Exception as e:
        self.writeTrace("RX: " + self.now() + "\t" + rd.__str__(), TraceLevel.ERROR)
        raise e
    self.writeTrace("RX: " + self.now() + "\t" + rd.__str__(), TraceLevel.VERBOSE)
    if reply.error != 0:
        raise GXDLMSException(reply.error)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gurux/gurux.dlms.python",
    "name": "gurux-dlms",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Gurux Ltd",
    "author_email": "gurux@gurux.fi",
    "download_url": "https://files.pythonhosted.org/packages/92/ea/7acfee4768053410ca2e565dcdae9fae5d54648797539cc540f9c0175a71/gurux_dlms-1.0.148.tar.gz",
    "platform": null,
    "description": "See An [Gurux](http://www.gurux.org/ \"Gurux\") for an overview.\r\n\r\nJoin the Gurux Community or follow [@Gurux](https://twitter.com/guruxorg \"@Gurux\") for project updates.\r\n\r\ngurux_dlms library is a high-performance Python component that helps you to read you DLMS/COSEM compatible electricity, gas or water meters. We have try to make component so easy to use that you do not need understand protocol at all.\r\n\r\nFor more info check out [Gurux.DLMS](http://www.gurux.fi/index.php?q=Gurux.DLMS \"Gurux.DLMS\").\r\n\r\nWe are updating documentation on Gurux web page. \r\n\r\nRead should read [DLMS/COSEM FAQ](http://www.gurux.org/index.php?q=DLMSCOSEMFAQ) first to get started. Read Instructions for making your own [meter reading application](http://www.gurux.org/index.php?q=DLMSIntro) or build own \r\nDLMS/COSEM [meter/simulator/proxy](http://www.gurux.org/index.php?q=OwnDLMSMeter).\r\n\r\nIf you have problems you can ask your questions in Gurux [Forum](http://www.gurux.org/forum).\r\n\r\nYou can use any connection (TCP, serial, PLC) library you want to.\r\nGurux.DLMS classes only parse the data.\r\n\r\nBefore start\r\n=========================== \r\n\r\nIf you find an issue, please report it here:\r\nhttps://www.gurux.fi/project/issues/gurux.dlms.python\r\n\r\n\r\nSimple example\r\n=========================== \r\nFirst you need to install the library:\r\n\r\n```bash\r\npip install gurux_dlms\r\n```\r\n\r\nBefore use you must set following device parameters. \r\nParameters are manufacturer spesific.\r\n\r\n```bash\r\n# First import gurux_dlms. \r\nfrom gurux_dlms import *\r\n\r\n# All default parameters are given in constructor.\r\n# Is used Logican Name or Short Name referencing.\r\nclient = GXDLMSClient(True)\r\n\r\n```\r\n\r\nHDLC addressing\r\n=========================== \r\n\r\nEach meter has own server address. Server address is divided to Logical address and Physical address.\r\nUsually you can use value 1 for meter address. You can count server address from serial number of the meter.\r\nYou can use GetServerAddress method for that.\r\n\r\n```bash\r\n# Count server address from serial number.\r\nserverAddress = GXDLMSClient.getServerAddressFromSerialNumber(Serial number)\r\n# Count server address from logican and physical address.\r\nserverAddress = GXDLMSClient.getServerAddress2(logical Address, physical Address, Address size in bytes);\r\n```\r\n\r\nIf you are using IEC handshake you must first send identify command and move to mode E.\r\n\r\n```bash\r\nSupport for serial port is added later.\r\n```\r\n\r\nAfter you have set parameters you can try to connect to the meter.\r\nFirst you should send SNRM request and handle UA response.\r\nAfter that you will send AARQ request and handle AARE response.\r\n\r\n\r\n```bash\r\nreply = GXReplyData()\r\ndata = self.client.snrmRequest()\r\nif data:\r\n    self.readDLMSPacket(data, reply)\r\n    self.client.parseUAResponse(reply.data)\r\n    size = self.client.hdlc.maxInfoTX + 40\r\n    self.replyBuff = bytearray(size)\r\nreply.clear()\r\nself.readDataBlock(self.client.aarqRequest(), reply)\r\nself.client.parseAareResponse(reply.data)\r\nreply.clear()\r\nif self.client.authentication.value > Authentication.LOW.value:\r\n    for it in self.client.getApplicationAssociationRequest():\r\n        self.readDLMSPacket(it, reply)\r\n    self.client.parseApplicationAssociationResponse(reply.data)\r\n```\r\n\r\nIf parameters are right connection is made.\r\nNext you can read Association view and show all objects that meter can offer.\r\n\r\n```bash\r\n# Read Association View from the meter.\r\nreply = GXReplyData()\r\nself.readDataBlock(self.client.getObjectsRequest(), reply)\r\nobjects = self.client.parseObjects(reply.data, True)\r\nconverter = GXDLMSConverter.GXDLMSConverter()\r\nconverter.updateOBISCodeInformation(objects)\r\n\r\n```\r\nNow you can read wanted objects. After read you must close the connection by sending\r\ndisconnecting request.\r\n\r\n```bash\r\n\r\nself.readDLMSPacket(self.client.disconnectRequest(), reply)\r\n#Close media.\r\n\r\n```\r\n\r\n```bash\r\ndef readDLMSPacket2(self, data, reply):\r\n    if not data:\r\n        return\r\n    notify = GXReplyData()\r\n    reply.error = 0\r\n    succeeded = False\r\n    rd = GXByteBuffer()\r\n    if not reply.isStreaming():\r\n        self.writeTrace(\"TX: \" + self.now() + \"\\t\" + GXByteBuffer.hex(data), TraceLevel.VERBOSE)\r\n        self.media.sendall(data)\r\n    msgPos = 0\r\n    count = 100\r\n    pos = 0\r\n    try:\r\n        while not self.client.getData(rd, reply, notify):\r\n            if notify.data.size != 0:\r\n                if not notify.isMoreData():\r\n                    t = GXDLMSTranslator(TranslatorOutputType.SIMPLE_XML)\r\n                    xml = t.dataToXml(notify.data)\r\n                    print(xml)\r\n                    notify.clear()\r\n                    msgPos = rd.position\r\n                continue\r\n            rd.position = msgPos\r\n            rd.set(self.media.recv(100))\r\n        if pos == 3:\r\n            raise ValueError(\"Failed to receive reply from the device in given time.\")\r\n        if pos != 0:\r\n            print(\"Data send failed.  Try to resend \" + str(pos) + \"/3\")\r\n        ++pos\r\n    except Exception as e:\r\n        self.writeTrace(\"RX: \" + self.now() + \"\\t\" + rd.__str__(), TraceLevel.ERROR)\r\n        raise e\r\n    self.writeTrace(\"RX: \" + self.now() + \"\\t\" + rd.__str__(), TraceLevel.VERBOSE)\r\n    if reply.error != 0:\r\n        raise GXDLMSException(reply.error)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "GPLv2",
    "summary": "Gurux DLMS library for Python.",
    "version": "1.0.148",
    "project_urls": {
        "Homepage": "https://github.com/gurux/gurux.dlms.python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e2f88b4df1050933fac7a9d5d2a98bd2628091cff69370b6ab293d73b9519a3",
                "md5": "85559114206db151983df6e2bdc2a15c",
                "sha256": "ba54e39c0259259831d38591ad0296b80d68dc7eadd4b4ea18e697f94734f363"
            },
            "downloads": -1,
            "filename": "gurux_dlms-1.0.148-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "85559114206db151983df6e2bdc2a15c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 545415,
            "upload_time": "2024-01-02T12:59:01",
            "upload_time_iso_8601": "2024-01-02T12:59:01.750243Z",
            "url": "https://files.pythonhosted.org/packages/9e/2f/88b4df1050933fac7a9d5d2a98bd2628091cff69370b6ab293d73b9519a3/gurux_dlms-1.0.148-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92ea7acfee4768053410ca2e565dcdae9fae5d54648797539cc540f9c0175a71",
                "md5": "432a2b192505df07a95978e86f80fe31",
                "sha256": "44c4f21d6833008f598147359431622f548c74ae6f46835ba3e9cff5447b874a"
            },
            "downloads": -1,
            "filename": "gurux_dlms-1.0.148.tar.gz",
            "has_sig": false,
            "md5_digest": "432a2b192505df07a95978e86f80fe31",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 288422,
            "upload_time": "2024-01-02T12:59:05",
            "upload_time_iso_8601": "2024-01-02T12:59:05.786916Z",
            "url": "https://files.pythonhosted.org/packages/92/ea/7acfee4768053410ca2e565dcdae9fae5d54648797539cc540f9c0175a71/gurux_dlms-1.0.148.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-02 12:59:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gurux",
    "github_project": "gurux.dlms.python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "gurux-dlms"
}
        
Elapsed time: 0.16360s