# Initialising CAN-communication on a X20CP0292

**URL:** <https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910>\
**Category:** Controls & Vision\
**Tags:** x20\
**Created:** [April 17, 2024, 8:21pm UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910 "2024-04-17T20:21:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eisner\_k](https://avatars.discourse-cdn.com/v4/letter/e/FF8800/32.png) [@eisner\_k](https://community.br-automation.com/u/eisner_k)\
**Post date:** [April 17, 2024, 8:21pm UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910/1 "2024-04-17T20:21:40Z")

</div>

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. 🙄

Thanks in advance.

 ![4](https://europe1.discourse-cdn.com/brcommunity/original/2X/b/babf171a07086eb5d5399b1efc94c199965ac644.png)

---

<div class="post-metadata">

**Author:** ![eisner\_k](https://avatars.discourse-cdn.com/v4/letter/e/FF8800/32.png) [@eisner\_k](https://community.br-automation.com/u/eisner_k)\
**Post date:** [April 17, 2024, 8:23pm UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910/2 "2024-04-17T20:23:52Z")

</div>

But here is more!

![7](https://europe1.discourse-cdn.com/brcommunity/original/2X/5/5d31c0ca5ddf2b1ac3a23dc00dc0d4810ee20b7a.png)

---

<div class="post-metadata">

**Author:** ![eisner\_k](https://avatars.discourse-cdn.com/v4/letter/e/FF8800/32.png) [@eisner\_k](https://community.br-automation.com/u/eisner_k)\
**Post date:** [April 17, 2024, 8:24pm UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910/3 "2024-04-17T20:24:22Z")

</div>

![1](https://europe1.discourse-cdn.com/brcommunity/original/2X/a/a402d78ffbb7659d8954ed0d4f210ff74d5211ac.png)

---

<div class="post-metadata">

**Author:** ![SvenG](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/sveng/32/1835_2.png) [@SvenG](https://community.br-automation.com/u/SvenG)\
**Post date:** [April 18, 2024, 4:21am UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910/4 "2024-04-18T04:21:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexander.hefner](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/alexander.hefner/32/111_2.png) [@alexander.hefner](https://community.br-automation.com/u/alexander.hefner)\
**Post date:** [April 18, 2024, 4:57am UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910/5 "2024-04-18T04:57:02Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![eisner\_k](https://avatars.discourse-cdn.com/v4/letter/e/FF8800/32.png) [@eisner\_k](https://community.br-automation.com/u/eisner_k)\
**Post date:** [April 18, 2024, 8:30am UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910/6 "2024-04-18T08:30:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eisner\_k](https://avatars.discourse-cdn.com/v4/letter/e/FF8800/32.png) [@eisner\_k](https://community.br-automation.com/u/eisner_k)\
**Post date:** [April 21, 2024, 5:01pm UTC](https://community.br-automation.com/t/initialising-can-communication-on-a-x20cp0292/2910/7 "2024-04-21T17:01:05Z")

</div>

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.
