组态王作为经典的国产组态软件,对于一些小的系统特别适用。但是组态王的历史报警记录需要配置数据库。否则关机后,下次打开就没有了。
首先我们建立一个测试变量。
建立报警界面:
建立两个时钟变量,分别是开始日期和结束日期。
开始日期设置:
VOID closeup2()
float Ayear;
float Amonth;
float Aday;
string temp52;
Ayear=ADate52.Year;
Amonth=ADate52.Month;
Aday=ADate52.Day;
temp52=StrFromInt( Ayear, 10 );
if(Amonth<10)
temp52=temp52+"/0"+StrFromInt( Amonth, 10 );
else
temp52=temp52+"/"+StrFromInt( Amonth, 10 );
if(Aday<10)
temp52=temp52+"/0"+StrFromInt( Aday, 10 );
else
temp52=temp52+"/"+StrFromInt( Aday, 10 );
\\local\选择日期52=temp52;
结束日期设置:
VOID closeUP355()
float Ayear;
float Amonth;
float Aday;
string temp55;
Ayear=ADate55.Year;
Amonth=ADate55.Month;
Aday=ADate55.Day;
temp55=StrFromInt( Ayear, 10 );
if(Amonth<10)
temp55=temp55+"/0"+StrFromInt( Amonth, 10 );
else
temp55=temp55+"/"+StrFromInt( Amonth, 10 );
if(Aday<10)
temp55=temp55+"/0"+StrFromInt( Aday, 10 );
else
temp55=temp55+"/"+StrFromInt( Aday, 10 );
\\local\选择日期55=temp55;
【查询记录】设置:
string whe1;
string str = \\local\选择日期52;
string str1 = ConvertLocalTimeToUTC(str);
str = \\local\选择日期55;
string str2 = ConvertLocalTimeToUTC(str) ;
whe1 = "AlarmTime >=#"+str1+"# And AlarmTime <=#"+str2+"#";
Trace('test = %2s', whe1);
Ctrl14.Where = whe1;
Ctrl14.FetchData();
Ctrl14.FetchEnd();
【报警打印】设置:
Ctrl14.PrintPreview();
找到【KvAdoDBGrid Class】
以上是画面的设计:
下面需要配置历史记录。
1)变量设置报警记录
2)报警配置
3)配置ODBC
注意一定要是以下路径的ODBCAD32
这个数据库是自己生成的。
测试效果:
