Skip to content

Example: CiA 401 digital I/O module

This example connects one CANopen digital I/O module (device profile CiA 401) to a logiccloud runtime. At the end, one input bit of the module controls two output bits.

The screenshots show the simulated module SIM-DIO-401 at node id 5 on the virtual interface vcan0. A real CiA 401 module works the same way: only the device file, the interface name and the bit rate differ.

ItemValue in this example
DeviceA device with logiccloud Control on Linux (amd64 or arm64), installed with linux-setup.sh --network host
CAN interfacecan0 at 250 kbit/s (or vcan0 for a test without hardware)
CANopen moduleCiA 401 module at node id 5, with heartbeat producer (object 0x1017 not 0)
Device fileThe EDS file of the module. Its PDO mapping must map the 8 inputs as one byte (0x6000:01, UNSIGNED8) in TPDO 0x1A00 and the 8 outputs as one byte (0x6200:01, UNSIGNED8) in RPDO 0x1600.
RolesManage runtimes (lc_manage_runtimes)

The node id and the bit rate of the module are set with the vendor tool or with switches on the module. logiccloud does not set them (no LSS).

Follow Setting up the host for can0 with the bit rate 250000.

Check: ip -details link show can0 shows state UP and bitrate 250000.

For a test without hardware, create vcan0 as described in Virtual interface for tests.

In the project tree, open the menu of the runtime, select Add connection, CANopen, Create new, and enter:

FieldValue
Connection nameCANopen Connection 1
CAN interfacecan0 (or vcan0)
Bit rate250 kbit/s
SYNC period (µs, 0: no SYNC)0
Heartbeat factor1.5
Output cycle (ms)50
Master node id126

Select Save.

Expected result: the connection appears under the runtime with the child nodes CANopen Connection 1 Mappings and CANopen Connection 1 Object dictionary.

Select CANopen Connection 1 in the project tree. In the header of its tab, select the Import device files icon. Select Upload file, select the EDS file of the module, and select Import.

Expected result: Created: 1 (or Updated: 1 when the file was imported before), and no warning. A warning about an entry that is not byte aligned means that the file cannot be used for this example: see PDO entries that are not byte aligned.

Two ways:

  • By hand: select the Add node icon (green plus). Enter Node id 5, select the device in Device (from the imported device files), and select Add. Expected: CANopen node 5 added.
  • By scan (the runtime is deployed and the module is powered): select the Scan bus icon. Expected: a row with Node id 5 and Matched in Device description. Select the row and select Add selected.

Expected result: the connector tab shows the card 5: <device name>. Select it: the grid lists the two entries that you can map.

Connector tab with node 5 (SIM-DIO-401): entry 0x6200 Write output 8-bit 1 (output) in PDO 0x1600 and entry 0x6000 Read input 8-bit 1 (input) in PDO 0x1A00

In a global variable block of the project, declare one input and two outputs:

VAR_GLOBAL
canIn3 : BOOL {IN};
canOut0 : BOOL {OUT};
canOut3 : BOOL {OUT};
END_VAR

In my_program, assign both outputs:

canOut0 := canIn3;
canOut3 := NOT canIn3;

The program must assign each output variable. A value that you write to an {OUT} variable in the debugger is currently not applied by the runtime (LC-4342).

Build the project. Expected: the three variables appear in the inputs and outputs of the configuration. If they do not, select Refresh in the inputs and outputs view. See Variables for the mapping.

Open CANopen Connection 1 Mappings and add three rows with Add mapping:

PLC variableCANopen itemBit
canIn3node 5, 0x6000:013
canOut0node 5, 0x6200:010
canOut3node 5, 0x6200:013

The Direction follows from the entry. The Type shows BOOL, bit <n> of Unsigned8. Save with Ctrl+S (Cmd+S on macOS).

Mappings tab with canIn3 on bit 3 of 0x6000 (input), canOut0 on bit 0 and canOut3 on bit 3 of 0x6200 (output)

  1. Build the project and deploy the runtime to the device.
  2. Open the log of the canopen-connector process on the device. Expected: NMT Start sent for node 5, with the vendor ID, product code and revision of the module.
  3. Switch input 3 of the module on and off. Expected: output 0 follows the input, and output 3 shows the opposite value.
  4. For more detail, set the log level of the connector to Debug. It then logs once per second the values that it reads (CANopen input PDO values) and writes (CANopen output PDO value). Set the level back to Info when you are done.

Optional check with the SDO probe: open CANopen Connection 1 Object dictionary, select node 5, and select Read in the row 0x1008 (device name) or 0x6000:01 (inputs). Last result shows the value. See Object dictionary and SDO probe.

If the node is not started or a value does not change, see Troubleshooting.