7 years, 10 months ago.

Help with Scope Resolution Operator

I want to use the MCP2515.cpp and MCP215.h files. The MCP2515.cpp file includes the following form the start:

  1. include "MCP2515.h"

MCP2515::MCP2515(SPI& spi, PinName cs) : spi(spi), cs(cs) { /* reset = 0; RESET MCP2515 CONTROLLER wait_ms(10); reset = 1; wait_ms(100);

  • / }

void MCP2515::send_1()transmits buffer 1 { cs = 0; spi.write(SEND_TX_BUF_1); cs = 1; }

void MCP2515::send_2()transmits buffer 2 { cs = 0; spi.write(SEND_TX_BUF_2); cs = 1; } ...more of the same type of "function" follow...

To a C programmer these look like functions that get called from a main program, but I'm new to C++ and don't understand how to "call" these needed operations. Can someone offer some help? So far I know the double colon represents a "scope resolution operator." I'm reading and researching but nothing so far provides a helpful example that shows and explains what to do. I just need to use these operations in an example to show students. And I don't plan to become a C++ programmer. Thank you. Jon

You will find the .cpp and .h files here if you want to look at them in more detail:

https://developer.mbed.org/users/FalconOnishi/code/MCP2515/

1 Answer

7 years, 10 months ago.

First you call the constructor, since how it is defined in this lib (a bit weird imo, but I have seen it before), this should work:

MCP2515 myMCP2515(SPI(<your_mosi_pin>, <your_miso_pin>, <your_clk_pin>), <your_cs_pin>);  //Note, not 100% sure I got the pin order correct

Now you made the MCP2515 object, and you call the functions on this object:

myMCP2515.send_0();

An alternative library which has a bit more documentation btw: https://developer.mbed.org/users/Just4pLeisure/code/SEEED_CAN/docs/tip/.

(I never used this component myself, or CAN at all, so I can't help further with that aspect).

I greatly appreciate your help. I'll check out the SEEED_CAN software. Thank you. Jon

posted by Jon Titus 09 Jun 2016