想在WINCC运行系统中单击显示两个阶段的报警数据(比如33~44和101~103),按钮代码如下:
sprintf(SQLcmd,"MSGNR>=%d AND MSGNR<=%d OR MSGNR>=%d AND MSGNR<=%d",begin_b,end_b,begin1_b,end1_b);
SetPropChar(lpszPictureName,"AlarmControl1",APCMsgFilterSQL,SQLcmd);
为什么只能显示begin_b和end_b之间的报警数据?刚如何解决?
问题补充:
"MsgFilterSQL" 是这样定义的:
#define APCMsgFilterSQL "MsgFilterSQL"
我也直接把SetPropChar(lpszPictureName,"AlarmControl2",APCMsgFilterSQL,SQLcmd);改为SetPropChar(lpszPictureName,"AlarmControl2", "MsgFilterSQL",SQLcmd);一样是没用的,不知道“ 兼容性”你是如何做到的,可不可以再说清楚一点,我用的是WINCC 6.0版本的
最佳答案
采用如下代码,可以实现所要求的报警记录的查询:
查询字串sSql="where (msgNR>33 and msgNR<44) or (msgNR>101 and msgNR<103)"
sSql = "ALARMVIEW:Select * FROM ALGVIEWCHT " & sSql
以下代码是用VBScript写的:
Dim sPro, sDsn, sSer,sCon
Dim oRptTitle
Dim conn, oRs, oCom, oItem
Dim m,n,s,nRec,lRet
'' 0.0 Get parameters from i/o fields in picture
sDsn=HMIRuntime.Tags("@DatasourceNameRT").Read(1)
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=" + sDsn + ";"
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer
'' 2.1 Make connection
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.CursorLocation = 3''adUseClient
conn.Open
'' 2.2 Use command text for query
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1 '' adCmdText = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
'' 2.3 Fill the recordset
On Error Resume Next
Set oRs = oCom.Execute
oRs中包含有查询结果,将其放在一个列表控件如List中即可看到所查询的内容.我的项目中也包括这样的查询,并且我采用上述方法实现了报警记录的任意查询
提问者对于答案的评价:
其实都很好,谢谢你们的建议
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc277740.html