wincc如何通过VB脚本读取报警数据库归档内容

刚接触wincc,下面脚本是根据帮助文档VB实例修改,但读取不到归档内容,系统内置报警控件中能读到数据,请大神指点。
' 1.1 Create connection string for ADO access
Dim ProviderName
Dim CatalogName
Dim DataSourceName
Dim ConnectionString
Dim CommandString
Dim snam1,Rtname
Dim ServerName1
Set ServerName1 = HMIRuntime.Tags("@ServerName")          
      ServerName1.Read 
Dim DatasourceNameRT
Set DatasourceNameRT = HMIRuntime.Tags("@DatasourceNameRT")
      DatasourceNameRT.Read 
      Rtname=DatasourceNameRT.Value 
      snam1=ServerName1.Value
ConnectionString = "provider=WinCCOLEDBProvider.1;catalog=" & Rtname & ";data source=" & snam1 & "\WinCC"       
' 1.2 Define command string for access (relative time range, last 10 minutes)
CommandString = "ALARMVIEW:Select * from algviewcht WHERE DateTime > '2017-11-30 00:00:00.000' " 
Dim DBConnection
Dim DBCommand
Dim DBRecordset
' 2.1 Open connection
'HMIRuntime.Trace "before open connection" & vbNewLine 
Set DBConnection = CreateObject("ADODB.Connection")
DBConnection.ConnectionString = ConnectionString
DBConnection.CursorLocation = 3             
DBConnection.open 
Set DBRecordset = CreateObject("ADODB.Recordset")
' 2.2 Execute command
'HMIRuntime.Trace "before execute command" & vbNewLine 
Set DBCommand = CreateObject("ADODB.Command")
DBCommand.CommandType = 1
DBCommand.ActiveConnection = DBConnection
DBCommand.CommandText = CommandString
Set DBRecordset = DBCommand.Execute
Dim lngCount                                  
Dim lngValue,aa
' 2.3 Record structure and first record data (test)
lngCount = DBRecordset.Fields.Count 
aa = DBRecordset.RecordCount 
HMIRuntime.Trace "RecordSet.Field.Count=" & lngCount & vbNewLine 
HMIRuntime.Trace "RecordSet.RecordCount=" & aa & vbNewLine 
If (aa>0) Then 
    DBRecordset.movefirst  
Else
    HMIRuntime.Trace "Selection returned no fields" & vbNewLine 
End If
' 4.1 Clean up
DBRecordset.Close
Set DBRecordset = Nothing
Set DBCommand = Nothing
DBConnection.Close
Set DBConnection = Nothing
HMIRuntime.Trace "Connection closed again" & vbNewLine

问题补充:
数据库已经连接上,脚本调试输出如图,显示库中无数据。

图片说明:

wincc如何通过VB脚本读取报警数据库归档内容    wincc如何通过VB脚本读取报警数据库归档内容   

最佳答案

Rtname=DatasourceNameRT.Value 
 snam1=ServerName1.Value
改成
Rtname=DatasourceNameRT.Read
 snam1=ServerName1.Read
试试

详细参考:
WinCC数据开放性
https://support.industry.siemens.com/cs/cn/zh/view/78682604
在WinCC中如何使用VBS读取报警记录数据到EXCEL
https://support.industry.siemens.com/cs/cn/zh/view/77938393
WinCC、Excel、VBA、脚本、连通性软件包
https://support.industry.siemens.com/cs/cn/zh/view/71676391
WinCC/连通性软件包 V7.4 SP1
https://support.industry.siemens.com/cs/cn/zh/view/109746336
补充:
按我的方法试过了吗?
另外您可以先把WHERE去掉,直接查询所有的,试试,如果能查询到了,再加上条件

提问者对于答案的评价:
谢谢你的回答,找到问题出在哪儿了,软件语言是中文简体,查询的是繁体的归档数据库表,ALGVIEWEXCHT改为ALGVIEWEXCHS就可以了。

原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc362472.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2021年7月5日 下午12:23
下一篇 2021年7月5日 下午12:23

相关推荐

发表回复

登录后才能评论