【问题标题】:Python / Python.NET 3.0 / OSIsoft / Enum-related errorPython / Python.NET 3.0 / OSIsoft / Enum相关错误
【发布时间】:2022-08-15 06:33:30
【问题描述】:

我最近将我的代码移到了工作中的新计算机上。一个基本的示例代码如下(但您将无法运行它,因为您无法连接到我的服务器 - 抱歉,我无法使其更具重现性)。

使用新计算机,我收到以下错误: \"System.ArgumentException:因为 Python.NET 3.0 int 无法隐式转换为 Enum。在方法 OSIsoft.AF.Asset.AFValue RecordedValue(OSIsoft.AF.Time.AFTime, OSIsoft.AF.Data.AFRetrievalMode) ---> Python.Runtime.PythonException 中使用 Enum(int_value):因为 Python.NET 3.0 int 不能隐式转换为 Enum。使用枚举(int_value)\"。

我的旧电脑使用 Spyder 4 和 Python 3.7 和 Python.NET 2.5.2。新计算机使用 Spyder 5 和 Python 3.9 和 Python.NET 3.0。由于 IT 限制,我无法在我的计算机上安装相同版本的 Spyder 和 Python。但是,我认为它不会导致此错误。

有没有人知道什么会导致枚举- 相关问题?谢谢!

import PIconnect as PI

def pidownload(tag):
    with PI.PIServer() as server:
        point = server.search(tag)[0]
        data = point.recorded_value(\'-1m\')
        data=data.to_frame()
    return data
tag=\'xxxx.pv\' #confidential data tag replaced with xxxx
print(pidownload(tag))

  • 旧机器上使用的是哪个版本的 .NET?
  • 嗨 Ethan,旧机器是 pythonnet 2.5.2。编辑我的帖子以反映这一点。

标签: python enums osisoft


【解决方案1】:

OSIsoft's documentationRecordedValue 函数的文档和PIConnect documentationrecorded_value 的文档来看,似乎Python 端函数正在发送一个枚举,而C# 端函数正在接收一个枚举值.但是,在检查 PIConnect 的GitHub documentation 时,我们可以看到问题出在retrieval_mode 变量上,它的默认值为RetrievalMode.AUTO,即IntEnum。看来转换无法正常工作,因为我在他们的存储库中注意到了这个GitHub issue

编辑

经过进一步检查,您的问题似乎是安装问题,可以通过重新安装piconnect 来解决,请参阅此question

【讨论】:

    【解决方案2】:

    Python2 and python3 enum is not completely compatible

    从这篇文章中可以看出,python2 使用不同的实现技术来编写枚举代码。我想您必须深入研究代码并重写一些行才能在 python3 环境中运行代码。

    PS我以前没有遇到过相同或类似的问题。

    希望这能给你更多的见解。

    【讨论】:

      猜你喜欢
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      相关资源
      最近更新 更多