FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We are updating our platform to a new
system.
Read more: Important
information on the platform change.
12-23-2022 06:34 AM
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,
Solved! Go to Solution.
01-05-2023 04:36 PM
On you picture I cannot see quite much because of the resolution.
Where did you find the example mentioned by you?
01-06-2023 03:06 AM
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,
01-11-2023 09:00 AM - edited 10-23-2023 07:52 AM
See online documentation for the library CXAC_Diagnostics and my hints and example below.
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