invalid operands of types 'int' and 'void' to binary 'operator=='

Doing CAN bus test, the error : invalid operands of types ‘int’ and ‘void’ to binary ‘operator==’
turn out on line: if(CAN_OK == CAN.begin(CAN_500KBPS))
need help. Thanks

#include "mcp_can.h"
INT32U canId = 0x000;

////
#include <CAN.h>
#include <SPI.h>

#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

////


//2024    4    65    12    18    248    185    147
 
unsigned char len = 0;
unsigned char buf[8];
char str[20];
String BuildMessage="";
int MSGIdentifier=0;
void setup()
{
    Serial.begin(38400);
START_INIT:

 if(CAN_OK == CAN.begin(CAN_500KBPS))
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}

void loop()
{
    char rndCoolantTemp=random(1,200);
    char rndRPM=random(1,55);
    char rndSpeed=random(0,255);
    char rndIAT=random(0,255);
    char rndMAF=random(0,255);
    char rndAmbientAirTemp=random(0,200);
    char rndCAT1Temp=random(1,55);
    
    //GENERAL ROUTINE
    unsigned char SupportedPID[8] =       {1,2,3,4,5,6,7,8};
    unsigned char MilCleared[7] =         {4, 65, 63, 34, 224, 185, 147}; 
    
    //SENSORS
    unsigned char CoolantTemp[7] =        {4, 65, 5, rndCoolantTemp, 0, 185, 147};  
    unsigned char rpm[7] =                {4, 65, 12, rndRPM, 224, 185, 147};
    unsigned char vspeed[7] =             {4, 65, 13, rndSpeed, 224, 185, 147};
    unsigned char IATSensor[7] =          {4, 65, 15, rndIAT, 0, 185, 147};
    unsigned char MAFSensor[7] =          {4, 65, 16, rndMAF, 0, 185, 147};
    unsigned char AmbientAirTemp[7] =     {4, 65, 70, rndAmbientAirTemp, 0, 185, 147};
    unsigned char CAT1Temp[7] =           {4, 65, 60, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT2Temp[7] =           {4, 65, 61, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT3Temp[7] =           {4, 65, 62, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT4Temp[7] =           {4, 65, 63, rndCAT1Temp, 224, 185, 147};


     if(CAN_MSGAVAIL == CAN.checkReceive())  
    {
      
      CAN.readMsgBuf(&len, buf); 
        canId = CAN.getCanId();
        Serial.print("<");Serial.print(canId);Serial.print(",");

for(int i = 0; i
        BuildMessage="";
    }
    
}

sketch_oct28a:34:36: error: invalid operands of types ‘int’ and ‘void’ to binary ‘operator==’

if(CAN_OK == CAN.begin(CAN_500KBPS))

^

C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_oct28a\sketch_oct28a.ino: In function ‘void loop()’:

sketch_oct28a:74:29: error: ‘class CAN_MCP2515’ has no member named ‘checkReceive’

if(CAN_MSGAVAIL == CAN.checkReceive())

^

sketch_oct28a:77:11: error: ‘class CAN_MCP2515’ has no member named ‘readMsgBuf’

CAN.readMsgBuf(&len, buf);

^

sketch_oct28a:78:21: error: ‘class CAN_MCP2515’ has no member named ‘getCanId’

canId = CAN.getCanId();

^

sketch_oct28a:82:9: error: expected ‘;’ before ‘BuildMessage’

BuildMessage="";

^

sketch_oct28a:82:24: error: expected ‘)’ before ‘;’ token

Multiple libraries were found for “mcp_can.h”
BuildMessage="";

Used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\MCP_CAN_lib-master
^

Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\MCP2515_lib-master
Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_BUS_Shield-1.0.0
Multiple libraries were found for “SPI.h”
Used: C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.11\libraries\SPI
Not used: C:\Program Files (x86)\Arduino\libraries\SPI-master
Using library MCP_CAN_lib-master in folder: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\MCP_CAN_lib-master (legacy)
Using library SPI at version 1.0 in folder: C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.11\libraries\SPI
Using library CAN_Library-master at version 1.6.0 in folder: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_Library-master
Using library SparkFun_CAN-Bus_Arduino_Library-master at version 5.1.0 in folder: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\SparkFun_CAN-Bus_Arduino_Library-master
exit status 1
invalid operands of types ‘int’ and ‘void’ to binary ‘operator==’

You can’t test the value a void function doesn’t return.

TheMemberFormerlyKnownAsAWOL:
You can't test the value a void function doesn't return.

Thank you.
Can you tell how to correct it?

Simple - don’t compare the value the function doesn’t return to a constant.

From the list of errors it appears that the sketch is expecting an entirely different CANbus library. Check the source of the sketch to see if they mention WHICH CANbus library they are using.

johnwasser:
From the list of errors it appears that the sketch is expecting an entirely different CANbus library. Check the source of the sketch to see if they mention WHICH CANbus library they are using.

Thanks.
I cleaned some library and compiled the sketch, got error: Error compiling for board Arduino/Genuino Uno.

////////////////////
Multiple libraries were found for “Canbus.h”
Used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\Canbus-master
Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\SparkFun_CAN-Bus_Arduino_Library-master
Multiple libraries were found for “mcp_can.h”
Used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_Library-master
Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_BUS_Shield-1.0.0
Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_BUS_Shield-1.0.0
Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_BUS_Shield-1.0.0
Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_BUS_Shield-1.0.0
Multiple libraries were found for “SPI.h”
Used: C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.11\libraries\SPI
Not used: C:\Program Files (x86)\Arduino\libraries\SPI-master
Using library CAN_Library-master at version 1.6.0 in folder: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\CAN_Library-master
Using library SPI at version 1.0 in folder: C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.11\libraries\SPI
Using library Canbus-master in folder: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\Canbus-master (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.
/////////////////////////

You still have multiple libraries that contain "Canbus.h", "mcp_can.h" and "SPI.h".

Start by moving these libraries out of the Arduino/libraries folder:

  • Canbus-master
  • SparkFun_CAN-Bus_Arduino_Library-master
  • CAN_Library-master
  • CAN_BUS_Shield-1.0.0
  • SPI-master

When you build your sketch you should get a "No such file or directory" error for "Canbus.h" and "mcp_can.h". For each library in turn, put it back into the "libraries" folder. If your build works, you found the right library! If not, remove that one and try the next one. You MAY need two libraries: one for Canbus.h and one for mcp_can.h. That would be strange to require two different CAnbus libraries for a single sketch.

Good luck.

Yup, this is the classic problem of multiple incompatible libraries with the same file names and it's using the wrong one.

johnwasser:
You still have multiple libraries that contain "Canbus.h", "mcp_can.h" and "SPI.h".

Start by moving these libraries out of the Arduino/libraries folder:

  • Canbus-master
  • SparkFun_CAN-Bus_Arduino_Library-master
  • CAN_Library-master
  • CAN_BUS_Shield-1.0.0
  • SPI-master

When you build your sketch you should get a "No such file or directory" error for "Canbus.h" and "mcp_can.h". For each library in turn, put it back into the "libraries" folder. If your build works, you found the right library! If not, remove that one and try the next one. You MAY need two libraries: one for Canbus.h and one for mcp_can.h. That would be strange to require two different CAnbus libraries for a single sketch.

Good luck.

Thank you john, you shown me how to fishing not just a fish.

I followed the steps tried each Lib. still got the: Error compiling for board Arduino/Genuino Uno.
maybe I didn't get the right lib. at the very beginning?

Another question confused me is: what scope does the Arduino IDE search for the libraries? inside the driver C: ?

I have read the error code, and checked there are two CANs declaration: extern CAN_MCP2515 CAN and extern MCP_CAN CAN, I just don't know how to do with that? please help.

//////////////////////////////////////////
In file included from C:\Program Files (x86)\Arduino\libraries\CAN_Library-master/CAN.h:250:0,

from C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_oct28a\sketch_oct28a.ino:16:

C:\Program Files (x86)\Arduino\libraries\CAN_Library-master/CAN_MCP2515.h:519:20: error: conflicting declaration 'CAN_MCP2515 CAN'

extern CAN_MCP2515 CAN;

^

In file included from C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_oct28a\sketch_oct28a.ino:12:0:

C:\Program Files (x86)\Arduino\libraries\CAN_Library-master/mcp_can.h:101:16: note: previous declaration as 'MCP_CAN CAN'

extern MCP_CAN CAN;

///////////////////////////////////////////

Best

The place where you got the sketch is broken. That code will never work. You can find the complete code here:
https://raw.githubusercontent.com/AppSaloon/ecu-can-bus-simulator/master/Seeedlib-ecu-sim/Seeedlib-ecu-sim.ino

It uses this one library: GitHub - Seeed-Studio/Seeed_Arduino_CAN: Seeed Arduino CAN-BUS library - MCP2518FD&MCP2515&MCP2551

johnwasser:
The place where you got the sketch is broken. That code will never work. You can find the complete code here:
https://raw.githubusercontent.com/AppSaloon/ecu-can-bus-simulator/master/Seeedlib-ecu-sim/Seeedlib-ecu-sim.ino

It uses this one library: GitHub - Seeed-Studio/Seeed_Arduino_CAN: Seeed Arduino CAN-BUS library - MCP2518FD&MCP2515&MCP2551

Thank you very much john, genius。

its good now.