sebi2k1 / node-can

NodeJS SocketCAN extension
223 stars 73 forks source link

create channel fail in nest.js #132

Closed Dingcy closed 11 months ago

Dingcy commented 11 months ago

this is my code , create channel fail node version: v16.17.0 socketcan version: 4.0.2

// socketcan.service.ts import { BusinessException } from '@app/common'; import { Injectable } from '@nestjs/common'; const can = require('socketcan');

@Injectable() export class SocketCanService { private channel;

constructor() { }

start() { try { console.log(can);

  this.channel = can.createRawChannel('can0',true);

  this.channel.addListener('onMessage', (msg) => {

    if (msg.id === 0x508) {

      console.log('Received CAN message with ID 0x508:', msg);
    }
  });

  this.channel.start();
} catch (error) {
  console.log(error);
  throw new BusinessException(error)
}

}

send(message) {

this.channel.send(message);

} }

Error is below: Error: Error while creating channel at Object.createRawChannel (/home/app/node_modules/socketcan/src/socketcan.ts:52:9) at SocketCanService.start (/home/app/src/socketcan/socketcan.service.ts:17:26) at SocketController.startSocketCAN (/home/app/src/socketcan/socketcan.controller.ts:17:27) at /home/app/node_modules/@nestjs/core/router/router-execution-context.js:38:29 at InterceptorsConsumer.transformDeferred (/home/app/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:31:33) at /home/app/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:15:53 at Observable._subscribe (/home/app/node_modules/rxjs/src/internal/observable/defer.ts:55:15) at Observable._trySubscribe (/home/app/node_modules/rxjs/src/internal/Observable.ts:245:19) at /home/app/node_modules/rxjs/src/internal/Observable.ts:235:18 at Object.errorContext (/home/app/node_modules/rxjs/src/internal/util/errorContext.ts:29:5)

Dingcy commented 11 months ago

solved