How to use CXAC_Diagnostics?

Hello Community,

I am new to ctrlX PLC CXAC_Diagnostics library.

I saw this example how should i declare MyPendingDiagnostics and MyDiagnostics.

or is there any example to use the CXAC_Diagnostics library.

Warmest regards,

Best reply by CodeShepherd

See online documentation for the library CXAC_Diagnostics and my hints and example below.

  • See online documentation for a description of the diagnostic code
  • Test.json file needs to be at "ActiveConfiguration/plc/run/linux-gcc-x64/data" and can be put there via ctrlX PLC Engineering or WebDAV
  • Only reset errors can be cleared and warnings do not need / cannot be cleared
  • Problems in verison 1.18:
    • Function "UnregisterDiagnostics" has no function
    • Fuctions "SetDiagnostics" and "ResetDiagnostics" give back an error even when function was executed properly (still investigating this)
    • The Pending error list will always show one item more then actually visible in the ctrlX CORE WebUI

Test.json:

 

{
	"language": "en-us",
	"product": "XCR-V-0118",
	"component": "plc.iec",
	"mainDiagnostics": 
	[
		{
			"number": "0E0F0815",
			"version": "1",
			"text": "Some error",
			"detailedDiagnostics": 
			[
				{
					"number": "00000001",
					"version": "1",
					"text": "Error 1"
				},
				{
					"number": "00000002",
					"version": "1",
					"text": "Error 2"				
				}
			]
		},
		{
			"number": "0E0E0815",
			"version": "1",
			"text": "Some Warning",
			"detailedDiagnostics": 
			[
				{
					"number": "00000001",
					"version": "1",
					"text": "Warning 1"
				},
				{
					"number": "00000002",
					"version": "1",
					"text": "Warning 2"
				}
			]
		},
		{
			"number": "0E0A0815",
			"version": "1",
			"text": "Some Message",
			"detailedDiagnostics": 
		    [
				{
					"number": "00000001",
					"version": "1",
					"text": "Note 1"
				},
				{
					"number": "00000002",
					"version": "1",
					"text": "Note 2"
				}
			]
		}
	]
}

 

Declaration:

 

PROGRAM PLC_PRG
VAR
	// register diagnostic
	bRegisterDiag: BOOL;
	FileName: STRING(255) := 'Test.json';
	ResultRegister: CXAC_Diagnostics.DIAG_RESULT;
	// unregister diagnostic
	bUnRegisterDiag: BOOL;
	ResultUnregister: CXAC_Diagnostics.DIAG_RESULT;
	// set diagnostics
	bSetDiag: BOOL;
	strEntity: STRING(255) := 'CompanyName';
	//Set Error
	MyDiagnostics: CXAC_Diagnostics.IEC_Diagnostics;
	udiMainDiagCodeError		: UDINT := 16#0E0F0815;
	udiDetailDiagCodeError		: UDINT := 16#00000001;
	ResultSetError: CXAC_Diagnostics.DIAG_RESULT;
	//Set Warning
	udiMainDiagCodeWarning		: UDINT := 16#0E0E0815;
	udiDetailDiagCodeWarning	: UDINT := 16#00000001;
	ResultSetWarning: CXAC_Diagnostics.DIAG_RESULT;
	//Set Note
	udiMainDiagCodeNote			: UDINT := 16#0E0A0815;
	udiDetailDiagCodeNote		: UDINT := 16#00000001;
	ResultSetNote: CXAC_Diagnostics.DIAG_RESULT;
	//get a list of all pending diagnostics
	bGetPendingDiag: BOOL;
	MyPendingElements: WORD;
	ReadPendingList: ARRAY [0..63] OF CXAC_Diagnostics.Pending_Diagnostics;
	ResultGetPending: CXAC_Diagnostics.DIAG_RESULT;	
	// reset/clear diagnostics
	bReset: BOOL := TRUE;
	MyPendingDiagnostics: CXAC_Diagnostics.Pending_Diagnostics;
	// reset error	
	bResetError: BOOL;	
	ResultResetError: CXAC_Diagnostics.DIAG_RESULT;
	// clear error (only resetted errors can be cleared)
	bClearError: BOOL;
	ResultClearError: CXAC_Diagnostics.DIAG_RESULT;
	// reset warning (warnings do not need / cannot be cleared)
	bResetWarning: BOOL;
	ResultResetWarning: CXAC_Diagnostics.DIAG_RESULT;		
END_VAR

 

Implementation:

 

// register diagnostic
IF bRegisterDiag THEN
	bRegisterDiag := FALSE;
	ResultRegister := RegisterDiagnostics(JsonFile:= FileName);
END_IF

// unregister diagnostic
IF bUnRegisterDiag THEN
	bUnRegisterDiag := FALSE;
	ResultUnregister := UnregisterDiagnostics(JsonFile:= FileName);
END_IF

// set diagnostics
IF bSetDiag THEN
bSetDiag := FALSE;
//Set Error
MyDiagnostics.MainDiagnosticCode := udiMainDiagCodeError; 
MyDiagnostics.DetailedDiagnosticCode := udiDetailDiagCodeError;
MyDiagnostics.DynamicDescription := 'This is a test error';
MyDiagnostics.Entity := strEntity;
ResultSetError := SetDiagnostics(IecDiag:= MyDiagnostics, Reset := bReset );

//Set Warning
MyDiagnostics.MainDiagnosticCode := udiMainDiagCodeWarning;
MyDiagnostics.DetailedDiagnosticCode := udiDetailDiagCodeWarning;
MyDiagnostics.DynamicDescription:= 'This is a test warning';
MyDiagnostics.Entity := strEntity;
ResultSetWarning := SetDiagnostics(IecDiag:=MyDiagnostics, Reset := bReset );

//Set Note
MyDiagnostics.MainDiagnosticCode :=  udiMainDiagCodeNote;
MyDiagnostics.DetailedDiagnosticCode := udiDetailDiagCodeNote;
MyDiagnostics.DynamicDescription:= 'This is a test message';
MyDiagnostics.Entity := strEntity;
ResultSetNote := SetDiagnostics(IecDiag:=MyDiagnostics, Reset := FALSE ); //Message cannot be reset
END_IF

//get a list of all pending diagnostics
IF bGetPendingDiag THEN
bGetPendingDiag := FALSE;
ResultGetPending := GetPendingDiagnostics(PendingElements=>MyPendingElements , PendingDiagnosticsList=>ReadPendingList );
END_IF

// reset/clear diagnostics
// reset error
IF bResetError THEN
bResetError := FALSE;
MyPendingDiagnostics.MainDiagnosticCode := udiMainDiagCodeError;
MyPendingDiagnostics.DetailedDiagnosticCode := udiDetailDiagCodeError;
MyPendingDiagnostics.Entity := strEntity;
ResultResetError:=ResetDiagnostics(IecDiag:= MyPendingDiagnostics );
END_IF

// clear error (only reset errors can be cleared)
IF bClearError THEN
bClearError := FALSE;
MyPendingDiagnostics.MainDiagnosticCode := udiMainDiagCodeError;
MyPendingDiagnostics.DetailedDiagnosticCode := udiDetailDiagCodeError;
MyPendingDiagnostics.Entity := strEntity;
ResultClearError:=ClearDiagnostics (IecDiag:= MyPendingDiagnostics );
END_IF

// reset warning (warnings do not need / cannot be cleared)
IF bResetWarning THEN
bResetWarning := FALSE;
MyPendingDiagnostics.MainDiagnosticCode := udiMainDiagCodeWarning;
MyPendingDiagnostics.DetailedDiagnosticCode := udiDetailDiagCodeWarning;
MyPendingDiagnostics.Entity := strEntity;
ResultResetWarning:=ResetDiagnostics(IecDiag:= MyPendingDiagnostics );
END_IF

 

View original
3 replies