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 Sat Sep 21, 2019 7:03 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 20 posts ]  Go to page 1 2 Next
Author Message
PostPosted: Fri Sep 06, 2019 10:55 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
I am trying to use Codesys on a BB-400 by Brainboxes and having trouble with Python services not running after installing the Codesys runtime. There are a series of python scripts that manage system services. One of which is shutting down the os when the UPS signals to.

Looking at the log files and also running the scripts in ssh, I can see they run fine normally. As soon as I install the Codesys run-time, these python files no longer run or just hang. I tried using pdb to debug the python but it will also freeze up when I step through the code.

I know this is related to the Codesys run time because I can remove the package and the Python scripts go back to working normal.

Anyone have any hints of how I can troubleshoot this?


Top
   
PostPosted: Sat Sep 07, 2019 6:51 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3451
Hi,
which CODESYS runtime and which RASBIAN (?) version is up and running on this system?

BR
Edwin


Top
   
PostPosted: Sat Sep 07, 2019 11:41 am 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
I tried versions 3.5.14.30 and 3.5.15.0

I will check the Raspbian version when I get to the office.

The device is currently running :
Linux 4.19.57-v7+


Last edited by arj3090 on Sat Sep 07, 2019 3:49 pm, edited 1 time in total.

Top
   
PostPosted: Sat Sep 07, 2019 2:09 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3451
Hi,
I have send out a release candidate of the 3.5.15.10 runtime,
almost sure that this will solve it.
Feedback well appreciated.

BR
Edwin


Top
   
PostPosted: Sat Sep 07, 2019 3:50 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
I will test the new version right now and report back the results.


Top
   
PostPosted: Sat Sep 07, 2019 5:04 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
So far that version seems to have fixed the issue. The python scripts are now running.

The problem is now related to the BB-400 which I need to work with Brainboxes to resolve. I can call system shutdown on a UPS warning in the Python code and CodeSys will save persistent data value. But if I call shutdown on the UPS shutdown signal, Codesys does not save values. I am going to work on the Python and BB-400 side now.

Thank you very much for the fast assistance and solution.


Top
   
PostPosted: Sat Sep 07, 2019 10:58 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
I have found a way to make the BB-400 work well with Codesys, but it is kind of a hack because something doesn't work as expected.

The BB-400 has 3 power states with 2 events that fire Python code.

1) Running (normal power applied) - fires ups_power_change event
2) UPS Alert (external power loss) - fires ups_power_change event
3) UPS Shutdown - fires shutdown_signal event

First Issue
When the state goes to UPS Alert, the device also removes power from peripherals such as the Ethernet ports. I found this causes Codesys to stop the EtherCAT communcations in which it does not recover if returning to Running before going into UPS Shutdown.

Second Issue
Although the shutdown_signal event fires and the "shutdown now" is executed, Codesys still does not save persistent values. However if anything is done, such as shutdown, in the UPS Alert state, Codesys will save persistent values.

My solution that resolves both issues is to stop Codesys when the BB-400 enter UPS Alert state and start Codesys when it goes into Running state.

This is the modified Python code found in /usr/share/brainboxes/bb-core/bb_core_power.py
Code:
    def ups_power_change(self):
        logging.warning("bb_core_power : ups_power_change")
        isUPS = True if self.UPS_ALERT.value == 0 else False
        if isUPS:
            self.set_power_state(PowerStates.RUNNING)
        else:
            self.set_power_state(PowerStates.UPS_ALERT)

        self.power_changed_event(self.get_power_state())
        self.fire_event()

        # These must be done after firing the events because the events restart the peripherals
        if isUPS:
            # Try to start Codesys in case a UPS Alert stopped it
            subprocess.run("sudo bash /etc/init.d/codesyscontrol start", shell=True)
        else:
            # Stop the Codesys in order to force it to save persistent value
            # It is also necessary because Codesys does not recover from Ethernet
            # being powered off during UPS Alert
            subprocess.run("sudo bash /etc/init.d/codesyscontrol stop", shell=True)


The proper solution is to figure why no values are saved during a shutdown in the shutdown_signal event. I know the event executes and the OS saves data because there is logging to a file that is updated in the event.

Any possible ideas of why a shutdown will save data in a ups_power_change event, but not in the shutdown_signal event?

Another thought I had was to use the GPIO signal in Codesys that comes from the Power Management Unit telling the OS to shutdown. Is there a way in Codesys to look at that signal and tell it to save its persistent data values?


Top
   
PostPosted: Sun Sep 08, 2019 1:24 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3451
Hi,
this works if Linux does a gracefull shutdown, means the codesys runtime will be stopped/exit by the shutdown of the Linux System.

what do this python exactly in this state.... shutdown the whole system? Then it must work.


BR
Edwin


Top
   
PostPosted: Sun Sep 08, 2019 11:52 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
This is the code that executes when the UPS sends the signal to shutdown:
Code:
    def shutdown_signal(self):
        logging.warning("bb_core_power : entered shutdown_signal")
#        subprocess.run('sudo killall codesyscontrol.bin', shell=True)
        subprocess.run("sudo bash /etc/init.d/codesyscontrol stop", shell=True)
        logging.warning("bb_core_power : after codesys kill")
        self.set_power_state(PowerStates.STOPPING)
        self.power_changed_event(self.get_power_state())
        self.fire_event()
        self.CMHalting.close()
        subprocess.run('sudo wall "Power failure, BB-400 will shut down"', shell=True, check=True)
        logging.warning("bb_core_power : About to  Shut Down")
        subprocess.run('sudo shutdown now', shell=True)
        logging.warning("bb_core_power : After Shut Down")


You can see where I attempted to stop Codesys prior to the Shutdown Now. I definitely know the code is executing because I can check the log file and see in the log file. I also know the commands I am using to stop Codesys will save data because I tested them in the UPS Alert event.

Considering the UPS Alert state powers down all peripherals, my next theory is that Codesys abruptly stops prior to the Shutdown_signal event, therefore not allowing a graceful shut down of Codesys. I am going to test this by listing the active processes to the log file so I can see if the Codesys process is still running when it reaches the Shutdown_Signal event.

I will do some further testing and report back.


Top
   
PostPosted: Mon Sep 09, 2019 4:38 am 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
I have confirmed the CodesysControl process abnormally stops prior to the Shutdown_Signal event, not allowing persistent data to be saved on the OS shutdown. To conclude this, I inserted a command into the Shutdown_Signal event to list all processes that contain "co". This was the result

37 ? 00:00:00 kcompactd0
69 ? 00:00:00 mmc_complete
74 ? 00:00:00 ext4-rsv-conver
75 ? 00:00:00 ipv6_addrconf

So CodesysControl is no longer running when entering the Shutdown_Signal event. Is there a log or crash report that may give a clue as to why the Codesys process exits abruptly after the UPS goes into Alert state?


Top
   
PostPosted: Mon Sep 09, 2019 8:41 am 
Offline
Site Admin

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

cat /tmp/codesyscontrol.log

or even better:
tail -f /tmp/codesyscontrol.log


BR
Edwin


Top
   
PostPosted: Mon Sep 09, 2019 6:16 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
These are my latest results after further testing:

In the UPS Alert event:
Code:
Process List of co* : In UPS Alert Event
   37 ?        00:00:00 kcompactd0
   69 ?        00:00:00 mmc_complete
   73 ?        00:00:00 ext4-rsv-conver
   75 ?        00:00:00 ipv6_addrconf
  607 ?        00:00:01 codesyscontrol.
  714 ?        00:00:13 codesyscontrol.
 1080 ?        00:00:00 COEX-TX-Thread
 

Code:
Codesys Log File
2019-09-09T08:48:43Z, 0x00000071, 1, 0, 0, **************************************************************
2019-09-09T08:48:58Z, 0x00000007, 1, 0, 6, Network interface: <ipaddress>192.168.63.1</ipaddress>, subnetmask <subnetmask>255.255.255.0</subnetmask>
2019-09-09T08:48:58Z, 0x00000018, 1, 0, 4, Network interface <interface>ether 5</interface> at router <instance>2</instance> registered
2019-09-09T08:48:58Z, 0x00000018, 1, 0, 1, Setting router <instance>2</instance> address to <address>(0001)</address>
2019-09-09T08:49:04Z, 0x00000007, 1, 0, 6, Network interface: <ipaddress>169.254.185.103</ipaddress>, subnetmask <subnetmask>255.255.0.0</subnetmask>
2019-09-09T08:49:04Z, 0x00000018, 1, 0, 4, Network interface <interface>ether 4</interface> at router <instance>3</instance> registered
2019-09-09T08:49:04Z, 0x00000018, 1, 0, 1, Setting router <instance>3</instance> address to <address>(0000:b967)</address>
2019-09-09T08:49:13Z, 0x00000111, 2, 0, 2, !!!! Warning: Duplicate IP detected. Skipping second one.
2019-09-09T08:49:46Z, 0x00000001, 1, 0, 0, runtime licensed


In the Shutdown_Signal event:
Code:
Process List of co* : In Shutdown_Event
   37 ?        00:00:00 kcompactd0
   69 ?        00:00:00 mmc_complete
   73 ?        00:00:00 ext4-rsv-conver
   75 ?        00:00:00 ipv6_addrconf

Something has caused the Codesys process to close.
Code:
Codesys Log File
2019-09-09T08:48:43Z, 0x00000071, 1, 0, 0, **************************************************************
2019-09-09T08:48:58Z, 0x00000007, 1, 0, 6, Network interface: <ipaddress>192.168.63.1</ipaddress>, subnetmask <subnetmask>255.255.255.0</subnetmask>
2019-09-09T08:48:58Z, 0x00000018, 1, 0, 4, Network interface <interface>ether 5</interface> at router <instance>2</instance> registered
2019-09-09T08:48:58Z, 0x00000018, 1, 0, 1, Setting router <instance>2</instance> address to <address>(0001)</address>
2019-09-09T08:49:04Z, 0x00000007, 1, 0, 6, Network interface: <ipaddress>169.254.185.103</ipaddress>, subnetmask <subnetmask>255.255.0.0</subnetmask>
2019-09-09T08:49:04Z, 0x00000018, 1, 0, 4, Network interface <interface>ether 4</interface> at router <instance>3</instance> registered
2019-09-09T08:49:04Z, 0x00000018, 1, 0, 1, Setting router <instance>3</instance> address to <address>(0000:b967)</address>
2019-09-09T08:49:13Z, 0x00000111, 2, 0, 2, !!!! Warning: Duplicate IP detected. Skipping second one.
2019-09-09T08:49:46Z, 0x00000001, 1, 0, 0, runtime licensed
2019-09-09T08:49:54Z, 0x00000018, 1, 0, 5, Network interface <interface>ether 5</interface> unregistered
2019-09-09T08:49:54Z, 0x00000018, 1, 0, 5, Network interface <interface>ether 4</interface> unregistered
2019-09-09T08:49:54Z, 0x000010f0, 1, 0, 1, <NetworkName>eth0</NetworkName><IPAddress>0.0.0.0</IPAddress><Subnetmask>0.0.0.0<Component>IoDrvEthernet</Component>


The log file only reported "unregistered" of ethernet interfaces. I assume this is because the ethernet ports are powered down in UPS Alert state. Could this cause Codesys to close abruptly?


Top
   
PostPosted: Tue Sep 10, 2019 7:07 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3451
Hi,
guess not.

Could you please stop the plc , followed by a (as sudo):

cd /var/opt/codesys
/opt/codesys/bin/codesyscontrol.bin -d /etc/CODESYSControl.cfg

Then you should a litte more information on this manual start of the runtime.

Why does your UPS not a simple trigger a 'shutdown -h now' - then I think it will close/shutdown the runtime in correct way

BR
Edwin


Top
   
PostPosted: Tue Sep 10, 2019 8:16 pm 
Offline

Joined: Sat Feb 17, 2007 5:06 pm
Posts: 29
The BB-400 goes into alert mode, then powers down the peripherals, but keeps the CPU running. If power is restored in less than 60 seconds, it will power the peripherals back up. If no power longer than 60 seconds, it will perform the shutdown -h now

Here is the last few lines from running the recommended test:
Code:
SysTaskFrame[425]:  OPCUAServer(tid:1603,OSprio:0) running
SysTaskCreate[497]: create CommCycleHook(prio:223,interval:0us,stacksize:131072)
SysTaskFrame[425]:  CommCycleHook(tid:1604,OSprio:0) running
SysTaskCreate[497]: create X509AsyncTask(prio:255,interval:0us,stacksize:131072)
SysTaskFrame[425]:  X509AsyncTask(tid:1605,OSprio:0) running
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(5,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
SysSockSendTo[1268]: sendto(11,0x76a309f4,8,0x0,...):Invalid argument
ooops... this runtime was built for RASPBERRYPI (-22, 0x00000BB8, 0xFFFFFFFB)


Top
   
PostPosted: Tue Sep 10, 2019 8:48 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3451
Think if you let eth0 up and running it might work... give this a try if possible.
Br Edwin


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 20 posts ]  Go to page 1 2 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 7 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