Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

How to use CXAC_Diagnostics?

How to use CXAC_Diagnostics?

Open
Occasional Contributor

Hello Community,

I am new to ctrlX PLC CXAC_Diagnostics library.

Open_0-1671772906410.jpeg

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

or is there any example to use the CXAC_Diagnostics library.

Warmest regards,

3 REPLIES 3

CodeShepherd
Community Moderator
Community Moderator

On you picture I cannot see quite much because of the resolution.

Where did you find the example mentioned by you?

Open
Occasional Contributor

Hello CodeShepherd,

Thank you for your reply.

The image was taken from RM 22.11 update on ctrlX PLC v1.18.

Implemetation:

 

// set diagnostics
MyDiagnostics.MainDiagnosticCode := 16#0A0A0115; // Plc iec info
MyDiagnostics.DetailedDiagnosticCode := 0;
MyDiagnostics.DynamicDescription := 'this is a iec-info-diagnostics';
MyDiagnostics.Entity := 'CompanyName';
SetDiagnostics(IecDiag:= MyDiagnostics );


MyDiagnostics.MainDiagnosticCode := 16#0A0F0115; // Plc iec error
MyDiagnostics.DetailedDiagnosticCode := 0;
MyDiagnostics.DynamicDescription:= 'this is a plc-error-diagnostics';
MyDiagnostics.Entity := 'BoschRexroth';
SetDiagnostics(IecDiag:=MyDiagnostics, Reset :=FALSE );

//get a list of all pending diagnostics

GetPendingDiagnostics(PendingElements=>MyPendingElements , PendingDiagnosticsList=>ReadPendingList );

// reset my diagnosites in the pending diagnostics

MyPendingDiagnostics.MainDiagnosticCode := 16#0A0F0115; // Plc iec error
MyPendingDiagnostics.DetailedDiagnosticCode := 0;
MyPendingDiagnostics.Entity := 'BoschRexroth';
MyResult:=ResetDiagnostics(IecDiag:= MyPendingDiagnostics );

// clear, delete my diagnostics in the pending diagnostics
MyPendingDiagnostics.MainDiagnosticCode := 16#0A0F0115; // Plc iec error
MyPendingDiagnostics.DetailedDiagnosticCode := 0;
MyPendingDiagnostics.Entity := 'BoschRexroth';
MyResult:=ClearDiagnostics (IecDiag:= MyPendingDiagnostics );

// read again all pending diagnostics -> my diagnostics must be deleted
GetPendingDiagnostics(PendingElements=>MyPendingElements , PendingDiagnosticsList=>ReadPendingList );

 

Here is my declaration:

PROGRAM POU
VAR
	MyDiagnostics: CXAC_Diagnostics.IEC_Diagnostics;
	MyPendingElements: word;
	ReadPendingList: ARRAY [0..63] OF CXAC_Diagnostics.Pending_Diagnostics;
	MyPendingDiagnostics: CXAC_Diagnostics.Pending_Diagnostics;
	MyResult: CXAC_Diagnostics.DIAG_RESULT;
END_VAR

I am unsure if i declare the variables correctly?

Warmest regards,

CodeShepherd
Community Moderator
Community Moderator

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

 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist