sebi2k1 / node-can

NodeJS SocketCAN extension
215 stars 72 forks source link

can id data type #121

Closed haticenurel closed 11 months ago

haticenurel commented 11 months ago

I would like to write an issue message regarding the problem with the can id number in this library. The id numbers are being displayed as hex values (e.g., 0x7FF), and as a result, it doesn't show values beyond 0x7FF. I believe using 'number' for representation limits the available space. Is there a way we can fix this?

sebi2k1 commented 11 months ago

To which tool do you refer? The dump script?

haticenurel commented 11 months ago

I meant send method

sebi2k1 commented 11 months ago

You have a code example? I don’t really understand the problem you are having.

haticenurel commented 11 months ago

You will understand when you try to send a message with can id bigger than 0x7FF to a channel . As you can see here: async Dork() { let i = 0x100; const newData = [0x03, 0x20, 0x01, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA];

while (true) {
    this.channel.send({
        id: i,
        data: Buffer.from(newData), 
    });

    await this.Delay(2);

    if (i >= 0xFFF)
        break;
    i++;
}

} The code keeps sending packets until the id value reaches 0xFFF. But this loop ends on 0x7FF. I think using 'number' for representation limits the available space.

sebi2k1 commented 11 months ago

Values > 0x7ff are not allowed when you send standard frame format by CAN spec. If you wanna send bigger values you have to send frames in extended frame format.

haticenurel commented 11 months ago

I didn't know that, thanks for letting me know.