WINCC获取项目路径和打开子画面C脚本

用户授权

#include "apdefap.h"

int gscAction( void )
{
int i;
//char* ComputorName; 
char* ServerName;
ServerName = GetTagChar("@ServerName"); 

SetTagChar("IPadr",ServerName);
//ComputorName = GetPropChar("HMI.Pdl","COMPUTORNAME","Text"); 



//printf("长=%d\r\n", strlen(ServerName));
for (i = 0; i < strlen(ServerName); i++) {
	printf("i=%d:", i);
	printf("%c\r\n", *(ServerName + i));
	
}


if(*(ServerName + 12)=='3' && *(ServerName + 13)=='8' && *(ServerName + 14)=='8')
{
	printf("授权成功\r\n");
}
else
{
	printf("授权失败\r\n");
	//ExitWinCC();	//完全退出WINCC
	DeactivateRTProject();//仅退出WINCC运行
}


return 0; 
}

二次确认窗口

#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{

int xRet = MessageBox(NULL,"确定选择吗?","确认",MB_YESNO|MB_ICONQUESTION|MB_SYSTEMMODAL);

if ( xRet == IDYES )
{
    int s=GetTagBit("sel");	//Return-Type: BOOL 
    if(s==1)
        SetTagBit("sel",0);	
    if(s==0)
       SetTagBit("sel",1);
}

获取项目路径

#include "apdefap.h"

int gscAction( void )
{
char prjName[_MAX_PATH+1];
DM_DIRECTORY_INFO dmDirInfo;
//HWND h;//--
char * restpath;//--

CMN_ERROR error;
char ProjPath[100];
DMGetRuntimeProject(prjName,_MAX_PATH,&error);
DMGetProjectDirectory("",prjName,&dmDirInfo,&error);
strcpy(ProjPath,dmDirInfo.szProjectDir);
restpath="Application\\Exe\\YangZheng.exe";
strcat(ProjPath , restpath);
printf("%s\r\n",ProjPath);

//h=FindWindow(NULL,"YangZheng"); 
//printf("%s\r\n",h);
//if(h==NULL)
//{
//ProgramExecute(ProjPath);
//ShellExecute(ProjPath);
//h=FindWindow(NULL,"YangZheng");
//}
//窗口在最前面
//ShowWindow(h, SW_NORMAL);
//SetForegroundWindow(h);

}

打开子画面

// 显示画面
SetPictureName(lpszPictureName,"画面窗口1","控制台.PDL");
SetVisible(lpszPictureName,"画面窗口1",1);
// 弹出窗口位置
SetLeft(lpszPictureName,"画面窗口1",337);	
SetTop(lpszPictureName,"画面窗口1", 129);
// 弹出窗口大小
SetWidth(lpszPictureName,"画面窗口1",900);	
SetHeight(lpszPictureName,"画面窗口1", 900);

操作控件

GetPropChar(“画面”,“控件”,“属性”); //必须带双引号
属性怎么获取?

举例说明

静态文本中的文本和字体属性。

在这里插入图片描述
右击文本会出现“这是什么?”提示,左击点击它进入。

在这里插入图片描述

使用名称“Text”可使“文本”属性动态化。“Text”

注意:字体同样上述步骤,在这里要注意的是多个单词时将“Font Name”在C脚本使用时中间空格去掉,即“FontName”!!!
char* Scr_Name; 
Scr_Name = GetPropChar("Main.Pdl","静态文本74","Text"); 
SetPropChar("Main.Pdl","静态文本74","Text","Math Model Systerm 锅炉"); 
SetPropChar("Main.Pdl","静态文本74","FontName","宋体"); 
printf("%s\r\n",Scr_Name);
static int i;
char* Scr_Name;
char* Net_Name;
Scr_Name = GetPropChar("Main.Pdl","静态文本74","Text"); 
SetPropChar("Main.Pdl","静态文本74","Text","Math Model Combustion Systerm 锅炉"); 
SetPropChar("Main.Pdl","静态文本74","FontName","宋体"); 

if(i>99)
	i=0;
else
	i=i+10;
//UCWaveChart
//.NET 控件7
SetPropWord("控制台.Pdl",".NET 控件7","WaveValue",i); 
printf("%s\r\n",Scr_Name);

在这里插入图片描述

#include "apdefap.h"
void Click(char* lpszPictureName, char* lpszObjectName )
{
if(GetPropBOOL("10万转煤流量控制.Pdl",".NET 控件37","Checked")==1)
    SetTagBit("LDGAUTO10",0)   ; 
else
    SetTagBit("LDGAUTO10",1)   ; 
}
WinCC判断c脚本注意事项
//正确写法
if(og1>=1&& og1<=3)
//错误写法
if(1<=og1<=3)
//进行字符串拼接
char* a;
char* b;
char* c;
b="Yang";
c="zheng";
sprintf(a,"%s%s",b,c);
#include "apdefap.h"

int gscAction( void )
{
char* Scr_Name; 
char t[1000];
int y,m,d;
int time;
#pragma code("kernel32.dll");
void GetLocalTime(SYSTEMTIME*lpst);
#pragma code();
SYSTEMTIME sysTmie;
GetLocalTime(&sysTmie); 

//SetTagWord("RunningMillisecond",sysTmie.wMillisecond);
SetTagWord("RunningSecond",sysTmie.wSecond);
SetTagWord("RunningMinute",sysTmie.wMinute); 
SetTagWord("RunningHour",sysTmie.wHour); 
SetTagWord("RunningDay",sysTmie.wDay);
SetTagWord("RunningMonth",sysTmie.wMonth);
SetTagWord("RunningYear",sysTmie.wYear);

y = 2025;
m = 3;
d = 15;


sprintf(t,"授权到期:%d 年 %d 月 %d 日,联系电话:134-8341-7110。",y,m,d);
printf("%s\r\n",t);

Scr_Name = GetPropChar("A Math Model.Pdl","授权文本","Text"); 
SetPropChar("A Math Model.Pdl","授权文本","Text",t); 


//printf("%s\r\n",Scr_Name);



if(GetTagWord("RunningYear")>=2025 && GetTagWord("RunningMonth")>=3 && GetTagWord("RunningDay")>=15
&& GetTagWord("RunningHour")>=0 && GetTagWord("RunningMinute")>=0 && GetTagWord("RunningSecond")>=0)
{
	//ExitWinCC();	//完全退出WINCC
	DeactivateRTProject();//仅退出WINCC运行
}

return 0; 
}

推荐网址:https://cloud.tencent.com/developer/article/1966731

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨铮...

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值