Initialising CAN-communication on a X20CP0292

Good Evening,

due to some new machines my company bought with b&r plc in it, I’m making myself familiar with AS. Most of our other stuff is Siemens.
For testing purposes I have a X20CP0292 with corresponding base module and some I/O.
I got the basics straight, i.e. getting the cpu up and running, creating some functions etc.
Now I want to initialise the CAN communication but I fail.
I use the canopen() function from can_lib, put it in INIT, feed it with the variables and get error 8817 meaning no can controller or wrong device string in canopen().

My CAN device is integratet in the cpu and listet as IF3. So my string is “SL0.IF3” or just “IF3”. Both don’t work.
I am also not sure if I did the references for canopen() right. My canopen() is declared in INIT, my references in cyclic. Sounds wrong to me, for INIT should be processed first and the references shouldn’t have any value yet. But if I put the references in INIT together with canopen(), AS aborts the upload, telling me it lost connection to the cpu.

Does anyone have a suggestion?
I wanted to upload some pictures of hardware and code, but I’m just allowed to post one media. :roll_eyes:

Thanks in advance.

But here is more!

7

Hello,

i use also CAN communication,
the port i use is named “IF3”

my settings are ( as an example )

C_open.enable:=1;
C_open.baud_rate:=25;
C_open.cob_anz:=15;
C_open.error_adr:=ADR(error);
C_open.device:=ADR(poort); (ADR(poort) ADR(dev);)
C_open.info:=0;
C_open();

to read

C_read(enable:=1, us_ident:=C_open.us_ident, can_id:=601, data_adr:=ADR(screenCommonValues));

hope this will help you a bit on the road

make sure that the baudrate of both devices are the same, and the ID is different for both devices

wr
Sven
Sven

1 Like

Hi,

like Sven showed in his sample, I think the cause are the missing ADR() statements.
Assuming that your variables “source” is a STRING and “sourceErr” is a USINT, you have to use
error_adr := ADR(sourceErr), device := ADR(source)
because this both inputs have to be given as a pointer to the function block.

Also make sure that “source” has already the suitable value when the CACopen FB instance is called (for example by setting the value with source := ‘IF3’; before calling the function block).
You also could use a static string instead of a variable by setting device := ADR(‘IF3’) in the function block call.

Hope that helps, best regards!

Thanks for the Input.
I think I see my mistake.

I’m at a training course the next days, but when I get back to my controller, I’ll give news.

1 Like

I made it work.

My initial assumption was correct. I messed up the declaration of the reference variables.
I looked up the commands in the AS-help and used the command ACCESS ADR() and tried to make it work.
In my case with the variable
“CANdevice” defined as String “IF3”
I wrote:
source ACCESS ADR(CANdevice);
and put that in the CYCLIC part of the program, because it crashed the download when I put it in the INIT part.
My call:
CAN.device:=source;
simply did nothing.

ADR() did the trick.

Thank you.