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 Fri Dec 06, 2019 1:52 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 10 posts ] 
Author Message
 Post subject: UPS with Codesys
PostPosted: Mon Oct 28, 2019 11:29 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 43
I have a Pi based device with a UPS. The relay output from the UPS is wired to GPIO0. I created a Python script to save persistent data when the UPS loses power and the GPIO0 signal changes. This is the code I am using:
Code:
      if GPIO.input(0):
        subprocess.run("sudo bash /etc/init.d/codesyscontrol stop", shell=True, check=True)
      else:
        subprocess.run("sudo bash /etc/init.d/codesyscontrol start", shell=True, check=True)

It does not seem very graceful to fully stop the Codesys service and restart when power is restored. Is there a better method to tell Codesys to save the persistent values?


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Tue Oct 29, 2019 6:56 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3559
Hi,
if you do this manually do you agree that this works?
I think if you trigger this by a GPIO and your UPS triggers a Linux shutdown - and as you told switch off Ethernet nic
at the same time.. this will not work properly. ( As I remember from an older post)
Is using a different UPS an option PI for you? For example: viewtopic.php?f=23&t=5872&p=10867#p13721

BR
Edwin


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Tue Oct 29, 2019 7:26 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 43
This is a different device with an external UPS. I was never able to get the first device with the built-in UPS to work because of the power being removed from the Ethernet ports

On the new device I cannot shut down Linux because the power may return before the UPS is completely drained. If Linux were shut down and the input power returned to the UPS, then Linux would not restart. So I need some way to force Codesys to save the data.


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Wed Oct 30, 2019 9:44 am 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 43
To be more specific, this is the UPS I am using:

https://www.bicker.de/index.php/eng/Pro ... PSIC-2403D

I have the relay output wired to GPIO0 of the Pi device.


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Wed Oct 30, 2019 2:06 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3559
Hi,
I would try:

if GPIO.input(0):
subprocess.run("sudo shutdown -h now", shell=True, check=True)
.
.
This is a graceful shudown of Linux which will lead to a graceful shutdown of the plc runtime -
I assume this will then lead to a valid retain file too.

BR
Edwin


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Wed Oct 30, 2019 9:02 pm 
Offline

Joined: Tue Mar 26, 2019 4:28 pm
Posts: 48
Archie, are you going about this the wrong way?
Have you tried the persistence manager which specifically implements what you are after?
https://help.codesys.com/webapp/f_appli ... n=3.5.14.0

Recipes is also an option, but Persistence Manager just has everything you could want. Redundant files.. write on change or write on demand.
Ian


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Thu Oct 31, 2019 11:50 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 43
Edwin Schwellinger wrote:
Hi,
I would try:

if GPIO.input(0):
subprocess.run("sudo shutdown -h now", shell=True, check=True)
.
.
This is a graceful shudown of Linux which will lead to a graceful shutdown of the plc runtime -
I assume this will then lead to a valid retain file too.
The reason I cannot do this is because the power may return before the UPS is fully drained. In this case the Pi would not boot back up. It would require someone to manually disconnect the power from the Pi or remove power into the UPS for about 60 seconds to let it fully drain.


Last edited by arj3090 on Fri Nov 01, 2019 12:44 am, edited 1 time in total.

Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Fri Nov 01, 2019 12:44 am 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 43
I-Campbell wrote:
Archie, are you going about this the wrong way?
Have you tried the persistence manager which specifically implements what you are after?
https://help.codesys.com/webapp/f_appli ... n=3.5.14.0

Recipes is also an option, but Persistence Manager just has everything you could want. Redundant files.. write on change or write on demand.
Ian
I briefly checked the Persistent Manager, but haven't got it to work yet. I am missing a step or two somewhere. I do like the Save On Change feature. It would be really nice if the normal Persistent Variables had the feature.


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Sat Nov 02, 2019 11:14 am 
Offline

Joined: Tue Mar 26, 2019 4:28 pm
Posts: 48
I couldn't find a nice tutorial for Persistence Manager, just the online help which details the components of Persistence Manager. They go through this in the training courses.

I am not infront of a CODESYS IDE at the moment, but I remember key steps being installing Application Composer for free from the store, showing the Modules View, and pressing the generate button.

It is kind of designed for exactly what you want.

I see you have already found the application manager store example which has the functions to store the var persistent retain data to a file and restore it... I haven't needed to try to get these to work though as Persistence Manager does it all for me. (Perhaps turn off the default "OnPowerfail" storage recovery with these two lines in your .cfg)
[CmpApp]
RetainType.Applications=None


Top
   
 Post subject: Re: UPS with Codesys
PostPosted: Fri Nov 08, 2019 9:35 am 
Offline

Joined: Thu Aug 17, 2017 12:35 pm
Posts: 35
There always are a problem using UPS and raspberry as raspberry doesnt have a BIOS with auto start option..
The Raspberry needs to shutdown and have 0V input a short time before power applied..
There are UPSes that work this way see attached picture for Andino-UPS different states.. If you had a "real" industrial computer the normal working UPSes would work.

Pictures taken from here: https://github.com/andino-systems/Andin ... master/src


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  [ 10 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 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:  
Powered by phpBB® Forum Software © phpBB Limited