QQ登录

只需一步,快速开始

大家都来说说平时用的最多的C脚本有哪些。做项目时都可以互相借鉴参考

[ 复制链接 ]
大家都来说说平时用的最多的C脚本有哪些。做项目时都可以互相借鉴参考1、再次按键确认
{
if(MessageBox(NULL,"确认要停机吗?","警告 ", MB_YESNOMB_ICONQUESTIONMB_SETFOREGROUNDMB_SYSTEMMODAL)==IDYES)
{
SetTagBit("TAG",1);
}
return;
}

***"确认要停机吗?
":提示语句,自己可以随意更改 "警告":
标题栏名称,自己随意更改

2、乒乓建
{
BOOL Z;
Z=GetTagBit("TAG");
if(Z==0) SetTagBit("TAG",1);
else SetTagBit("TAG",0);
}
**TAG:要置位复位的变量
3、切换画面按钮
{
SetPictureName(lpszPictureName,"PictureWindow1","HS_MODE.Pdl");
//设定PictureWindow1填充为页面HS_MODE.Pdl
SetTagChar("TT","操作模式");        //Return-Type: BOOL //设定字符串变量TT当前值为“操作模式”以显示页眉

}
//页眉属性:heading 字符串type:text tag 16 bit character set
4、设定BIT变量当前值
SetTagBit("N3_VALVE_RESET",0);
5、设定CHAR属性
SetPropBool(“picture1”,”customizedobject1”,”visible1”,false)
图像“picture”里的自定义对象“CUSTOMIZEDOBJECT1”的OLE自动化名称VISIBLE1的自定义属性被设置为0


6、用脚本控制变量修改空间属性
SetPropChar(lpszPictureName,"Picturewindow3","TagPrefix",GetTagChar("charvalve"));
//Text tag 16-bit character set
//更改(charvalve)的值修改属性
SetPictureName(lpszPictureName,"Picturewindow3","NewPdl0.Pdl");


------你这几个脚本都是很实用的,在做工程中经常用到的,最近也在学习C和VB,谢谢了


--------这个题目比较大啊,西门子培训业不过3天,最重要的还是在工程中运用,但是由于工程紧,一般能实现功能记得了。


------请教一个有关WINCC的问题,在做项目的时候,需要在上位机上输入2个参数,速度R 高度H,当PLC检测到R或H为0的时候,在WINCC画面上自动弹出提示框,速度R/高度H的值不能为0!你以前做过此类的项目吗?是怎样的思路解决问题的啊!


关于楼上。你只要在我的帖子的第一条语句前面加上一个if语句就可以完成了。

-----可以的。两层结构。嵌套。C动作跟C语言差不多。

-----乒乓键起的名字不错
脚本的话这样还简单点
SetTagBit("TAG",1-GetTagBit("TAG"));
---------以前就会用C做些简单的画面切换。动态之类的,后来认识了个 朋友才接触VB,不过现在都不用了,所以脚本也基本都忘净了


-----------//用单选框选择画面(共3个);
#define PIC_0 "History sum Picture.PDL"
#define PIC_1 "History sum Picture_Xj.Pdl"
#define PIC_2 "History sum Picture_sq.Pdl"
#define PIC_3 "History sum Picture_xq.Pdl"
switch (value){
case 1: SetPictureName(PIC_0,"main",PIC_1);
break;
case 2: SetPictureName(PIC_0,"main",PIC_2);
break;
case 4: SetPictureName(PIC_0,"main",PIC_3);
break;
}
// 间接寻址;

SetTagChar ( "PID_Text_Name","???????è????_TR05"); //"PID_Text_Name" 是一个Char类型
SetTagChar ( "PID_Text_PV", "TCK-101.12");
SetTagChar ( "PID_Text_SV", "SV_TCK_101.12");
SetTagChar ( "PID_Text_CV", "S7_300_PID_Aout_003.03");
SetTagChar ( "PID_Text_P", "S7_PID_P_003.03");
SetTagChar ( "PID_Text_I", "S7_PID_I_003.03");
SetTagChar ( "PID_Text_D", "S7_PID_D_003.03");
SetTagChar ( "PID_Text_OL", "S7_PID_OL_003.03");
SetTagChar ( "PID_Text_OH", "S7_PID_OH_003.03");
SetTagChar ( "PID_Text_Mout", "S7_300_PID_Mout_003.03");
SetTagChar ( "PID_Text_Man", "S7_300_PID_Man_003.03");

// 对趋势图中的趋势进行更改
SetVisible(lpszPictureName, "Control100", 0 ); //Control100 是趋势图的名称, == 0 表示关闭,写完打开
SetPropWord(lpszPictureName,"Control100","Index",0);
SetPropChar(lpszPictureName,"Control100","TagName","TCK-101.12");

SetPropWord(lpszPictureName,"Control100","Index",1);
SetPropChar(lpszPictureName,"Control100","TagName","SV_TCK_101.12");

SetPropChar(lpszPictureName,"Control100","Command","Reload");
SetVisible(lpszPictureName, "Control100", 1 ); //趋势图打开

// 这个是对位进行的确定;中间的外星文我也不知道是什么情况,那是自己编写的一些警告文字,看心情可自己编写,文字较多必要忘了通过“r\n”进行分段。
BOOL bool1;

HWND Hwnd;

int iRet;

Hwnd = FindWindow(NULL,"WinCC-Runtime - ");

if (!Hwnd) Hwnd = FindWindow(NULL,"WinCC-Runtime - ");

if (!Hwnd) printf("\r\nGetWinCC Handle Failed!");

iRet = MessageBox(Hwnd,"μ¥?÷?°ê??±£??????ˉ×??ˉ???è?ú??£?","×¢òa2ù×÷",MB_YESNOMB_ICONEXCLAMATIONMB_SETFOREGROUNDMB_SYSTEMMODAL);

if(iRet==IDYES)

{

printf("user do YES\r\n");

SetTagBit("Cur_Start_1",1);

}

else

{

printf("user do NO\r\n");

SetTagBit("Cur_Start_1",0);

}

}

//写频率时的确定操作;isetSpeed1 and isetSpeed2 and isetSpeed3 是存放要写入的速度的临时地址;
我把那些火星文给从新翻译过来啦!

float isetSpeed1, isetSpeed2, isetSpeed3;

BOOL bool1;

HWND Hwnd;

int iRet;

isetSpeed1= GetTagFloat("CountSpeed1");
isetSpeed2= GetTagFloat("CountSpeed2");
isetSpeed3= GetTagFloat("CountSpeed3");

Hwnd = FindWindow(NULL,"WinCC-Runtime - ");

if (!Hwnd) Hwnd = FindWindow(NULL,"WinCC-Runtime - ");

if (!Hwnd) printf("\r\nGetWinCC Handle Failed!");

iRet = MessageBox(Hwnd,确定使用以上频率\r\n单击“是”将频率下载到PLC!!\r\n单击“否将取消下载”!!\r\n单击“取消”讲后退到之前画面!!",
"注意操作!",MB_YESNOCANCELMB_ICONEXCLAMATIONMB_SETFOREGROUNDMB_SYSTEMMODAL);

switch (iRet)

{

case IDYES: printf("user do YES\r\n");

SetTagFloat("USS_SV_1Hz", isetSpeed1);
SetTagFloat("USS_SV_2Hz", isetSpeed2);
SetTagFloat("USS_SV_3Hz", isetSpeed3);

break;

case IDNO: printf("user do NO\r\n");

SetTagBit("m00",0);

break;

case IDCANCEL: printf("user do CANCEL\r\n");

break;

}

}

想了想,还有好多,可是还不好找比较简单又实用的,就这样吧!拜拜!

回复

使用道具 举报

大神点评(1)

baikhgmv 楼主 2016-9-18 21:16:43 显示全部楼层
链接上边的
字太多啦,要分开发!

// 利用复选框来选择要显示的趋势;本来有好多个,但是都是一样的做法,就取了前5个的;
哦,对了这个要放在“复选框”的“事件”的“输入输出域”的“选择框”上的“更改”;
上边的太绕口啦、、“复选框”→“事件→“输入输出域”→“选择框”→“更改,嗯,感觉好多啦!
{
int index=1;
DWORD i;
int CurveNum=16;

SetTagDWord("Intex_2", value);

for (index=1;index{
switch (index)
{
case 1:
if ( value&1)
{
SetPropWord(lpszPictureName,"Control100","Index",0);
SetPropChar(lpszPictureName,"Control100","Name"," 1_HaoWangDaiLu_PV\\PV_1");
}
break;
case 2:
if ( value&2)
{
SetPropWord(lpszPictureName,"Control100","Index",1);
SetPropChar(lpszPictureName,"Control100","Name"," 1_HaoWangDaiLu_PV\\PV_2");
}
break;
case 3:
if ( value&4)
{
SetPropWord(lpszPictureName,"Control100","Index",2);
SetPropChar(lpszPictureName,"Control100","Name"," 1_HaoWangDaiLu_PV\\PV_3");
}
break;
case 4:
if ( value&8)
{
SetPropWord(lpszPictureName,"Control100","Index",3);
SetPropChar(lpszPictureName,"Control100","Name"," 1_HaoWangDaiLu_PV\\PV_4");
}
break;
case 5:
if ( value&16)
{
SetPropWord(lpszPictureName,"Control100","Index",4);
SetPropChar(lpszPictureName,"Control100","Name"," 1_HaoWangDaiLu_PV\\PV_5");
}
break;

}
break;
SetPropChar(lpszPictureName,"Control100","Command","Reload");
}

}
}
这个是在网上看到的比较好玩的C代码,一起付上啦,作者不要建议啊;
//PIC_Name 曲线控件画面名称
//CON_Name 曲线控件名称
//TagIref 曲线1归档变量路径

//++++
SetPropWord(PIC_Name,CON_Name,"Index",0);
SetPropChar(PIC_Name,CON_Name,"TagName",TagIref );
SetPropWord(PIC_Name,CON_Name,"Index",1);
SetPropChar(PIC_Name,CON_Name,"TagName",TagIps);
SetPropWord(PIC_Name,CON_Name,"Index",2);
SetPropChar(PIC_Name,CON_Name,"TagName", TagIpn);
SetPropWord(PIC_Name,CON_Name,"Index",3);
SetPropChar(PIC_Name,CON_Name,"TagName",TagUps);
SetPropWord(PIC_Name,CON_Name,"Index",4);
SetPropChar(PIC_Name,CON_Name,"TagName", TagUpn);
SetPropWord(PIC_Name,CON_Name,"Index",5);
SetPropChar(PIC_Name,CON_Name,"TagName",TagRps);
SetPropWord(PIC_Name,CON_Name,"Index",6);
SetPropChar(PIC_Name,CON_Name,"TagName",TagRpn);
SetPropWord(PIC_Name,CON_Name,"Index",7);
SetPropChar(PIC_Name,CON_Name,"TagName",TagLOAD);
SetPropChar(PIC_Name,CON_Name,"Command","Reload");
}
封装的一个函数,一个趋势图7条线!
#include "apdefap.h"
void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
SETUP_TlgOnlineTrend("S0曲线查询.PDL","控件1","1\\11#显示.Iref[A1]","1\\11#显示.Ips[A1]","1\\11#显示.Ipn[A1]","1\\11#显示.Ups[A1]","1\\11#显示.Upn[A1]","1\\11#显示.Rps[A1]","1\\11#显示.Rpn[A1]","1\\11#显示.LOAD[A1]");        //Return-Type: void


// 这个是模板的,就是加上了位置,因为模板比较多,屏幕较大,老是在一个位置显示不好看,是不是,就
先将按钮的位置读上来再写到模板的X,Y上去,搞定!
long x;
long y;
BOOL z;
int a;

x = GetLeft (lpszPictureName,"×é59");
y = GetTop(lpszPictureName,"×é59");
SetTagWord ("Template_X" ,( x - 85)); //?-??????
SetTagWord ("Template_Y" , (y+27));
SetTagChar ("Name" ," 1#加热模板控制");

SetPropChar(lpszPictureName, "画面窗口1","Tagprefix","AOI-00301.");        //Return-Type: BOOL AOI-00301.MPI_MAN
SetPictureName(lpszPictureName,"画面窗口1","加热控制模板.PDL");

SetVisible(lpszPictureName, "画面窗口1", 1 ); //??ê??-??
回复

使用道具 举报

快速回复 返回列表 客服中心 搜索