The thing is I don't know how to call it in my program since it is not public... I tried to edit the archive and change it from private and put it on public but doesn't work. What do I have to do to be able to use this function?
The project is about 2 arduinos trying to communicate using a CAN-Bus protocol. Here is the send code where I use the function and also the error message I get:
CODE:
// demo: CAN-BUS Shield, send data
#include <mcp_can.h>
#include <SPI.h>
/*SAMD core*/
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif
// 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;
const int ledHIGH = 1;
const int ledLOW = 0;
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!");
}
unsigned char stmp[8] = {ledHIGH, 1, 2, 3, ledLOW, 5, 6, 7};
void loop()
{ SERIAL.println("In loop");
// send data: id = 0x70, standard frame, data len = 8, stmp: data buf
CAN.sendMsgBuf(0x70, 0, 8, stmp);
delay(1000); // send data once per second
CAN.mcp2515_readRegister(28);
}
ERROR MSG:
exit status 1
'byte MCP_CAN::mcp2515_readRegister(byte)' is private within this context
The thing is that I have already developed an entire code using this library and I learned with this one... Is there no option to use private functions??
Mephirius:
The thing is that I have already developed an entire code using this library and I learned with this one... Is there no option to use private functions??
No, that's what private means. You've already been given 2 viable options:
Change the function in question to 'public'.
Add a 'public' function to the library that calls the 'private' one.
You could also specify a 'friend' function in the library.
I see... then can someone explain to me briefly how to do any of the given options? or maybe give me a link to learn how to either change a private function to public or how to call a private function by adding a public.
If you look at the library code you will see the PRIVATE and PUBLIC keywords. Either move the function you want from the PRIVATE to the PUBLIC area or make a copy of it in the PUBLIC area with a slightly different name. Or create your own function in the PUBLIC area that makes a call to the private function.
This is what I actually tried but I can't edit this file... when I copy the function from the PRIVATE into the PUBLIC part and try to save the file it appears an error message. I don't know if I am doing something wrong, any idea?
Custom libraries don't belong in that location. How did you install the library there?
If you copy the entire library to Documents\Arduino\libraries with your other custom libraries then it will give a warning about multiple copies but it should use that one first.
If you must edit a library or core file in Program Files then when you first open your editor (Notepad+ or your preference) you can right-click the program icon and choose "run as administrator".