@canboat/canboatjs 2.12.2 → 2.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/canbus.js +11 -2
  2. package/package.json +1 -1
package/lib/canbus.js CHANGED
@@ -73,7 +73,7 @@ function CanbusStream (options) {
73
73
  this.socketcan = require('socketcan')
74
74
  } catch ( err ) {
75
75
  console.error(err)
76
- var msg = 'WARNING unable to load native socketcan interface'
76
+ var msg = 'unable to load native socketcan interface'
77
77
  console.error(msg)
78
78
  }
79
79
 
@@ -90,7 +90,9 @@ function CanbusStream (options) {
90
90
 
91
91
  var canDevice = options.canDevice || 'can0'
92
92
 
93
- this.connect()
93
+ if ( this.connect() == false ) {
94
+ return
95
+ }
94
96
 
95
97
  const noDataReceivedTimeout = typeof options.noDataReceivedTimeout !== 'undefined' ? options.noDataReceivedTimeout : -1
96
98
  if ( noDataReceivedTimeout > 0 ) {
@@ -114,6 +116,11 @@ function CanbusStream (options) {
114
116
 
115
117
  CanbusStream.prototype.connect = function() {
116
118
  try {
119
+ if ( this.socketcan === undefined ) {
120
+ this.setProviderError('unable to load native socketcan interface')
121
+ return false
122
+ }
123
+
117
124
  var that = this
118
125
  var canDevice = this.options.canDevice || 'can0'
119
126
  this.channel = this.socketcan.createRawChannelWithOptions(canDevice, { non_block_send: true} );
@@ -153,10 +160,12 @@ CanbusStream.prototype.connect = function() {
153
160
  this.setProviderStatus('Connected to socketcan')
154
161
  this.candevice = new CanDevice(this, this.options)
155
162
  this.candevice.start()
163
+ return true
156
164
  } catch (e) {
157
165
  console.error(`unable to open canbus ${canDevice}: ${e}`)
158
166
  console.error(e.stack)
159
167
  this.setProviderError(e.message)
168
+ return false
160
169
  }
161
170
  }
162
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "2.12.2",
3
+ "version": "2.12.3",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {