ARSim Boot Error with additional data for ArEventWrite

Hi,

I am getting a boot error in ARSim due to the following lines of code related to ArEventLogWrite:

strcpy ((char*)ArEventLogWrite_0.AddData, str);
ArEventLogWrite_0.AddDataSize = strlen(str)+1;
ArEventLogWrite_0.AddDataFormat = arEVENTLOG_ADDFORMAT_TEXT;

I was wondering if anyone know what is the issue? I have defined str as a global variable:
char str=“test msg”;

Attached the whole program:

#include <bur/plctypes.h>
#include
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif

// amount of memory to be allocated for heap storage must be specified for every ANSI C++ program with the bur_heap_size variable
unsigned long bur_heap_size = 0xFFFF;
char str=“test msg”;
void _INIT ProgramInit(void)
{
// Insert code here
//arEventLogStr = “this is additional info”;
//ArEventLogWrite_0.AddData = &arEventLogStr;

}

void _CYCLIC ProgramCyclic(void)
{
switch (Step)
{
case 0:
// Add Start Condition if nessesary
Step = 5;

		break;
	
	case 5:
		ArEventLogGetIdent_0.Name[0] = 'a';
		ArEventLogGetIdent_0.Execute = false; 

		ArEventLogGetIdent(&ArEventLogGetIdent_0);
	
		Step = 10; 
	
		break;
	
	case 10:

		ArEventLogGetIdent_0.Execute = true; 
		ArEventLogGetIdent(&ArEventLogGetIdent_0);
		
		if (ArEventLogGetIdent_0.Done) 
		{
			Ident = ArEventLogGetIdent_0.Ident; 
			ArEventLogGetIdent_0.Execute = false; 
			Step = 30;		// Write 
		}			
		else if (ArEventLogGetIdent_0.Error) 
		{
			if (ArEventLogGetIdent_0.StatusID == arEVENTLOG_ERR_LOGBOOK_NOT_FOUND)
			{
				Step = 20; 	// create
				
				ArEventLogCreate_0.Name[0] 		= 'a'; 
				ArEventLogCreate_0.Size 		= 65535;
				ArEventLogCreate_0.Persistence 	= arEVENTLOG_PERSISTENCE_PERSIST;
				ArEventLogCreate_0.Info 		= 0;
				ArEventLogCreate_0.Execute 		= false;
				ArEventLogCreate(&ArEventLogCreate_0);
				
			}
			else
			{
				Step = 255; // error 	
			}
		}
		
		break;
	
	case 20:
		
		
		ArEventLogCreate_0.Execute = true; 
		ArEventLogCreate(&ArEventLogCreate_0);
		
		if (ArEventLogCreate_0.Done) 
		{
			Ident = ArEventLogCreate_0.Ident;
			ArEventLogCreate_0.Execute = false; 
			Step = 30;		// Write 
		}
		else if (ArEventLogCreate_0.Error) 
		{
			Step = 255; // error 	
		}
		
		break;
		
	case 30:
		
		ArEventLogWrite_0.Ident				= Ident; 
		ArEventLogWrite_0.EventID			= 536870912;
		ArEventLogWrite_0.OriginRecordID	= 0; 
		//ArEventLogWrite_0.AddDataSize		= 0; 	
		//ArEventLogWrite_0.AddDataFormat		= 1; 
		//ArEventLogWrite_0.AddData			= 0;
		ArEventLogWrite_0.ObjectID[0]		        = '2';
		ArEventLogWrite_0.TimeStamp			= 0; 	
	
		strcpy ((char*)ArEventLogWrite_0.AddData, str);
		ArEventLogWrite_0.AddDataSize = strlen(str)+1;
		ArEventLogWrite_0.AddDataFormat = arEVENTLOG_ADDFORMAT_TEXT;
		
		ArEventLogWrite_0.Execute			        = true; 
		ArEventLogWrite(&ArEventLogWrite_0);	// synchron fub call 
	
		ArEventLogWrite_0.Execute			       = false; 
		ArEventLogWrite(&ArEventLogWrite_0);	// synchron fub call 
	
		Step = 40;
	
		break;
	
	case 40:
	
		break;
	
}

}

void _EXIT ProgramExit(void)
{
// Insert code here

}

I found the error, need to set the str address instead of strcpy:

		ArEventLogWrite_0.AddData = (unsigned int)str;

The whole program below:

#include <bur/plctypes.h>
#include
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif

// amount of memory to be allocated for heap storage must be specified for every ANSI C++ program with the bur_heap_size variable
unsigned long bur_heap_size = 0xFFFF;
char str=“test msg”;
void _INIT ProgramInit(void)
{
// Insert code here
//arEventLogStr = “this is additional info”;
//ArEventLogWrite_0.AddData = &arEventLogStr;

}

void _CYCLIC ProgramCyclic(void)
{
switch (Step)
{
case 0:
// Add Start Condition if nessesary
Step = 5;

		break;
	
	case 5:
		ArEventLogGetIdent_0.Name[0] = 'a';
		ArEventLogGetIdent_0.Execute = false; 

		ArEventLogGetIdent(&ArEventLogGetIdent_0);
	
		Step = 10; 
	
		break;
	
	case 10:

		ArEventLogGetIdent_0.Execute = true; 
		ArEventLogGetIdent(&ArEventLogGetIdent_0);
		
		if (ArEventLogGetIdent_0.Done) 
		{
			Ident = ArEventLogGetIdent_0.Ident; 
			ArEventLogGetIdent_0.Execute = false; 
			Step = 30;		// Write 
		}			
		else if (ArEventLogGetIdent_0.Error) 
		{
			if (ArEventLogGetIdent_0.StatusID == arEVENTLOG_ERR_LOGBOOK_NOT_FOUND)
			{
				Step = 20; 	// create
				
				ArEventLogCreate_0.Name[0] 		= 'a'; 
				ArEventLogCreate_0.Size 		= 65535;
				ArEventLogCreate_0.Persistence 	= arEVENTLOG_PERSISTENCE_PERSIST;
				ArEventLogCreate_0.Info 		= 0;
				ArEventLogCreate_0.Execute 		= false;
				ArEventLogCreate(&ArEventLogCreate_0);
				
			}
			else
			{
				Step = 255; // error 	
			}
		}
		
		break;
	
	case 20:
		
		
		ArEventLogCreate_0.Execute = true; 
		ArEventLogCreate(&ArEventLogCreate_0);
		
		if (ArEventLogCreate_0.Done) 
		{
			Ident = ArEventLogCreate_0.Ident;
			ArEventLogCreate_0.Execute = false; 
			Step = 30;		// Write 
		}
		else if (ArEventLogCreate_0.Error) 
		{
			Step = 255; // error 	
		}
		
		break;
		
	case 30:
		
		ArEventLogWrite_0.Ident				= Ident; 
		ArEventLogWrite_0.EventID			= 536870912;
		ArEventLogWrite_0.OriginRecordID	= 0; 
		ArEventLogWrite_0.ObjectID[0]		        = '3';
		ArEventLogWrite_0.TimeStamp			= 0; 	
	
		ArEventLogWrite_0.AddData = (unsigned int)str;
		ArEventLogWrite_0.AddDataSize = strlen(str)+1;
		ArEventLogWrite_0.AddDataFormat = arEVENTLOG_ADDFORMAT_TEXT;
		
		ArEventLogWrite_0.Execute			        = true; 
		ArEventLogWrite(&ArEventLogWrite_0);	// synchron fub call 
	
		ArEventLogWrite_0.Execute			       = false; 
		ArEventLogWrite(&ArEventLogWrite_0);	// synchron fub call 
	
		Step = 40;
	
		break;
	
	case 40:
	
		break;
	
}

}

void _EXIT ProgramExit(void)
{
// Insert code here

}

Hello,
Good that you found it by urself. Can you mark the Thread as solved, it works also on your own posts.

Greetings
Michael

1 Like