Beispiel #1
0
 int _GetLGXValueAsInteger(LGX_Read *reply,int index)
{
	return(_GetLGXValueAsFloat(reply,index));
}
Beispiel #2
0
int main(int argc,char *argv[])
{
	//cip_debuglevel=LogDebug; // You can uncomment this line to see the data exchange between TuxEip and your Logic controller

	char *IP="192.168.1.3\0";
	BYTE path[]={1,1,2,5,1,0};
// 	char *IP="10.140.200.48\0";
// 	BYTE path[]={1,8,2,4,1,0};
	int res;
	char *var;
	
	printf("Starting, Pid = %d\n",getpid());

	if (argc<2)
	{
		printf("You have to provide a tag name\n");
		return(1);
	}
	var=argv[1];
			
	/* Openning a session */	
	printf("entering OpenSession \n");

	Eip_Session *session=OpenSession(IP);
	if (session==NULL)
	{
		printf("Error : OpenSession %s (%d:%d)\n",cip_err_msg,cip_errno,cip_ext_errno);
		return(1);
	}
	printf("OpenSession Ok\n");
	printf("entering RegisterSession \n");
	res=RegisterSession(session);

	if (res!=Error)
	{ int i,val_int;
		float val_float;
		printf("RegisterSession Ok\n");
		printf("entering ConnectPLCOverCNET\n");
		Eip_Connection *connection=ConnectPLCOverCNET(
			session, // session whe have open
			LGX, // plc type
			0x12345678, // Target To Originator connection ID
			0x6789, // Connection Serial Number
			5000, // Request Packet Interval
			path, // Path to the ControlLogix
			sizeof(path) // path size
			);

		if (connection!=NULL)
		{
			printf("ConnectPLCOverCNET Ok, \n");
			
			printf("Reading %s\n",var);
			LGX_Read *data=ReadLgxData(session,connection,var,1);
			if (data!=NULL)
			{
				if (data->Varcount>0)
				{
					printf("ReadLgxData Ok :\n");
					printf("\telements :%d\n\tDatatype : %d\n\ttotalsize : %d\n\tElement size : %d\n",data->Varcount,data->type,data->totalsize,data->elementsize,data->mask);
					for (i=0;i<data->Varcount;i++)
					{
						val_int=_GetLGXValueAsInteger(data,i);
						val_float=_GetLGXValueAsFloat(data,i);
						printf("Value [%d] = %f (%d)\n",i,val_float,val_int);
					}
				} else printf("Error ReadLgxData : %s\n",cip_err_msg);
				free(data); // You have to free the data return by ReadLgxData
			} else
			{
				printf("Error : ReadLgxData %s (%d:%d)\n",cip_err_msg,cip_errno,cip_ext_errno);
			}
			
			val_int++;
			printf("Writing %s=%d\n",var,val_int);
			//res=WriteLgxData(session,connection,var,LGX_INT,&val_int,1);
			if(res!=Error) printf("WriteData Ok\n");
				else printf("Error : WriteData %s (%d:%d)\n",cip_err_msg,cip_errno,cip_ext_errno);
				
			printf("entering Forward_Close\n");
			res=Forward_Close(connection);
			if (res!=Error)	printf("Forward_Close %s\n",cip_err_msg);
				else printf("Error : Forward_Close %s (%d:%d)\n",cip_err_msg,cip_errno,cip_ext_errno);
		} else
		{
			printf("Error : ConnectPLCOverCNET %s (%d:%d)\n",cip_err_msg,cip_errno,cip_ext_errno);
		}	
		UnRegisterSession(session);	
		printf("UnRegister : %s\n",cip_err_msg);
	}else 
	{
		printf("Error : RegisterSession %s (%d:%d)\n",cip_err_msg,cip_errno,cip_ext_errno);
	}
	printf("entering CloseSession\n");
	CloseSession(session);

	return(0);
}