How to obtains the CAN IDs of multiple unconfigured CANopen slaves with AsCANopen library?

Hi,
I have a IF1072 CANopen Master interface to which I’m planning to connect a few CANopen slaves. Suppose they are all brand new devices and I don’t know their CAN IDs; how do I discover them using the AsCANopen library?

Hi there,

I assume you can use CANopenGetSlaveState() to go through all possible nodes, putting those you find (where the slaveState is indicating the device exists) into an array for later handling.

Best regards

Most CanOpen slaves have a switches to define the node number.
This defines the correct CAN IDs.
Normally you import the eds file from the supplier for every can-device in Automation Studio with Tools->Manage 3rd-Party devices->Import Fieldbus Device(s).

Hi, I’m trying this solution but the function block outputs status 30841 and it does not communicate with the slave node. My X20IF1072 is connected to a X20CP3686X in the slot 1, so as pDevide I gave the pointer ADR(interface), where interface=‘SS1.IF1’.

What am I doing wrong?

Have you enabled the Canopen communication in the module’s config? (the 1072)
Also, I am not sure if my proposed solution works at all - but I assume it wouldn’t fail with device open already ^^

Yes CANopen communication is active; it’s automatically activated once I connect my slave. Even if your solutions does not work, I have tried many AsCANopen functions and they all give status 30841

Hi,

maybe it’s a dumb question, sorry about that in advance, but I’m a bit confused about the info that something is automatically activated:
" Yes CANopen communication is active; it’s automatically activated once I connect my slave"

The setting “Enable CANopen communication” inside the modules hardware configuration is set to “on”, and this hardware configuration setting was transferred to the PLC?

Because AsCanOpen operates on top of the AR integrated CANopen driver, and this driver has to be enabled in the hardware configuration setup ( in default settings, it’s disabled).

Hi,
Yes it is On; I said it is automatic because when connecting the slave in the hardware tree it asks to turn in on in order to connect them. I’ll try to explain a bit better my problem so maybe we can figure this out.

  1. I have opened a brand new project with a X20CP3686X; I have attached to the SS1 slot my X20IF1072 and then connected my CANopen slave to the CAN interface. The CANopen slave was imported via an EDS file.

  2. In the configuration of the hardware I have turned On the CANopen communication, and turned Off the CAN-I/O communication. Then I have setup the communication by setting the baudrate to 1MBit/s (which I know is the same speed set in my slave). The CAN driver driver priority is Cyclic #1 (0.4ms).

  3. I added the AsCANopen lib to my project and created a variable with type CANopenNMT. On a ST cyclic program I have set the Enable:=1, the pDevice:=ADR(interface) with interface:=“SS1.IF1”, the node:=2 (I know my slave has NodeID 2), and finally state:=3 as I want to restart It. The ST program is in Cyclic #7 (1000ms).

  4. I have transferred the code on the PLC, and once it updates and turns on, the IF1072 sets my slave from Preoperational to Operational, but the code does not work. The communication with the slave is clearly working as I can see it’s state when it changes, but it’s not restarting as commanded by the program. If I monitor the NMT function I have written, in the status field it alternates 2 code: 65535 (busy because the block it’s running) and 30841 (cannot open the device).

To my understanding the CANopen NMT message is not being sent because for some reason it cannot access the interface, but I don’t know what It’s wrong. Any clue?

with ST you have to use the single quotes and not the double quotes for strings, e.g. ‘SS1.IF1’ not “SS1.IF1”

(I know my slave has NodeID 2), and finally state:=3 as I want to restart

so you do not use an EDS ? Did you configure the slave with AsCANopen - CANopenActivateSlaveMonitoring() before ?

1 Like

Hi, I think the STRING might be the problem; I come from MATLAB and I didn’t even notice I was using the wrong data type with the double “”. I will test and update.

About the EDS, yes I’m using it. The Slave comes from a company that also provides their own software to set it up beforehand, so I chose node number 2 and baudrate 1MBit/s from their software.

double qoutes mean wide character literals. But FB parameter normally require the use of single byte characters.

Literals in IEC languages

if you’ve got an EDS then there is mostly no need to use AsCanopen - FBs despite of the ones handling SDOs.

I know that with the EDS file I can already configure the CAN communication, read PDOs and also have some info’s about the state. However, the application for which I need this slave requires me to use SDOs to change the internal configuration of the slave often (e.g. CPU restarts and a different configuration is read from an HMI and sent to the Slave), and also use NMTs to switch its state in different conditions. I guess in these case it’s unavoidable to use the library on top of the configuration already provided by automation studio

1 Like

The problem were the double quotes, it seems now communication works, thanks :slight_smile:

2 Likes