GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Gurux.DLMS.Python/Gurux.DLMS.Client.Example.python/main.py at master · Gurux/Gurux.DLMS.Python Expand file tree/ Copy pathmain.pyMore file actions 163 lines (157 loc) · 5.86 KB / Copy pathmain.pyFile metadata and controls163 lines (157 loc) · 5.86 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 # # -------------------------------------------------------------------------- # Gurux Ltd # # # # Filename: $HeadURL$ # # Version: $Revision$, # $Date$ # $Author$ # # Copyright (c) Gurux Ltd # # --------------------------------------------------------------------------- # # DESCRIPTION # # This file is a part of Gurux Device Framework. # # Gurux Device Framework is Open Source software; you can redistribute it # and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 of the License. # Gurux Device Framework is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # # More information of Gurux products: http://www.gurux.org # # This code is licensed under the GNU General Public License v2. # Full text may be retrieved at http://www.gnu.org/licenses/gpl-2.0.txt # --------------------------------------------------------------------------- import os import sys import traceback import gurux_dlms from gurux_serial import GXSerial from gurux_net import GXNet from gurux_dlms.enums import ObjectType from gurux_dlms.objects.GXDLMSObjectCollection import GXDLMSObjectCollection from GXSettings import GXSettings from GXDLMSReader import GXDLMSReader import locale from gurux_dlms import ( GXDLMSException, GXDLMSExceptionResponse, GXDLMSConfirmedServiceError, ) try: if sys.version_info >= (3, 7): from importlib.metadata import version else: import pkg_resources # pylint: disable=broad-except except Exception: # It's OK if this fails. print("pkg_resources not found") # pylint: disable=too-few-public-methods,broad-except class sampleclient: @classmethod def main(cls, args): try: if sys.version_info >= (3, 7): print("gurux_dlms version: " + version("gurux_dlms")) print("gurux_net version: " + version("gurux_net")) print("gurux_serial version: " + version("gurux_serial")) else: print( "gurux_dlms version: " + pkg_resources.get_distribution("gurux_dlms").version ) print( "gurux_net version: " + pkg_resources.get_distribution("gurux_net").version ) print( "gurux_serial version: " + pkg_resources.get_distribution("gurux_serial").version ) except Exception: # It's OK if this fails. print("pkg_resources not found") # args: the command line arguments reader = None settings = GXSettings() try: # ////////////////////////////////////// # Handle command line parameters. ret = settings.getParameters(args) if ret != 0: return # ////////////////////////////////////// # Initialize connection settings. if not isinstance(settings.media, (GXSerial, GXNet)): raise Exception("Unknown media type.") # ////////////////////////////////////// reader = GXDLMSReader( settings.client, settings.media, settings.trace, settings.invocationCounter, ) # Enable Compression: # Add compression package to onCompression event handler when compression is needed. # settings.client.compressionOptions.enableCompression = True settings.media.open() # Export client and server certificates from the meter. if settings.exportSecuritySetupLN: reader.exportMeterCertificates(settings.exportSecuritySetupLN) # Generate new client and server certificates and import them to the server. elif settings.generateSecuritySetupLN: reader.generateCertificates(settings.generateSecuritySetupLN) elif settings.readObjects: read = False reader.initializeConnection() if settings.outputFile and os.path.exists(settings.outputFile): try: c = GXDLMSObjectCollection.load(settings.outputFile) settings.client.objects.extend(c) if settings.client.objects: read = True except Exception: read = False if not read: reader.getAssociationView() for k, v in settings.readObjects: obj = settings.client.objects.findByLN(ObjectType.NONE, k) if obj is None: raise Exception("Unknown logical name:" + k) val = reader.read(obj, v) reader.showValue(v, val) if settings.outputFile: settings.client.objects.save(settings.outputFile) else: reader.readAll(settings.outputFile) except ( ValueError, GXDLMSException, GXDLMSExceptionResponse, GXDLMSConfirmedServiceError, ) as ex: print(ex) except (KeyboardInterrupt, SystemExit, Exception) as ex: traceback.print_exc() if settings.media: settings.media.close() reader = None finally: if reader: try: reader.close() except Exception: traceback.print_exc() print("Ended. Press any key to continue.") if __name__ == "__main__": sampleclient.main(sys.argv) |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |