CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Mon Oct 16, 2017 10:55 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Nov 01, 2016 5:44 pm 
Offline

Joined: Mon Oct 31, 2016 5:49 pm
Posts: 23
Hello,

I'm struggling to figure out a way to communicate with two serial devices in codesys v3.5 SP9 + BBB rev C.

I use both uart2(ttyO2) and uart4(ttyO4) ports. I can successfully communicate using only one uart port by appending the following line in /etc/CODESYSControl.cfg:
Code:
[SysCom]
Linux.Devicefile=/dev/ttyO
portnum := COM.SysCom.SYS_COMPORT1;

I use the example project available in the store: SerialComWithVisu with the following call to the FB Serial_Line
Code:
FirstSerialLine(
      slMode:= SL_READWRITE,
      udiPort:= 1, //tty02 ???
      udiBaudrate:= 115200,
      paParity:= COM.PARITY.NONE,
      sbStopBits:= COM.STOPBIT.ONESTOPBIT,
      udiByteSize := 8);

Everything works fine. I can write and read out of ttyO2.

Then i added the uart4 (ttyO4). I wired Tx4 -> Rx2 and Tx2 ->Rx4. I tested the communication with a python script and i was able to read and write from both serial devices.

Following the thread http://forum.codesys.com/viewtopic.php?f=21&t=5699&start=15, i left unchanged the CODESYSControl.cfg and i added a second call to the FB setting 2 as COM2
Code:
SecondSerialLine(
      slMode:= SL_READWRITE,
      udiPort:= 2,
      udiBaudrate:= 115200,
      paParity:= COM.PARITY.NONE,
      sbStopBits:= COM.STOPBIT.ONESTOPBIT,
      udiByteSize := 8);


Both ports udiPort 1 and 2 open with no errors and the write function returns successfully. The read function instead always returns empty string. Moreover if i execute
Code:
 cat /dev/ttyO2 or 4 
no output is returned as no one is actually writing in that file. I tried to change the udiPort value but ANY value i type gives the same result.
What is the right way to handle two serial devices in parallel in codesys ?? Should i edit the CODESYSControl.cfg file to declare the second port too ? if yes, how ?

Thank you.


Top
   
PostPosted: Thu Nov 03, 2016 11:54 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2157
hi,
have you tried
FirstSerialLine( slMode:= SL_READWRITE, udiPort:= 3, //ttyO2
and
FirstSerialLine( slMode:= SL_READWRITE, udiPort:= 5, //ttyO4


another one posibility is to set symbolic links for your ports... in Linux.

BR
Edwin


Top
   
PostPosted: Thu Nov 03, 2016 2:25 pm 
Offline

Joined: Mon Oct 31, 2016 5:49 pm
Posts: 23
Hi,

It works like a charm now. I used udiPort 3 and 5 as you suggested!

Leaving the CODESYSControl.cfg unchanged as i wrote it in my last post, The mapping between tty and COM in codesys is of the type: ttyOx -> COM(x+1), isn't it ? Hence, why must the udiPort be equal to 1, if i use only one uart port (e.g. ttyO2) ? What is the meaning of
Code:
portnum := COM.SysCom.SYS_COMPORT1;
in CODESYSControl.cfg when two or more ports are used ?

Sorry to bother you with all these questions but i'd like to understand better how the serial mapping works. It may be also useful to others.

Thank you.


Top
   
PostPosted: Sun Nov 06, 2016 3:31 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2157
Hi,

you could remove this line, make no sense.
portnum := COM.SysCom.SYS_COMPORT1;

only:

[SysCom]
Linux.Devicefile=/dev/ttyO

is needed.

BR
Edwin


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 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