CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Feb 18, 2020 7:19 am

All times are UTC+01:00

Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Apr 05, 2019 6:14 am 

Joined: Thu Aug 16, 2018 8:20 pm
Posts: 5
Hi everyone,

Unfortunately I havent found anything regarding my question using the search function.

Here is my question:

I want to connect 4 serial devices to the 4 USB ports on Raspi. All 4 devices are exactely the same (Roboclaw motor controller).
Using udev rules I am able to give all of them reproducable names, even if I disconnect and reconnect them, so thats all fine.

To use the serial USB in codesys I know that I need to add the following lines to CODESYSControl_User.cfg:


After this I am able to control the devices vial the CAA serial library.

My question is now if there is a way to assign each Motorcontroller to a specific comport, so that I can decide which motorcontroller to "speak" without sending every command to each motor?

Thank for any help!

PostPosted: Tue Apr 09, 2019 3:01 pm 
User avatar

Joined: Tue Jun 28, 2016 2:45 pm
Posts: 65
Hi pdoubleu,

you can bound the COM-Port Number to the USB-Port, by specifying the USB-port path.
And then you can use the COM-Port numbers for a single motor, for example COM-Port number 1 for motor 1 and COM-Port number 2 for motor 2 and so on.

I've got a little instruction for this:

First let's identify the name of the interface, by using the attribute ATTRS(interface}.
So we can make sure that only a device, with the correct interface name, is "linked".

To check the attributes of a plugged-in device, use following code:
 udevadm info --name /dev/ttyUSB0 --attribute-walk

It will show you the information, from parent device to parent device. So the first info should be something like this:
 looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/ttyUSB0/tty/ttyUSB0':

So go ahead and look for the attribute "ATTRS{interface}"
This attribute gives you the name of the plugged-in USB extension.

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0':
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{interface}=="<Name of the device>"

Now you can create a udev rule, by editing your udev rule file and add:
SUBSYSTEM=="tty", KERNEL=="ttyUSB*", KERNELS=="1-1.4:1.0", ATTRS{interface}=="<Name of the device>", SYMLINK+="ttyRS0"

The Parameter KERNELS=="1-1.4:1.0" is the fixed path of the usb-port.

So this device will now always have the COM-Port number 1. If you want to add another device and you want to skip Com-Port number 2, you can use following rule:

1.) Find out the name of the interface again
2.) Check the USB-Port path.
3.) add your rule as you want :)
SUBSYSTEM=="tty", KERNEL=="ttyUSB*", KERNELS=="1-1.3:1.0", ATTRS{interface}=="<Name of the other device>", SYMLINK+="ttyRS2"

What we also did, is to create a SYMLINK. This will avoid further problems, in case of that you're using different devices, like "ttyAMA" or something else. Because as far as I know, you can specify only one Device file name in the codesyscontrol config file, so you can avoid further troubles.

In case of that, you have a totally different device, you can also use other devices.
SUBSYSTEM=="tty", KERNEL=="ttyAMA*", KERNELS=="1-1.2:1.0", ATTRS{interface}=="<Name of the ttyAMA device>", SYMLINK+="ttyRS3"

The CODESYSControl_User.cfg should look like this:


I think you don't need the last parameter "_:=...". But I'm not sure.

I hope this little instruction helps you.

Let me know if I missed something.

PS: I think this post should be moved to the raspberry pi forum category.

Building & Process Automation with HVAC Library for CODESYS© -

PostPosted: Tue Apr 09, 2019 3:51 pm 
User avatar

Joined: Tue Jun 28, 2016 2:45 pm
Posts: 65
After writing the instruction, I've checked the forum and have seen, that there is already an instruction available:

Check this link:

Building & Process Automation with HVAC Library for CODESYS© -

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited