PLC Visual Basic 程序:"Conversion from type 'Counter' to type 'Integer' is not valid"

PLC Visual Basic Program: "Conversion from type 'Counter' to type 'Integer' is not valid"

我有一个程序可以通过网络连接从 PLC 读取数据点。

异常

"Conversion from type 'Counter' to type 'Integer' is not valid"

当我尝试从 Allen Bradley PLC-5 上的 C 文件读取时发生。

为 C 文件列出的类型是计数器,但在 Visual Basic 中没有计数器类型。
"counter" 类型在 Visual Basic 中是否可以接受任何类型?将函数的 return 类型更改为 CounterCounterSample 没有帮助。

这是相关功能的代码。我正在使用自动化解决方案 Ascomm.net 驱动程序。

Public Function readValueCounter(item As Item, num As Integer) As Integer
    Try
        'read in the data for ASComm object instances
        item.Read()
        'return value
        Return item.Values(num)
    Catch ex As Exception
        'report error
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return 0
    End Try
End Function

我不熟悉你正在使用的驱动程序,但听起来你正试图让它读取计数器的基址 - 比如 C5:0,但函数正在寻找一个整数标记,而不是完整的计数器结构。

我怀疑您正在尝试 return Preset 或 Accum 值。

尝试将 .ACC 或 .PRE 添加到您的代码中,看看是否 return 值不会出错。 (即:C5:0.ACC)