Kvaser CanKing GUI Extensions SDK v7.6.1
Kvaser CanKing GUI Extensions SDK / hooks
hooks
This module includes React hooks for getting/setting data from/to CanKing.
Remarks
To be able to use these hooks the CanKingDataProvider component must be present in the component tree above your component. Normally the CanKingDataProvider is added at the root of the component tree.
Common hooks
Signal and message data — use these when your view needs live or historical CAN/LIN traffic:
useMessageData / useSignalData — subscribe to a known, fixed set of frames or signals (for example a gauge or custom widget bound to specific signals). Both automatically persist which frames/signals are subscribed to, buffer data received during startup, and clear their data when a new measurement goes online.
useSignalDataEnvelopes — like useSignalData, but returns min/max envelopes over a time window instead of individual samples. Use it to feed a signal plot/graph instead of a table.
useScrollModeMeasurementData / useFixedPositionModeMeasurementData — use these instead when your view needs to show all traffic rather than a fixed set of frames: scroll mode for a trace/log style view (latest data, at most 500 frames), fixed position mode for a dashboard showing the latest value per frame id.
To let the user pick which messages/signals to subscribe to, prefer the ready-made SelectMessageDialog, SelectSignalDialog and SelectSignalsControl components from
@kvaser/canking-api/controlsover building a custom picker. Fall back to useMessageDatabases — which lists the message databases (and their signals) available in the current measurement — only if you need a custom picker UI those controls don’t support.
Measurement setup nodes — use these to inspect the sources, data processors and targets configured in the measurement setup:
useMeasurementSourceNodes / useMeasurementSourceNode — list or look up source nodes (CAN/LIN channels, log replay, traffic generator). Filter by MeasurementSourceNodeType.
useMeasurementDataProcessorNodes / useMeasurementDataProcessorNode — list or look up data processor nodes (CAN message filter, databases, interpreter, extension). Filter by MeasurementDataProcessorNodeType.
useMeasurementTargetNodes / useMeasurementTargetNode — list or look up target nodes (message logger, signal logger, extension). Filter by MeasurementTargetNodeType.
Online status — use these to react to the measurement going online/offline:
useOnlineStatus — the current online/offline state. Use it to disable controls or clear stale data while offline.
useOnlineStatusSync — use this instead of useOnlineStatus when your view needs to run logic exactly once when going online or offline (rather than just reading a flag), and needs to distinguish a freshly-created view from one that’s remounting after being hidden.
Workspace persistence — use these to persist view state so it survives reloads:
useProjectDataSlice / useProjectData — persist data to the CanKing project file. Use this for state the user would expect saved with the project, e.g. a selected channel or configuration.
useSessionDataSlice / useSessionData — persist data to session data instead. Session data survives the view being hidden/shown again, but is not saved to the project file. Use this for transient UI state that shouldn’t pollute the saved project, e.g. the currently selected tab.
Prefer the *Slice variants (useProjectDataSlice, useSessionDataSlice) when a view stores
several independent pieces of data, since each slice is loaded/saved independently under its own key.
Example
import { useUserSettings } from '@kvaser/canking-api/hooks';
...
const userSettings = useUserSettings();