Very easy canbus-signal tester.....

Hello

Today i can send canbus from one canbus shield to another but I want the receiver to compare the received data with a master.

Why???
My project:
I will test some different canbus cables and thats because i want to send canbus for maybe 12Hours and then see if any of the package has been broken!

Any help???

/Peter

how much data are you planning to compare?
how is the master data stored? SD card?
would it be simpler to use a USB-Canbus dongle on a PC and compare with data stored on the PC?

Hello!
And thanks for answere!

I think it's enough with one data pack that repeats itself. And in the receiver, compare the package and have a counter that indicates if there is a diff.

I think its a very easy program but i didnt get the function...

I have use the code from seeed-studio at github.

what is the problem?
does the test fail after a time?
post your code?

Sorry, the program are on my computer on my work....

But i use the seeed-studio program send/receive.

The problem is to get the "canbusstring" into one string that i can compare with.
Now i get 8 small string.... ( buf)
How can i do to the 8 (BUF) to be only one!
Hope you get it!

#include <SPI.h>
#include "mcp_can.h"

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN); // Set CS pin

void setup()
{
Serial.begin(115200);

while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}

void loop()
{
unsigned char len = 0;
unsigned char buf[8];

if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf

unsigned int canId = CAN.getCanId();

Serial.println("-----------------------------");
Serial.print("Get data from ID: ");
Serial.println(canId, HEX);

for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf*, HEX);*

  • Serial.print("\t");*
  • }*
  • Serial.println();*
  • }*
    }

after the CAN.readMsgBuf(&len, buf); the incomming message is in buf[] and you can compare it with your test data using memcmp() function

Thanks very much!!!
I will test it!!!

Hello

Have it worked!
But unfortunately, it does not work with canid, somehow I do not get it to work to compare it with an int string.

I also test with " if (id == canId) " but whatever I choose, it does not work.

Do you think that CanId can be something other format??

If I wrote serial.print(myid) and serial.print(canId) its the same but nothing happend in the IF....

how many bits are you using to store canID?
if you are using extended ID (29 bits) try

        unsigned long int canId = CAN.getCanId();