【问题标题】:Python 3.5 - ctypes - create string buffer for Citect APIPython 3.5 - ctypes - 为 Citect API 创建字符串缓冲区
【发布时间】:2016-07-18 07:08:34
【问题描述】:

我想从 Python 中的外部脚本访问我们的 Citect SCADA 系统。我在这里找到了一些示例代码:https://github.com/mitchyg/Random/blob/master/pyctapi/src/pyctapi.py

当我运行这段代码时:

def ct_tag_read(self, tag_name):
    buffer = create_string_buffer('\000' * 32)
    ok = windll.CtApi.ctTagRead(self.hCTAPI, tag_name, byref(buffer), sizeof(buffer), None)

    return buffer.value

我收到此错误:

line 63, in create_string_buffer
raise TypeError(init)
TypeError:  

我正在使用 Python 3.5。

这里是 Citect API 函数 ct_TagRead 的描述:

http://www.citect.schneider-electric.com/webhelp/vijeo740/Content/ctTagRead.html

【问题讨论】:

    标签: python api ctypes scada


    【解决方案1】:

    好的,首先我混合了 ctCicode 和 ctTagRead 的参数,所以代码应该看起来像(没有“,无”参数):

    def ct_tag_read(self, tag_name):
        buffer = create_string_buffer('\000' * 32)
        ok = windll.CtApi.ctTagRead(self.hCTAPI, tag_name, byref(buffer), sizeof(buffer))
        if ok == False:
            print("Unable to read TAG")
            return
    
    return buffer.value
    

    我切换到 python 2.7,一切正常。

    【讨论】:

      猜你喜欢
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多