CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Mon Jul 24, 2017 7:27 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Tue May 03, 2016 7:08 am 
Offline
User avatar

Joined: Wed Mar 30, 2016 8:51 pm
Posts: 6
Hello,
I'm using the following setup:
- Raspberrry Pi 3 (Modbus RTU Master)
- Codesys Runtime (Current Version)
- Arduino UNO (Modbus RTU Slave)

The Raspberry Pi controls the logic and the Arduino uno is for the periphery. They're connected per USB. Communication over modbus rtu works between these two and I testet it with different bitrates.
Modbus RTU works after every code upload quite well.
But after every cold boot, codesys does not recognize the Arduino as Slave.
In this case, a "cold reboot" helps to fix the the problem in most cases.

Have anyone an idea where the problem is or a guess how to fix it?
Thanks :)

_________________
Ist da noch Strom drauf?


Top
   
PostPosted: Wed May 04, 2016 5:05 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 2011
Hi,
I would recommend to check:
1. If the startup is done and the communication stucks with modbus rtu, Login with CODESYS and check the device tree
- which components have a green\red sign (Modbus Master / Modbus Slave / Modbus Comport)
- Then add the name of the slave (the name in the devicetree) to the watchwindow and check the communications states, if there is an slave error you should see this
Maybe you give us a few screenshots of these states to see what happens
BR
Edwin


Top
   
PostPosted: Sat May 28, 2016 5:48 pm 
Offline

Joined: Wed May 25, 2016 8:08 am
Posts: 10
Hello marv_nene,

Would You like to post screen how you connect raspberry with arduino and how you configure it?
I want to do the same to control my home

Regards,
Marcys


Top
   
PostPosted: Tue May 31, 2016 2:38 pm 
Offline
User avatar

Joined: Wed Mar 30, 2016 8:51 pm
Posts: 6
@Edwin, thanks for your response, but I figured out a solution:
Code:
IF (xInit = FALSE) THEN
   ...
   Modbus_Slave_COM_Port.xReset := FALSE;
END_IF
...
xInit := TRUE;
...
IF Modbus_Slave_COM_Port.xError THEN
   Modbus_Slave_COM_Port.xReset := TRUE;
   Modbus_Master_COM_Port.xResetComPort := TRUE;
   Modbus_Master_COM_Port.xStop := TRUE;
ELSE
   Modbus_Slave_COM_Port.xReset := FALSE;
   Modbus_Master_COM_Port.xResetComPort := FALSE;
   Modbus_Master_COM_Port.xStop := FALSE;
END_IF


I guess, the problem is the following: When the raspberry boots, the COM port for the arduino is initialized after the start of the codesys runtime, or it seems it needs longer then expected. So, the automatic reconnection doesn't work for me. When I do it manually, it works. This code is executed every 5 seconds.

@marcys
I will respond you later.

_________________
Ist da noch Strom drauf?


Top
   
PostPosted: Wed Jun 01, 2016 6:12 pm 
Offline

Joined: Wed May 25, 2016 8:08 am
Posts: 10
Hi marv_nene,

Ok, Thank You. I will wait for response.


Top
   
PostPosted: Thu Jun 09, 2016 7:54 am 
Offline
User avatar

Joined: Wed Mar 30, 2016 8:51 pm
Posts: 6
Hello Marcys,
so, first you have to configure the USB Com Port of your connected Arduino described in thishttp://forum.codesys.com/viewtopic.php?f=21&t=6755&p=14284&hilit=modbus+rtu#p14284

For ModBus on Arduino, you can use the ModBusIno Library from stephane @[url]https://github.com/stephane/modbusino
[/url]. It works for me with
Baud : 38400
Parity: none
Data Bits: 8
Stop bits: 2

In Codesys add a Com-Port-> Modbus RTU Master-> Modbus Slave

In the Modbus Master deactivate the "auto reconnect" and use my code above.
A good idea is, to create a task for it, which circles all 30 sec.

Hope, this will help you.

_________________
Ist da noch Strom drauf?


Top
   
PostPosted: Fri Jun 10, 2016 6:20 am 
Offline

Joined: Wed May 25, 2016 8:08 am
Posts: 10
Hello marv_nene,

Would you like to post some screenshot and code example. I did what you wrote but it does not work for me:-(

Regards,
Marcys


Top
   
PostPosted: Fri Jul 15, 2016 4:52 pm 
Offline

Joined: Wed Nov 04, 2015 1:59 pm
Posts: 1
Hi,
You need to set .xResetComPort and .xStop flags for a minimun of 5 sec.

Hope, this will help you.

BR
Sandro


Top
   
PostPosted: Wed May 17, 2017 10:21 am 
Offline

Joined: Thu Feb 23, 2017 5:07 pm
Posts: 36
Hi,
I tried inserting the code in a task to check the status of the arduino connection but it does not work automatically.
When I unplug the arduino usb cable I can not see Modbus_Slave_COM_Port.xError switched from FALSE to TRUE so when connecting the cable the connection is not restored.
If I force the state of xError to TRUE and then put it back to FALSE the connection re-establishes.

Where am I wrong?

Thank you, Alberto


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


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