Python串口连接触发段错误(Windows访问违例) 智能电表软件问题排查
关于使用Python DLMS库连接Landis+Gyr电表的段错误问题
这是我在Stack Overflow的首次提问,烦请各位多多包涵:
我正在尝试使用Python编写的开源智能计量软件连接Landis+Gyr电表,对应代码为Gurux官方开源的DLMS Python组件。我持有光学编程读头,因此打算通过串口建立连接。
我已确认执行命令正确、所需文件齐全,但在终端运行命令时收到*「Windows fatal exception: access violation」报错、部分调用栈信息,随后出现「Segmentation fault」*段错误。
我已将问题范围缩小到如下代码的最后一行:
def close(self): #pylint: disable=broad-except if self.media and self.media.isOpen(): print("DisconnectRequest") reply = GXReplyData() try: #Release is called only for secured connections. #All meters are not supporting Release and it's causing #problems. if self.client.interfaceType == InterfaceType.WRAPPER or self.client.ciphering.security != Security.NONE: self.readDataBlock(self.client.releaseRequest(), reply) except Exception: pass # All meters don't support release. reply.clear() self.readDLMSPacket(self.client.disconnectRequest(), reply) self.media.close()
如果我注释掉self.media.close()语句,就不会再触发Windows访问违例报错,但脚本无法正常执行。
我的运行环境为Windows 10 64位、Python 3.7,恳请各位帮忙分析可能的问题原因,非常感谢。
问题解决补充说明
最终排查出问题出在用于和智能电表通信的光学读头上,Gurux软件无法和其驱动正常通信,该问题已由Gurux团队快速修复,感谢各位的反馈建议。
内容的提问来源于stack exchange,提问作者user16966640
相关产品推荐
相关产品推荐

