<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Scheduling and long task-execution</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/61832d8d0a/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/61832d8d0a/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/61832d8d0a/</id><updated>2020-02-27T20:50:13.712000Z</updated><subtitle>Recent posts to Scheduling and long task-execution</subtitle><entry><title>Scheduling and long task-execution</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/61832d8d0a/?limit=25#2958" rel="alternate"/><published>2020-02-27T20:50:13.712000Z</published><updated>2020-02-27T20:50:13.712000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comb05fbec69cec082dad95528a816e2365b8ea5f85</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; Nicolai_Hanssing&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;spfeif hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Interesting that the task takes so long. Typically you have a watchdog timer that wouldn't let something run for more that ~100msec.&lt;br/&gt;
How are the recipes given to you and how many and often are they received? Maybe you can do the following:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;They are not recieved, but made online while the application is running (2 axis Scara-robot and several more servos and IO). When the operator wants to store the current active recipe, I insert it into the array, sort it, and I store the whole array on disk. Array is fixed size of 300, and is allways loaded into memory during bootup.&lt;/p&gt;
&lt;p&gt;If the array is allready sorted it does not take long, about 7-30ms.&lt;/p&gt;
&lt;p&gt;However if its is not, which was my testcase, and have long string as names like '0000001' '0000002' etc, then it took quite a while. The string compare function takes longer due to the names, and the sorting was worst-case for a bubble-sort. &lt;/p&gt;
&lt;p&gt;Seeing its not an issue during production, as the array is allways sorted except for the new insert, I'll just leave it be.&lt;/p&gt;
&lt;p&gt;Actually the write-access onto a flash-card afterwards takes longer, it takes 500ms or more.&lt;/p&gt;
&lt;p&gt;Nicolai&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scheduling and long task-execution</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/61832d8d0a/?limit=25#ac31" rel="alternate"/><published>2020-02-27T20:50:09.814000Z</published><updated>2020-02-27T20:50:09.814000Z</updated><author><name>spfeif</name><uri>https://forge.codesys.com/u/spfeif/</uri></author><id>https://forge.codesys.com27cb513f7fdc4a19a2c6337592e1bbddd827df26</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Interesting that the task takes so long. Typically you have a watchdog timer that wouldn't let something run for more that ~100msec.&lt;/p&gt;
&lt;p&gt;How are the recipes given to you and how many and often are they received? Maybe you can do the following:&lt;/p&gt;
&lt;p&gt;Create a multi-dimensional array.&lt;/p&gt;
&lt;p&gt;Sorted&lt;span&gt;[1..26,1..100]&lt;/span&gt; of MyRecipe;&lt;/p&gt;
&lt;p&gt;When received look at the first character of the name and add it to the array like. A = 1 B= 2, C=3, Z=26. Instead of sorting all the time you can break the sort into smaller chunks. So if you get a new recipe "Cookies" you can add it to the Sorted&lt;span&gt;[char(C) - 64,uLastIndex]&lt;/span&gt; then sort only Sorted&lt;span&gt;[3,100]&lt;/span&gt; instead of all recipes. Because it sounds more like you are inserting instead of resorting?&lt;/p&gt;
&lt;p&gt;Or if you have control of it add an id to the recipe and let the software outside of the PLC sort them?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scheduling and long task-execution</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/61832d8d0a/?limit=25#a1aa" rel="alternate"/><published>2020-02-27T20:50:08.382000Z</published><updated>2020-02-27T20:50:08.382000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com4a211ad17cbff4cf79c33bc30897571e5287d299</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; Nicolai_Hanssing&lt;/p&gt;
&lt;p&gt;Hi One clear question for you:&lt;/p&gt;
&lt;p&gt;System:&lt;/p&gt;
&lt;p&gt;CoDEsys 2.3.7.5&lt;/p&gt;
&lt;p&gt;Running in a multi-task enviroment, I have a low-priority task that does a sorting on a large array, wich sometime takes a long while to finish (several seconds).&lt;/p&gt;
&lt;p&gt;Will the scheduler restart the process on top of itself, as it is scheduled to run with a fixed cycle of 100ms?&lt;/p&gt;
&lt;p&gt;I've been unable to find a clear description of this, I assume not.&lt;/p&gt;
&lt;p&gt;NExt question:&lt;/p&gt;
&lt;p&gt;ANyone have a good way of sorting an array of structs, by a string inside the struct.&lt;/p&gt;
&lt;p&gt;Right now i've made a String-compare-function using OSCAT, that is called and returns that Str1&amp;gt;Str2, Str1&amp;lt;Str2 or Str1=Str2, .....&lt;/p&gt;
&lt;p&gt;and then do a cocktail-sort (bubble-variant)  &lt;/p&gt;
&lt;p&gt;Issue is sorting an array of recipies by their recipe-name.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>