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