控制工程师论坛

人机界面

转帖 wincc的n个经典问题解答之一

yuhoucaihong
yuhoucaihong

2007-07-18

1、问: 如何触发计算机扬声器的声音? 
  答: 编写如下C-Action:
  #pragma code("kernel32.dll");
  BOOL Beep(DWORD dwFreq,DWORD dwDuration);
  #pragma code();
  Beep(500,500);
  
  2、问: 如何通过C脚本来确定报警信息?
  答: 首先必须在画面中插入报警控件,可以用如下两种方式来确认信息:
  (1)、确认单条信息
  4版本和高于此版本的WinCC
  BOOL OnBtnSinglAckn(char*lpszPictureName,char*lpszObjectName)
  5版本和高于此版本的WinCC
  BOOL AXC_OnBtnSinglAckn(char*lpszPictureName,char*lpszObjectName)
  
  (2)、确认报警窗口所有可见的报警
  4版本和低于此版本的WinCC
  BOOL OnBtnVisibleAckn(char*lpszPictureName,char*lpszObjectName)
  
  5版本和高于此版本的WinCC
  BOOL AXC_OnBtnVisibleAckn(char*lpszPictureName,char*lpszObjectName)
  
  
  3、问: 如何在WinCC中读取系统时间?
  答: 通过如下C-Action:
  #pragma code("kernel32.dll");
  Void GetLocalTimes(SYSTEMTIME*lpst);
  #pragma code();
  SYSTEMTIME time;
  GetLocalTime(&time);
  SetTagWord("Varname",time.wYear);
  SetTagWord("Varname",time.wMonth);
  SetTagWord("Varname",time.wDayOfWeek);
  SetTagWord("Varname",time.wDay);
  SetTagWord("Varname",time.wHour);
  SetTagWord("Varname",time.wMinute);
  SetTagWord("Varname",time.wSecond);
  SetTagWord("Varname",time.wMilliseconds);
  
  4、问: 如何经Windows对话框设置日期时间?
  答: 通过调用Windows对话框实现。具体如下:
  #include"apdefap.h"
  void onClick(char*lpszPictureName,char*lpszObjectName,
  char*lpszPropertyName)
  {ProgramExcute("c:\\win98\\control.exe timedate.cpl");}
  其中执行的程序路径,需根据具体情况填写。
  
  
  5、问: 如何在WinCC中调用SQL语言?
  答: 1、创建一个 SQL文件,此文件在ISQL中建立,文件内包含所要执行的SQL语句。Windows对话框实现。具体如下:
  2、在WinCC中用C Script 调用上述SQL文件,如下所示:
  #include"apdefap.h"
  void OnLButtonDown(char* lpszPictureName,
  char* lpszObjectName,
  char* lpszPropertyName,
  UINT nFlags,int x,int y)
  {
  char*a="c:\\siemens\\common\\SQLANY\\ISQL-q-b-c
  UID=DBA;PWD=SQL;DBF=E:\\testsql\\testsqlRT.DB;
  DBN=CC_testsql_99-12-03-12:48:26R;READ
  E:testsql\\test.sql";
  Printf("%s\r\n",a);
  ProgramExcute(a);
  }
  下面是一个简单的SQL文件内容:
  select *from pde#hd#t#test;
  output to e:\\test2.txt FORMAT ascii
  注意:文件名及路径中不要带空格。
  
  
  
  6、问: 如何整点启动归档?
  答: 在"Globle Script"下的Project function编写程序函数:cyclicarchive
  BOOL cyclicarchive()
  {
  #pragma code("kernel.dll");
  void GetLocalTime(SYSTEMTIME*lpsz);
  #pragma code();
  SYSTEMTIME time;
  Int t1;
  GetLocalTime(&time);
  T1=time.wMinute;
  If(t1==00)
  {
  SetTagBit("startarchive",1);
  Return(BOOL) (GetTagBit("startarchive"));
  }
  }
  在Tagloging中的"Properties of process tag"中的"archive tag"Tab下的Archive type选择Cycle-selective,在"Event"标签下的"StartEvent"内选择cyclicarchive函数。
  
  
  7、问: How can I set and reset a WinCC variable by mouse click with C script?
  答: The following function shows how you can alternately set and reset a WinCC variable by mouse click.
  #include "apdefap.h"
  void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
  {
  BOOL z;
  z=GetTagBit("MyBitVariable");
  if (z==0)
  SetTagBit("MyBitVariable",1);
  else
  SetTagBit("MyBitVariable",0);
  }
  
  
  8、问: How can I program a waiting function (Sleep) in WinCC?
  答: The following sample program shows how the "Sleep" is used.
  #pragma code("Kernel32.dll")
  void Sleep(int milliseconds);
  #pragma code()
  Sleep(1000); //time specification in milliseconds
  Warning:
  If you use Sleep(), processing the C script is interrupted for the time indicated. Requests for the interrupted function cannot be processed during this time.
  
  
  
  9、问: How can I output a SIMATIC timer minutes and seconds in WinCC?
  答: If you want to output a SIMATIC Timer in minutes and seconds in WinCC, then in WinCC please use a static text in the Graphics Designer to which you interface the following action:
  char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
  {
  char *p;
  DWORD hilf;
  int min, sec;
  p=SysMalloc(10);
  hilf=GetTagDWord("Time");
  min=hilf/60000;
  sec=hilf%60000/1000;
  sprintf(p,"%d min %d sec",min,sec);
  return p;
  }
  The "Time" variable linked to the I/O field must have the following properties:
  •Data type "32-bit value without sign"
  •Format adaptation "DwordToSimaticBCDTimer"
  •Address: data area "Times" and addressing "Word"
回帖

评论1

总共 , 当前 /
首页 | 登录 | 注册 | 返回顶部↑
手机版 | 电脑版
版权所有 Copyright(C) 2016 CE China