⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 softplc.cpp 的new

📁 Vxworks 下重矿设备应用开发
💻 CPP 的NEW
📖 第 1 页 / 共 2 页
字号:
		 		sLine[0]=strtok(Str,"\n");  
		 		for (iCnt=1;iCnt<iLineCnt;iCnt++)
					 sLine[iCnt]=strtok(NULL,"\n");
	
				for (iCnt=0;iCnt<iLineCnt;iCnt++)
					{   
						strcpy(sTmp,sLine[iCnt]);
						SeparateALine(sTmp);
					}
       		}
    return;
}      			

/************** 
 * 函数名:Push
 * 功  能: 入栈
 * 
 **************/
void Push(void)
{
	if (iTop==99) ReportErr(PushError);
	Stack[0][iTop] = iInstruction;
	Stack[1][iTop] = bCR;
	iTop=iTop+1;
}

/************** 
 * 函数名:Pop
 * 功  能: 出栈
 * 
 **************/
void Pop(void)
{	
	if (iTop<1) 
	  { 
	  	ReportErr(PopError);
	  }
  	else 
  	  {
	  	iTop=iTop-1;
	  	iInstruction = Stack[0][iTop];
	  	Fl_Pop=1;
	  	RunALine(1);
		Stack[0][iTop] = 0;
		Stack[1][iTop] = 0;
  	  }
}

/************** 
 * 函数名:ExcuteLD
 * 功  能: 执行LD指令
 * 
 **************/
void ExcuteLD(void)
{
	bCR=Addr[iSignal][iFirstAddr][iSecondAddr];
}	

/************** 
 * 函数名:ExcuteLDN
 * 功  能: 执行LDN指令
 * 
 **************/
void ExcuteLDN(void)
{
	bCR=!Addr[iSignal][iFirstAddr][iSecondAddr];
}

/************** 
 * 函数名:ExcuteAND
 * 功  能: 执行AND指令
 * 
 **************/
void ExcuteAND(bool Fl_Pop)
{	if (Fl_Pop==0)
	bCR=bCR&&Addr[iSignal][iFirstAddr][iSecondAddr];
	else bCR=bCR&&Stack[1][iTop];
}

/************** 
 * 函数名:ExcuteANDN
 * 功  能: 执行ANDN指令
 * 
 **************/
void ExcuteANDN(bool Fl_Pop)
{	if (Fl_Pop==0) 
	bCR=bCR&&!(Addr[iSignal][iFirstAddr][iSecondAddr]);
	else bCR=Stack[1][iTop]&&bCR;
}

/************** 
 * 函数名:ExcuteOR
 * 功  能: 执行OR指令
 * 
 **************/
void ExcuteOR(bool Fl_Pop)
{	if (Fl_Pop==0)
	bCR=bCR||Addr[iSignal][iFirstAddr][iSecondAddr];
	else bCR=bCR||Stack[1][iTop];
}

/************** 
 * 函数名:ExcuteORN
 * 功  能: 执行ORN指令
 * 
 **************/
void ExcuteORN(bool Fl_Pop)
{	if (Fl_Pop==0)
	bCR=bCR||!(Addr[iSignal][iFirstAddr][iSecondAddr]);
	else bCR=Stack[1][iTop]||!bCR;
}

/************** 
 * 函数名:ExcuteORN
 * 功  能: 执行ORN指令
 * 
 **************/
void ExcuteXOR(bool Fl_Pop)
{	if (Fl_Pop==0)
	bCR=(((!bCR)&&Addr[iSignal][iFirstAddr][iSecondAddr])||(bCR&&(!Addr[iSignal][iFirstAddr][iSecondAddr])));
	else bCR=(((!bCR)&&Stack[1][iTop])||(bCR&&(!Stack[1][iTop])));

}

/************** 
 * 函数名:ExcuteXORN
 * 功  能: 执行XORN指令
 * 
 **************/
void ExcuteXORN(bool Fl_Pop)
{	if (Fl_Pop==0)
	bCR=((bCR&&Addr[iSignal][iFirstAddr][iSecondAddr])||((!bCR)&&(!Addr[iSignal][iFirstAddr][iSecondAddr])));
	else bCR=((bCR&&Stack[1][iTop])||((!bCR)&&(!Stack[1][iTop])));

}

/************** 
 * 函数名:ExcuteST
 * 功  能: 执行ST指令
 * 
 **************/
void ExcuteST(void)
{
	Addr[iSignal][iFirstAddr][iSecondAddr]=bCR;
}

/************** 
 * 函数名:ExcuteSTN
 * 功  能: 执行STN指令
 * 
 **************/
void ExcuteSTN(void)
{
	Addr[iSignal][iFirstAddr][iSecondAddr]=!bCR;
}

/************** 
 * 函数名:ExcuteS
 * 功  能: 执行S指令
 * 
 **************/
void ExcuteS(void)
{	if (bCR==1)
	Addr[iSignal][iFirstAddr][iSecondAddr]=1;
}

/************** 
 * 函数名:ExcuteR
 * 功  能: 执行R指令
 * 
 **************/
void ExcuteR(void)
{	if (bCR==1)
	Addr[iSignal][iFirstAddr][iSecondAddr]=0;
}


/************** 
 * 函数名:RunALine
 * 功  能: 执行一行PLC语句
 * 
 **************/
void RunALine(bool Flag_Pop)
{	switch (iInstruction)
	{
		case 0:ExcuteLD();break;
		case 1:ExcuteLDN();break;
		case 2:ExcuteAND(Flag_Pop);break;
		case 3:ExcuteANDN(Flag_Pop);break;		
		case 4:ExcuteOR(Flag_Pop);break;
		case 5:ExcuteORN(Flag_Pop);break;
		case 6:ExcuteXOR(Flag_Pop);break;
		case 7:ExcuteXORN(Flag_Pop);break;		
		case 8:ExcuteST();break;
		case 9:ExcuteSTN();break;	
		case 10:ExcuteS();break;	
		case 11:ExcuteR();break;					
		default:ReportErr(iInstructionError);
	}
}

/************** 
 * 函数名:ReportErr
 * 功  能: 报错
 * 
 **************/
void ReportErr(int ErrCode)
{
	printf("\nERROR CODE = %d\n",ErrCode);
}

/************** 
 * 函数名:RunIL
 * 功  能: 运行PLC(Segment)
 * 
 **************/
int RunIL(bool* InPoint,bool* OutPoint)
//int RunIL()
{	char *Sdup;
	int len;

	Addr[0][1][0]=InPoint;
	Addr[0][1][1]=InPoint+1;
	Addr[0][1][2]=InPoint+2;
	Addr[0][1][3]=InPoint+3;
	Addr[0][1][4]=InPoint+4;
	Addr[0][1][5]=InPoint+5;
	Addr[0][2][0]=InPoint+6;
	Addr[0][2][1]=InPoint+7;
	
	
	Addr[1][1][0]=OutPoint;
	Addr[1][1][1]=OutPoint+1;
	Addr[1][1][2]=OutPoint+2;
	Addr[1][1][3]=OutPoint+3;
	Addr[1][1][4]=OutPoint+4;
	Addr[1][1][5]=OutPoint+5; 
	Addr[1][2][0]=OutPoint+6;
	Addr[1][2][1]=OutPoint+7;

	/*Addr[0][1][0]=In[0];
	Addr[0][1][1]=In[1];
	Addr[0][1][2]=In[2];
	Addr[0][1][3]=In[3];
	Addr[0][1][4]=In[4];
	Addr[0][1][5]=In[5];
	Addr[0][2][0]=In[6];
	Addr[0][2][1]=In[7];
	
	Addr[1][1][0]=Out[0];
	Addr[1][1][1]=Out[1];
	Addr[1][1][2]=Out[2];
	Addr[1][1][3]=Out[3];
	Addr[1][1][4]=Out[4];
	Addr[1][1][5]=Out[5]; 
	Addr[1][2][0]=Out[6];
	Addr[1][2][1]=Out[7];	
*/
/**************  
 * IL.txt的多行是用 \x0D \x0A来分隔的
 * 用Segment表示一段文档
**************/
char *Segment= "LD %IX1.0\n OR %QX1.0\n ANDN %IX1.1\n ST %QX1.0\n LDN %QX1.0\n ST %QX1.1\n LD %IX1.2 \n OR %QX1.2 \n ANDN %IX1.3\n ANDN %IX1.5\n ST %QX1.2\n LD %IX1.3 \n OR %QX1.3 \n ANDN %IX1.1 \n ANDN %IX1.2 \n ANDN %IX1.4 \n ST %QX1.3 \n LD %IX1.4 \n OR %QX1.4 \n ANDN %IX1.1 \n ANDN %IX1.2 \n ANDN %IX1.3 \n ST %QX1.4 \n LD %IX1.5 \n OR %QX1.5 \n ANDN %IX1.1 \n ANDN %IX1.2\n ANDN %IX1.4 \n ST %QX1.5 \n LD %IX2.0 \n OR %QX2.0 \n ANDN %IX2.1 \n ST %QX2.0 \n LDN %QX2.0 \n ST %QX2.1 \n" ;	
	len=strlen(Segment);
	Sdup=(char *)malloc(len+1);	          
	strcpy(Sdup,Segment);
	SeparateSeg(Sdup);
	free(Sdup);

	*InPoint=Addr[0][1][0];
	*(InPoint+1)=Addr[0][1][1];
	*(InPoint+2)=Addr[0][1][2];
	*(InPoint+3)=Addr[0][1][3];
	*(InPoint+4)=Addr[0][1][4];
	*(InPoint+5)=Addr[0][1][5];
	*(InPoint+6)=Addr[0][2][0];
	*(InPoint+7)=Addr[0][2][1];
	
	*OutPoint=Addr[1][1][0];
	*(OutPoint+1)=Addr[1][1][1];
	*(OutPoint+2)=Addr[1][1][2];
	*(OutPoint+3)=Addr[1][1][3];
	*(OutPoint+4)=Addr[1][1][4];
	*(OutPoint+5)=Addr[1][1][5];
	*(OutPoint+6)=Addr[1][2][0];
	*(OutPoint+7)=Addr[1][2][1];
	
	/*In[0]=Addr[0][1][0];
	In[1]=Addr[0][1][1];
	In[2]=Addr[0][1][2];
	In[3]=Addr[0][1][3];
	In[4]=Addr[0][1][4];
	In[5]=Addr[0][1][5];
	In[6]=Addr[0][2][0];
	In[7]=Addr[0][2][1];
	
	Out[0]=Addr[1][1][0];
	Out[1]=Addr[1][1][1];
	Out[2]=Addr[1][1][2];
	Out[3]=Addr[1][1][3];
	Out[4]=Addr[1][1][4];
	Out[5]=Addr[1][1][5];
	Out[6]=Addr[1][2][0];
	Out[7]=Addr[1][2][1];*/
		
 return 0; 
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -