Help with CANopen Communication using X20IF1041-1

Hi Christoph
Thanks for your reply. I started to begin from scratch. I am using ST format. I created a variable “RECEIVE” which has type = ArCanReceive. Then i wrote these below code:

                        RECEIVE.Enable :=  TRUE; 
			RECEIVE.DeviceName := 'IF3.ST3.SS1.IF1'; 
			RECEIVE.ID:= 16#181;
			RECEIVE.IDMask:= 1;
			RECEIVE.QueueSize := 100;
			RECEIVE();

When i build and transfer it, everything is fine. But under Monitor mode, i get StatusID = -1070584148 which corresponds to “arCAN_ERR_DEVICE_NAME–> -1070584148–> Check the device name.”

The device has PLC address = " IF3.ST3.SS1.IF1". What is actually wrong here with device name? I also tried usinf “SS1.IF1”. But no luck. Do you have any idea?


Thanks

Drakku

Can you please post a picture of your hardware tree, at least up to the CS2770? That format looks correct but it’s hard to debug without knowing what your hardware tree actually is.

Also, does your hardware tree in Automation Studio match what you physically are working with? Are there any hardware errors in the System Diagnostics Manager?

Hi Marcus
I am not using CS2770 as my can interface. Slave module X20IF1043 also has CAN interface and want to read from it the values.

Ah I see. I think that’s probably the issue then.

In your original post, you mentioned an X20CS2770. This module has two CAN bus interfaces. Your hardware tree instead shows an X20IF1041-1 (CANopen Master) and an X20IF1043-1 (CANopen Slave).

While CAN and CANopen share the same physical layer, they are two different communication protocols. In order to send/receive CAN messages, you would use the ArCan library. This library sends and receives CAN frames using a CAN interface. CAN itself is a relatively simple protocol in that any device can send messages to any other device and so you just pack up your data and send it out.

CANopen is a protocol that uses the CAN bus as the base layer but adds on some additional features, such as a device hierarchy. There is a Master device which is responsible for getting the needed data from the Slave devices. If you want to communicate using CANopen, the other devices on the network must also be CANopen devices (not simple CAN devices). You have two options to set up this communication:

  • Import the slave devices’ EDS files into Automation Studio. This is the easiest way and I recommend it if your other devices provide EDS files
  • Use the AsCANopen library

Per Christoph’s post, you could get CANopen working via a CAN device (the X20CS2770) since CANopen works as an application layer on top of CAN. However as far as I know you can’t go backwards (meaning use a CANopen interface for simple CAN communication)

1 Like

Hi Marcus
Yes the first post was was with CS2770 . But then i realized that its not CANopen compatible. I dont have the EDS file for the Slave device. What is then the solution?

But i did something similar to what you suggested:

  1. added some codes so that X20IF1043-1 (CANopen Slave) has some constant values saved in it.
  2. i added the EDS file for X20IF1043-1 (CANopen Slave) to X20IF1041-1 (CANopen Master) ( like in the picture in the post nr7)
  3. Using arCAN i tried to read the received frame ( like in post nr6) and using AsCANOpen lib i tried to do PDORead8. Both of them returned error codes.

Hi Drakku,

If you want to configure CANopen communication using the X20IF1043-1 (CANopen Master interface module) then you have two options:

  1. Import a slave device’s EDS file into Automation Studio and add it to the hardware tree. You do not need any extra code in this case. As long as everything has been configured correctly, the slave’s data will show in the I/O mapping for the interface module when the communication is started.
  2. Use the AsCANopen library to communicate the data. The ArCan functions (i.e. ArCanReceive) should not be used in this case because those functions are for CAN, not CANopen. If you plan to use AsCANopen I suggest starting from the examples provided as you have to do some additional work before can read data. If you run into errors or problems that you need help with, please post detailed error information.

In your last screenshot, it looks like you’re trying to get the X20IF1043-1 to communicate with the X20IF1041-1 and you’ve done so by importing the slave device’s EDS file. This is possible but keep in mind that the slave device’s data is configurable and so the master device must know how the slave has been configured. The I/O mapping on the Master must match the I/O being communicated by the Slave in order for communication to work. See this Help page for more information.

1 Like

Hi Marcus

Thanks for the reply. Yes now am trying to get X20IF1043-1 to communicate with X20IF1041-1. With imported EDS file of X20IF1041 from B&R, i am able to see values in the I/O mapping. But its cyclic and continous.
But what i need to parse values depending on COBID and save it to specific variable. So i used AsCANOpen lib with using the lib examples. See attached image. i tired to register the COBID ( Case3 ) and then ReadPDO (Case2).When using this approach i was getting the error: 30841 which corresponds to “the selected device could not be opened”. I also tried using ADR('IF3.ST3.SS1.IF1.ST1" also as device name. But same error appears.

The funny things which i noticed is: if you look in the watch window “pdevice” on both cases, they have both different values. How is this possible even though i give the same pdevice ADR() on both cases?

Hi @mathew086 Drakku,

even at the risk of confusing you:

the IF cards based on Hilscher NETX chips need other Libraries:

AsNxCoM

B&R Online Help

and AsNxCoS

B&R Online Help

AsCANopen

AsCan

is for the built-in CANopen Master which is available for the standard IF CAN interfaces (e.g. X20IF1072)

2 Likes

Hi Christoph
That makes sense now why AsCANOpen lib is not wrking at all. So you say that for X20IF1041, i need to use AsNxCoM lib? i quickly checked it. It has but only READ/WRITE SDO functions. how do i read then PDOs? :thinking:

Just wanted to make sure this question got answered as well:

The funny things which i noticed is: if you look in the watch window “pdevice” on both cases, they have both different values. How is this possible even though i give the same pdevice ADR() on both cases?

This is because the pDevice input is an address of (pointer to) a value. In your code, you used a literal string rather than a variable name to define the value. Had you created a variable and then put the device name string inside of that variable, the pointer to the variable would have the same address every time. However, you essentially created two different variables by writing out the string ‘IF3.ST3…’ twice.

This will have no impact on the result of the code however. In both cases, the function blocks are getting the correct values (assuming no weird memory issues). Christoph’s answer sounds like what you need.

1 Like

I do not see any FB for that. But well, you can read any readable register with nxcomSdoRead() even those which are mapped to an PDO…
And all PDOs are connected in the IO Mapping.

1 Like

Hi Christoph

I tried to read the PDO 16#181 with AsNxCoM library . But i get the following error messages. Status = 34505 (ncomERR_PARAMETER) & 65535 ( ERR_FUB_BUSY)

Seems like the FB is not at all being called/executed correctly.and i dont knw what is wrong in my code.

When i read SDO Object 1018, i get the same errors as above. On a CAN Sniffer i am able to see values for both PDO and SDO.

Hi Drakku,

16#181 is not a valid CANopen object (instead it can be a CAN- Object which can carry a PDO).

Perhaps there is a misunderstanding about what CANopen is and how it works. Hence the question: what is the intention?

PDOs are configured when the CANopen device starts up. They can be used to determine which registers (‘objects’) are read (and written) cyclically. This does not require a special command from the master (despite a SYNC message). With B&R, the PDOs are then located in the IO mapping of the slave.

SDOs, on the other hand, are only read (and written) cyclically at the request of the master. And this requires these function blocks.

My problem is: I have a device( lets say SlaveX) which does not have an EDS file. So am not able to add this SlaveX to the Master CanOpen (DTM) in B&R. So i was thinking i could write a program code using lib functions which could use Master X20IF1041 CANOpen interface to read PDOs & SDOs from this SlaveX [ by defining Node ID, PDOs( 181h, 281h, etc) and SDOs object) and write these filtered values into variables. SLaveX has CANOpen protocol implemented on it but does not have any infos like VendorID, Name, etc. which is useful.

From the variables , i will send the values to B&R Slave X20IF1043.

Hope i am clear with what i want. I have these HWs : Master X20IF1041, Slave X20IF1043, X20EM1611,X20PS9400,X20CS2770,X20BC1083.

What i tried was: Used CS2770 with ArCAN, AsCAN libto read from SlaveX and mapp to Master X20IF1041 but didnt work.

I have a device( lets say SlaveX) which does not have an EDS file

oh, that make it somewhat clearer

I am surprised that these devices still exist today. In most cases, the CANopen stack has then only been implemented in a rudimentary way.

In most cases, such devices can then be controlled with a simple CAN interface under CAN_lib or ArCAN. The manufacturer then describes the exact procedure for configuration.
You then have to deal with how to configure this device correctly during start-up (preoperational) so that it sends the PDOs with the correct data, or you can read everything acyclically via SDO if you don’t need deterministic data.

My approach would be to use a standard CAN interface and implement a rudimentary CANopen master with it or use a ready-made CANopen master and then write the EDS yourself. Ultimately, this is just a normal text file.

However, you need to know the device and the structure of an EDS file well (there are also tools for the latter).

It is also possible that AsCanopen (with a standard CAN) works.
But you already tried this (?):

How to read values from a Device which has CANOpen - Ask Questions - B&R Community

Blockquote
My approach would be to use a standard CAN interface and implement a rudimentary CANopen master with it or use a ready-made CANopen master and then write the EDS yourself. Ultimately, this is just a normal text file.
Blockquote

I had actually tried creating an EDS file for the slave. It was of no use. Only 1 PDO was able to be read. and moreover the manufacturer does not provide much details of the device. I have only a “dbc” and “dbf” file and i was not able to make an EDS file from these.
You mentioned " use a standard CAN interface and implement a rudimentary CANopen master with it" . I tried this way with CS2770 CAN interface and X20IF1041 Master. But it didnt work. Seems that the CS2770 is not compatible with X20IF1041.

So like @marcusbnr mentioned in one of his posts (How to read CANOpen , i might need new HWs * X20IF1072 & * X20CS1070 to communicate with my SlaveX which has CANOpen on it. X20IF1041/1043 and CS2770 wont work. Is that correct `?

I know ‘dbc’ files for J1939 CAN only. Are you sure your SlaveX is really a CANopen device ?

X20IF1041/1043 and CS2770 wont work. Is that correct

Yes. You would need X20IF1072 (not a ‘CS’) for the built-in CANopen Master.

But CS2770 can be used as you own handmade CANopen- Master (with ArCAN). But well, this can be a bit tedious.

Hi @christoph.hilchenbac & @marcusbnr

Thank you so much for your support. I will order 1x X20IF1072. ( Since i have X20CS2770 which a 2x CAN inteface am not planning to buy X20CS1070 again)
I still have one more ques before ordering X20IF1072. So basically this X20IF1072is a CAN Bus interface module which can be configured to be a CANOpen Master. With this new X20IF1072, how is the connection goin to be? its a bit confusing. Should i then connect my SLaveX to one of the CAN inteface of X20CS2770 and then connect it to X20IF1072 pins and then use ArCAN Lib functions to read from X20IF1072 interface? Is that correct?
Why can’t i directly connect my SlaveX to X20IF1072 pins and use ArCAN lib functions to read specific IDs?

Thanks

Hi Drakku,

Why can’t i directly connect my SlaveX to X20IF1072 pins and use ArCAN lib functions to read specific IDs?

of course you can. And if we talk about ArCan (and not a CANopen master) then also X20CS1070, X20CS2770 will be ok for a (handmade) Master functionality.

The X20IF1070 (and X20IF2770) additionally has the option of CANopen master functionality. However, the question is whether this is really useful and necessary for you, as you do not have an EDS file for the ‘SlaveX’.

Many CANopen slave devices can be brought to life by a few CAN IDs using standard CAN interfaces. However, some knowledge of the CANopen protocol is necessary.

There is a very good post from Abid:

How-to & Trace description guide: CanOpen - Share Info & Ideas - B&R Community

and Stephan provided a library for CANopen functionality with standard CAN interfaces:

[Searching] CANopen wrapper library for CAN interface - Ask Questions - B&R Community

but if you had an EDS, everything could be solved without much effort with a ‘real’ CANopen master without much programming.

However, your ‘SlaveX’ will not come to life simply by writing CAN IDs. The manufacturer will have implemented a state machine in it according to the CANopen protocol, which you will have to replicate.