CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sun Jun 25, 2017 6:10 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 81 posts ]  Go to page 1 2 3 4 5 6 Next
Author Message
PostPosted: Wed Apr 02, 2014 7:34 pm 
Offline

Joined: Tue Apr 01, 2014 10:52 pm
Posts: 5
The Raspberry Pi has many interfaces and the 3S Target support many of them.
But how connect simple serial devices ?

On the pole pin connector of the raspberry pi there are these serial signals.
With the additional RasPiComm board these signals are available on a DSUB9 RS232 interface connector.
Do the 3S Target support this now or in the future ?

Is it possible to use the 2 USB Ports with "PL2303HX USB to TTL UART RS232 COM Kabel-Modul Converter" to connect simple serial devices ?


Top
   
PostPosted: Fri Apr 04, 2014 12:02 pm 
Offline
Site Admin

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

this works already but you need to add your configuration:

1. you need to check on linux side which tty port is available.

For my tests I've used a USB to serial converter:
Check under Linux with 'dmesg' which port is used:

in my case it reports: ttyUSB0

so you need to add in /etc/CODESYSControl.cfg
(Attention you need to remove the 0 from USB0)

[SysCom]
Linux.Devicefile=/dev/ttyUSB


this was the pi side under Linux

2. then after reboot or restart plc, you could communicate via serial com from your IEC application see attached screenshot and attached projectarchive (this is an
application example from store slightly modified)


BR
Edwin


You do not have the required permissions to view the files attached to this post.


Last edited by Edwin Schwellinger on Tue Apr 18, 2017 5:58 am, edited 1 time in total.

Top
   
PostPosted: Mon Apr 14, 2014 9:56 pm 
Offline

Joined: Tue Apr 01, 2014 10:52 pm
Posts: 5
Thank you Edwin !

I use a PL2303 usb-serial-adapter together with your example project and the standard configuration is working well.

But if I change the Baud rate to 300 Bd (exactly 1200 Bd or slower) the comOpen method throws an UNKNOWN_ERROR.
I need the 300 Baud to communicate with an IEC61107 electronic meter.

Do you have a solution ?
At the moment I don't know if it is a problem of the usb-serial-adapter, the RPI or in the CODESYS function block ?

Thank you for your support.

BR Martin


Top
   
PostPosted: Tue Apr 15, 2014 5:21 am 
Offline
Site Admin

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

could you please check if These baudrates are possible with plain Linux use?

configure
stty -F /dev/ttyUSB0 1200
stty -F /dev/ttyUSB0 raw

now read from the port by:
cat /dev/ttyUSB0

sending:

echo Hello Raspberry > /dev/ttyUSB0

or use a terminal on Linux:

sudo apt-get install minicom

minicom -b 1200 -D /dev/ttyUSB0

Let me know the results of this tests,
if this works on your Pi, this should be a problem in the libraries.

BR
Edwin


Top
   
PostPosted: Wed Apr 16, 2014 10:15 pm 
Offline

Joined: Tue Apr 01, 2014 10:52 pm
Posts: 5
Hello Edwin,

I tried your recommendations, but there was no responds on cat /dev/ttyUSB0 (see attachments).
Does this work on your raspberry ?

The identical CODESYS program ist running on a WinV3 soft plc with 300 Baud.
Therefore I think the USB-Serial-Adapter isn't the problem.

Do you have any further ideas (after easter hollidays) ?

Best Regards Martin


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Thu Apr 17, 2014 7:26 am 
Offline
Site Admin

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

in my case it works under Linux see screenshot,
anyway it seems there is a problem in CODESYS.
We need to investigate this.

BR Edwin


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Thu Apr 17, 2014 8:09 am 
Offline
Site Admin

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

i've added an JIRA for this at the moment baudrate below 4800 are not possible.
Could you change the reciving device to an hight baudrate as a workaround?

BR
Edwin


Top
   
PostPosted: Thu Apr 17, 2014 5:05 pm 
Offline

Joined: Tue Apr 01, 2014 10:52 pm
Posts: 5
Yet I can also reproduce this.
I agree Raspberry Serial communication on 300 Baud is possible, but CODESYS below 4800 Baud not (on a raspberry only).

I can't change the baud rate of the corresponding device, because it's an electonic meter from EON Westfalen Weser :-) .
IEC61107 electronic meter get requests with 300 Baud and answer with 9600 Baud.
This challange is handled by my codesys program and is running successfully on a WinV3 soft plc but I wan't do it on a raspberry ...

Thank you for your Support and maybe for the bugfix in the future.

BR Martin


Top
   
PostPosted: Wed Apr 23, 2014 3:51 pm 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 69
Hi,

I tested USB/RS-485 adapter. I set up Raspberry just like Edwin described. It works perfectly from the start. I tested modbus RTU communication with room thermostat.

There is only one thing which I don't like. If I break connection on RS-485 side (I leave USB adapter connected in Rpi), bus goes to Failure status:
Image

But even if I connect RS-485 line again, bus don't recover. Only Rpi reboot helps.
Is there a way to auto recover the bus after failure?

Thank you.
Best regards,
Zdenko.


Top
   
PostPosted: Thu Apr 24, 2014 7:17 am 
Offline
Site Admin

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

check if:

Device.Application.Modbus_Master_COM_Port.xResetComPort
Device.Application.Slave3.xReset

does solve the restart problem.

BR
Edwin


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Thu Apr 24, 2014 8:20 am 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 69
Thank you Edwin,

yes, Device.Application.Slave3.xReset does helps. Modbus communication works ok after reset. How can we make this works automatically?

I think, Modbus RTU should work also in this case:
-PLC as a Modbus master
-10x modbus slave devices on the same RS-485 bus.
-If one of this 10 slave devices won't respond, the communication with other devices should work normally.
-Also if some slave device will not reply to one specific request from master, master should repeat this request (number of retries).

Regarding this, is there a usable solution to make this work properly?

Best regards,
Zdenko.


Top
   
PostPosted: Thu Apr 24, 2014 8:27 am 
Offline
Site Admin

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

this is a open point which will be fixed to 3.5SP5 (release July 2014).

At the moment you need to do this manually in the application.
How?
The Workaround is, always to check modbus error in modbus master function block and if error happens, restart the communication
BR
Edwin


Top
   
PostPosted: Thu Apr 24, 2014 1:48 pm 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 69
Hi Edwin,

thank you.

I am trying this declaration:
IF Device.Application.Modbus_Slave_COM_Port.xError THEN
Device.Application.Modbus_Slave_COM_Port.xReset := TRUE;
END_IF

But I think I am not doing this right. I get this exception:
[ERROR] MB485_230414: PLC_PRG [Device: Plc Logic: Application](Line 10, Column 1 (Impl)): C0062: 'Device.Application.Modbus_Slave_COM_Port' is no structured variable

I also tried with FBD, but I also don't find Modbus master FB. Can you point me in the right direction, please.

I understand that you will integrate the additional Modbus RTU master functionality in version V3.5. So this means, that this problem is in all controllers which uses Codesys for programming?

Best regards,
Zdenko.


Top
   
PostPosted: Thu Apr 24, 2014 2:24 pm 
Offline
Site Admin

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

IF Modbus_Slave_COM_Port.xError THEN
Modbus_Slave_COM_Port.xReset := TRUE;
END_IF

BR
Edwin


Top
   
PostPosted: Thu Apr 24, 2014 4:14 pm 
Offline

Joined: Fri Apr 18, 2014 5:36 pm
Posts: 69
Hi,

thank you. This works.

Is there a way to read and write the same Modbus holding register to the same Raspberry variable? This have to used if we like to change some modbus slave setpoint on the both devices (master and slave).

Best regards,
Zdenko.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 81 posts ]  Go to page 1 2 3 4 5 6 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Limited