我有一个通过网络连接从PLC读取数据点的程序。
例外
“从‘计数器’到‘整数’类型的转换无效”
当我试图读取艾伦布拉德利PLC-5上的C文件时发生。
C文件列出的类型是计数器,但Visual中没有计数器类型。
在Visual中有“计数器”类型可以接受的类型吗?将函数的返回类型更改为Counter或CounterSample没有帮助。
这是相关函数的代码。我正在使用一个自动解决方案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发布于 2017-08-17 19:39:16
我不熟悉您正在使用的驱动程序,但听起来您想让它读取计数器的基址,比如C5:0,但是函数正在寻找一个整数标签,而不是完整的计数器结构。
我怀疑您正在尝试返回预置值或Accum值。
尝试将.ACC或.PRE添加到您的标记中,以查看它是否会返回值而不存在out错误。(即: C5:0.ACC)
https://stackoverflow.com/questions/45038888
复制相似问题