Hello, I'm Trying to read Specific CAN-ID from the CAN-Communication to control Digital Ouput.
The problem is:
I used IF-loop to turn on the relay only if CAN-ID 0X25 getting in and the rest IDs don't have to be part of this program. However the programm also take that IDs and deal with it as a part of my program.
void loop() {
SERIAL_PORT_MONITOR.println("In loop");
unsigned char len = 0;
unsigned char buf[8];
unsigned long canId = CAN.getCanId();
if (CAN_MSGAVAIL == CAN.checkReceive()) { // check if data coming CAN_MSGAVAIL:Indicates there are data in FIFO buffer to be read.
CAN.readMsgBuf(&len, buf); // Daten von CAN-Bus auslesen mit [len: Daten Länge]und [buf: data buf]
canId = CAN.getCanId();
Serial.println(canId);
if (canId == cId ) { //Serial.println("CAN ID Korrekt!");
if (bitRead(buf[0], 0) == 1) { // Offene Leitung Relais Kanal_1, Check die Daten von ID.[--] Byte N.0 Bit N.0
digitalWrite(OFL1, 1);
}
else {
digitalWrite(OFL1, 0);
}
}
else {
Serial.println("CAN ID is not for this programm");
Serial.println();
}
}
else Serial.println("CAN READ Communication Failed!!!");
delay(50);
}