@@ -33,6 +33,15 @@ export enum ThreadPriority {
3333 PriorityError
3434}
3535
36+ export class CanBridgeInitializationError extends Error {
37+ cause : any ;
38+
39+ constructor ( cause : any ) {
40+ super ( "Failed to load the CANBridge native addon. This is likely a packaging problem, or perhaps the Visual Studio C++ redistributable package is not installed. See cause field for details." ) ;
41+ this . cause = cause ;
42+ }
43+ }
44+
3645export class CanBridge {
3746 getDevices : ( ) => Promise < CanDeviceInfo [ ] > ;
3847 registerDeviceToHAL : ( descriptor :string , messageId :Number , messageMask :number ) => number ;
@@ -57,28 +66,33 @@ export class CanBridge {
5766 ackHeartbeats : ( ) => void ;
5867
5968 constructor ( ) {
60- const addon = require ( 'node-gyp-build' ) ( path . join ( __dirname , '..' ) ) ;
61- this . getDevices = promisify ( addon . getDevices ) ;
62- this . registerDeviceToHAL = addon . registerDeviceToHAL ;
63- this . unregisterDeviceFromHAL = promisify ( addon . unregisterDeviceFromHAL ) ;
64- this . receiveMessage = addon . receiveMessage ;
65- this . openStreamSession = addon . openStreamSession ;
66- this . readStreamSession = addon . readStreamSession ;
67- this . closeStreamSession = addon . closeStreamSession ;
68- this . getCANDetailStatus = addon . getCANDetailStatus ;
69- this . sendCANMessage = addon . sendCANMessage ;
70- this . sendHALMessage = addon . sendHALMessage ;
71- this . intializeNotifier = addon . intializeNotifier ;
72- this . waitForNotifierAlarm = promisify ( addon . waitForNotifierAlarm ) ;
73- this . stopNotifier = addon . stopNotifier ;
74- this . writeDfuToBin = promisify ( addon . writeDfuToBin ) ;
75- this . openHALStreamSession = addon . openHALStreamSession ;
76- this . readHALStreamSession = addon . readHALStreamSession ;
77- this . closeHALStreamSession = addon . closeHALStreamSession ;
78- this . setThreadPriority = addon . setThreadPriority ;
79- this . setSparkMaxHeartbeatData = addon . setSparkMaxHeartbeatData ;
80- this . startRevCommonHeartbeat = addon . startRevCommonHeartbeat ;
81- this . ackHeartbeats = addon . ackHeartbeats ;
69+ try {
70+ const addon = require ( 'node-gyp-build' ) ( path . join ( __dirname , '..' ) ) ;
71+
72+ this . getDevices = promisify ( addon . getDevices ) ;
73+ this . registerDeviceToHAL = addon . registerDeviceToHAL ;
74+ this . unregisterDeviceFromHAL = promisify ( addon . unregisterDeviceFromHAL ) ;
75+ this . receiveMessage = addon . receiveMessage ;
76+ this . openStreamSession = addon . openStreamSession ;
77+ this . readStreamSession = addon . readStreamSession ;
78+ this . closeStreamSession = addon . closeStreamSession ;
79+ this . getCANDetailStatus = addon . getCANDetailStatus ;
80+ this . sendCANMessage = addon . sendCANMessage ;
81+ this . sendHALMessage = addon . sendHALMessage ;
82+ this . intializeNotifier = addon . intializeNotifier ;
83+ this . waitForNotifierAlarm = promisify ( addon . waitForNotifierAlarm ) ;
84+ this . stopNotifier = addon . stopNotifier ;
85+ this . writeDfuToBin = promisify ( addon . writeDfuToBin ) ;
86+ this . openHALStreamSession = addon . openHALStreamSession ;
87+ this . readHALStreamSession = addon . readHALStreamSession ;
88+ this . closeHALStreamSession = addon . closeHALStreamSession ;
89+ this . setThreadPriority = addon . setThreadPriority ;
90+ this . setSparkMaxHeartbeatData = addon . setSparkMaxHeartbeatData ;
91+ this . startRevCommonHeartbeat = addon . startRevCommonHeartbeat ;
92+ this . ackHeartbeats = addon . ackHeartbeats ;
93+ } catch ( e : any ) {
94+ throw new CanBridgeInitializationError ( e ) ;
95+ }
8296 }
8397}
8498
0 commit comments