# Error handling The J1939 and CANopen stacks produces error messages that is transmitted via Data Engine to your application. The default data engine signal name is “fieldbusAccess_J1939Error” or “fieldbusAccess_CANopenError”. If you would like to change it you may start the fieldbusaccess runtime with the argument --name “InstanceName”. Please note that the signal name should start with lower case letter (this will be automatically changed by the runtime). ``` console ./fieldbusaccess --name instanceName FieldbusAccess_ConfigFile.json ``` This would create the data engine signal “instanceName_J1939Error” or “instanceName_CANopenError” available for the application. This should be considered as an advanced feature and is in most cases not needed to be altered. ## J1939 error model LinX Manager Fieldbus injects projects with the following files which are related to error handling: * fieldbusaccesserror.cpp * fieldbusaccesserror.h * fieldbusaccesserrormodel.cpp * fieldbusaccesserrormodel.h Qt projects based on the `CrossControl Qt Quick 2 Application` project template are prepared to work directly with the configurator. LinX Manager Fieldbus Access injects `main.cpp` with the required code to make the configured signals available directly in QML, including the error model. The error model is available in QML as a context property named `j1939ErrorModel`. ``` cpp QQuickView *view = new QQuickView; // // ... FieldbusAccessErrorModel *fieldbusAccessErrorModel = new FieldbusAccessErrorModel(&dataEngineContext); view->rootContext()->setContextProperty("j1939ErrorModel", fieldbusAccessErrorModel); QObject::connect( dataEngineContext.fieldbusAccess_J1939Error_CAN0(), &QByteArrayConsumerSignal::valueChanged, fieldbusAccessErrorModel, [fieldbusAccessErrorModel](QByteArray value){ fieldbusAccessErrorModel->receiveError(value, 0); }); // // ``` The following roles can be access from the `FieldbusAccessErrorModel` model: | Role | Description | |-------------|-------------------------------------------| | bus | Bus nr the error occurred on. | | level | Severity of the error. | | code | Error code. | | identifier | Module ID. | | addInfo | PGN the error is associated with. | | description | Error description. | | started | Time and date when the error started. | | ended | Time and date when the error ended. | | exists | True if error is active, otherwise false. | Value descriptions for the `level`, `code` and `identifier` are found in [J1939 stack errors](stackerror-j1939.md). An example how to access and display errors in QML can be found in [J1939 examples](j1939-examples.md). ## J1939 cyclic timeout monitor detection When an RX (receive) PGN is configured as `Cyclic` in the be automatically monitored for cyclic timeouts (no values received on the CAN bus since last received value + cycle time x 3). As soon as a cycle timeout is detected for a PGN an error message is sent to the application through Data Engine. Every period (cycle time x 3) a new error will be sent. When Fieldbus Access starts to receive values again from the CAN bus an error message is sent once with same code and PGN info except that the error classification is of type ERR_OK. This way it’s possible to validate the status of the values received in your application. ``` qml Text { id: engSpeed text: dataEngine.engSpeed.value visible: dataEngine.engSpeed.status === IDataEngineSignalError.OK } ``` Please view the [Cyclic timeout detection for J1939 SPNs in QML](j1939-examples.md) for information how to setup and access the `status` information of signals. ## CANopen error model LinX Manager Fieldbus Access injects projects with the following files which are related to error handling: * idataenginesignalerror.cpp * idataenginesignalerror.h * fieldbusaccesscanopenstatusmodel.h * fieldbusaccesscanopenstatusmodel.cpp Qt projects based on the `CrossControl Qt Quick 2 Application` project template are prepared to work directly with the configurator. LinX Manager Fieldbus Access injects `main.cpp` with the required code to make the configured signals available directly in QML, including the error model. The error model is available in QML as a context property named `canopenStatusModel`. ``` cpp QQuickView *view = new QQuickView; // // ... FieldbusAccessCANopenStatusModel *canopenStatusModel = new FieldbusAccessCANopenStatusModel(); view->rootContext()->setContextProperty("canopenStatusModel", canopenStatusModel); QObject::connect( dataEngineContext.fieldbusAccess_CANopenError_CAN0(), &ShortConsumerSignal::valueChanged, canopenStatusModel, [canopenStatusModel](short value){ canopenStatusModel->receiveError(value, 0); }); QObject::connect( dataEngineContext.fieldbusAccess_CANopenStatus_CAN0(), &ShortConsumerSignal::valueChanged, canopenStatusModel, [canopenStatusModel](short value){ canopenStatusModel->receiveStatus(value, 0); }); // // ``` The following roles can be access from the `FieldbusAccessCANopenStatusModel` model: | Role | Description | |----------|--------------------------------------------| | bus | Bus nr the error occurred on. | | type | Severity of the error. | | code | Error code. | | message | Error description. | | received | Time and date when the error was received. | Value descriptions for the `type`, `code` and `message` are found in [CANopen stack errors](stackerror-canopen.md). An example how to access and display errors in QML can be found in [CANopen examples](canopen-examples.md).