其实就是正常使用,我连了一台S7-200,然后做组合控制。 在屏幕上先进行几个回路的设定,然后就编写了一个宏,在宏里面去判断这几个回路是否符合组合规律,其实就是一些for循环和If判断,但是不知道为什么运行起来那么慢,大概要5~10秒中才能运行完,甚至更长,难道步科的屏幕都是这样吗?
下面是程序:
#include "macrotypedef.h"
#include "math.h"
int MacroEntry()
{
int i=0;
int j=0;
unsigned int Order_Num[4]={M0,M1,M2,M3}; //顺控设定的数字
unsigned int Double_Ctrl[4]={M4,M5,M6,M7}; //双速设定的数字
int Flag_no_repeat=0;
Flag_Order=0;
Flag_S_D=0;
Flag_D_D=0;
S_1=0;
S_0=0;
//顺序控制
if(Order_Num[0]!=Order_Num[1]&&Order_Num[0]!=Order_Num[2]&&Order_Num[0]!=Order_Num[3]&&Order_Num[1]!=Order_Num[2]&&Order_Num[1]!=Order_Num[3]&&Order_Num[2]!=Order_Num[3]&&Order_Num[0]!=0&&Order_Num[1]!=0&&Order_Num[2]!=0&&Order_Num[3]!=0)
{
Flag_Order=1;
}
//单机双速控制
if(Double_Ctrl[0]!=Double_Ctrl[2]&&Double_Ctrl[0]!=0&&Double_Ctrl[1]==0&&Double_Ctrl[2]!=0&&Double_Ctrl[3]==0)
{
Flag_S_D=1;
}
//双机双速控制
if(Double_Ctrl[0]!=Double_Ctrl[1]&&Double_Ctrl[0]!=Double_Ctrl[2]&&Double_Ctrl[0]!=Double_Ctrl[3]&&Double_Ctrl[1]!=Double_Ctrl[2]&&Double_Ctrl[1]!=Double_Ctrl[3]&&Double_Ctrl[2]!=Double_Ctrl[3]&&Double_Ctrl[0]!=0&&Double_Ctrl[1]!=0&&Double_Ctrl[2]!=0&&Double_Ctrl[3]!=0)
{
Flag_D_D=1;
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if((Order_Num[i]==Double_Ctrl[j])&&Order_Num[i]!=0) //顺序控制和双速控制中有重复的数值,弹出重复界面
{
FLAG_S_1=0;
FLAG_S_1=1; //0->1 : 触发“重复界面”
S_1=1;
Flag_no_repeat=1;
break;
}
}
}
if(Flag_no_repeat==0)
{
for(i=0;i<4;i++)
for(j=i+1;j<4;j++)
{
if(Order_Num[i]==Order_Num[j]&&Order_Num[i]!=0)
{
FLAG_S_1=0;
FLAG_S_1=1; //0->1 : 触发“重复界面”
S_1=1;
Flag_no_repeat=1;
break;
}
}
}
if(Flag_no_repeat==0)
{
for(i=0;i<4;i++)
for(j=i+1;j<4;j++)
{
if(Double_Ctrl[i]==Double_Ctrl[j]&&Double_Ctrl[i]!=0)
{
FLAG_S_1=0;
FLAG_S_1=1; //0->1 : 触发“重复界面”
S_1=1;
Flag_no_repeat=1;
break;
}
}
}
if(Flag_no_repeat==0)
{
FLAG_S_0=0;
FLAG_S_0=1; //0->1 : 触发"有效界面”
S_0=1;
}
return 0;
}