Notifications
CanServiceClient and IOServiceClient expose two kinds of API surface:
- Requests — the methods documented directly on each client (
SendCanMessages,GetVBat,SetCanTermination, ...). You call these; the service replies. - Notifications — messages the service pushes to you, unprompted, when something happens
(a CAN message arrives, the ignition changes state, a DTC is reported). These never appear as a
method on the client. Instead, both clients inherit a single event,
NotificationReceived, from their common base class. Every notification from every service arrives through that one event.
This page covers the notification pattern once, generically, for both services. For the full list
of what each service can send, see CAN Notifications and
IO Notifications below, or browse CanMessageTypes.Ids /
IOMessageTypes.Ids in the API Reference.
Subscribing
Two equivalent ways to subscribe, depending on how your application is structured:
Directly on the event — the callback runs on whatever thread received the underlying socket message:
canClient.NotificationReceived += (_, notif) =>
{
// handle it — see "Handling a Notification" below
};
Through the Dispatcher — the recommended pattern for an application already running the
Ahsoka.Core.Dispatch.Dispatcher main loop (Dispatcher.Default.StartAndRun()). The callback is
marshaled onto the dispatcher's run loop thread instead of the socket thread:
using Ahsoka.Core.Dispatch;
Dispatcher.Default.RegisterCallback<CanServiceClient.AhsokaNotificationArgs>(OnCanNotification, canClient);
Note
Register your callback before calling OpenCommunicationChannel(). Both services can raise
notifications as soon as the channel opens (IO's ignition catch-up notification, for example),
and neither the raw event nor Dispatcher.RegisterCallback buffers anything sent before you
subscribe — you would simply miss it.
Handling a Notification
Every notification carries an AhsokaNotificationArgs with two members: TransportId (which
Ids value this is) and NotificationObject (the payload, typed as object — cast it to the
type documented for that Ids value). Match on TransportId, then cast:
canClient.NotificationReceived += (_, notif) =>
{
if (notif.TransportId == CanMessageTypes.Ids.NetworkStateChanged)
{
var state = (CanState)notif.NotificationObject;
// ...
}
else if (notif.TransportId == CanMessageTypes.Ids.Dm1State)
{
var dtcs = (DiagnosticTroubleCodeState)notif.NotificationObject;
// ...
}
};
The J1939 Requests page walks through a complete example of handling one
specific notification (CanMessageRequested) end to end, including building and sending a
response.
CAN Notifications
CanMessageTypes.Ids value |
Payload | Fires when |
|---|---|---|
NetworkStateChanged |
CanState |
A port's network/address-claim state changed. |
CanMessagesReceived |
CanMessageDataCollection |
One or more CAN messages were received on a subscribed port. |
CanMessageRequested |
CanMessageData |
Another node sent a J1939 RQST for a PGN this application transmits — see J1939 Requests. |
CanErrorCountsChanged |
CanErrorCounts |
The bus-off state or RX/TX error counts changed for a port. |
CanQuietTimerElapsed |
CanQuietTimerElapsed |
The quiet timer set via SetQuietTimer elapsed with no CAN activity. |
Dm1State |
DiagnosticTroubleCodeState |
Active DTCs (J1939 DM1) were received and decoded for a port/source address. |
Dm2State |
DiagnosticTroubleCodeState |
Previously-active DTCs (J1939 DM2) arrived in response to RequestDiagnosticTroubleCodes. |
CanServiceIsReadyNotification |
none | CanService has finished opening every configured port — see Core Concepts. |
CoprocessorRestartNotification |
none | A coprocessor reset was detected mid-session and recovery completed. |
CoprocessorIsReadyNotification and CoprocessorBootNotification also exist on
CanMessageTypes.Ids, but are internal protocol handshakes — the service never raises them to
application clients.
IO Notifications
IOMessageTypes.Ids value |
Payload | Fires when |
|---|---|---|
IgnitionOnNotification / IgnitionOffNotification |
none | The ignition input changed state, or (once) as a catch-up to a client that connects after the state is already known. |
AnalogInputNotification |
AnalogInputList |
Every polling interval (see SetPollingInterval), once a client has set one — sent unconditionally, whether or not values changed. |
DigitalInputNotification |
DigitalInputList |
Same polling cadence as AnalogInputNotification, for digital inputs. |
BatteryVoltageNotification |
VoltageValue |
Battery (VBAT) voltage, forwarded from the coprocessor. |
CoreTemperatureNotification |
TemperatureValue |
Coprocessor core die temperature, forwarded from the coprocessor. |
CoprocessorRestartNotification |
none | A coprocessor reset was detected mid-session (bridged from CanService). |
AnalogOutputNotification, DigitalOutputNotification, and FrequencyInputNotification are also
registered on IOMessageTypes.Ids, but no current platform implementation raises them.
Related docs
- Getting Started — minimal subscribe/open/read example for both services.
- Core Concepts — why
CanServiceIsReadyNotificationmatters before sending CAN messages. - J1939 Requests — a complete worked example built on this pattern.