Paolo
Good evening,
My machine allows me to cut panels to the desired length.
Is it possible, when starting the PLC, to fill in an array with the lengths to be cut? For example with a file on the RPi desktop (txt or csv file for example) or by sending a string via Fuxa?
Like 125,125,200,200,320,320,130,130 to fill the array [1..8] ?
Thank you
Reply 0 0
Paolo
I'm starting to understand how to do in C :
using System.IO;

static void Main(string[] args)
{
    using(var reader = new StreamReader(@"C:\test.csv"))
    {
        List<string> listA = new List<string>();
        List<string> listB = new List<string>();
        while (!reader.EndOfStream)
        {
            var line = reader.ReadLine();
            var values = line.Split(';');

            listA.Add(values[0]);
            listB.Add(values[1]);
        }
    }
}
Those array listA and listB can be declared in my structured text function block and so be filled by the C code ?
Reply 0 0
thiagoralves
From your code, listA and listB are C++ arrays, not IEC arrays. In fact, most of your code is C++ and won't work. The core is just C, so you will have to use C libraries to read files. 
 
I think the easiest way for you to accomplish this would be to send these values over Modbus. You can have a function block that stores the values on the array, something like this:
Screenshot 2024-02-21 at 9.36.24 AM.png
 
You can code the block so that every time there is a rising pulse on STORE, the value on VALUE is stored in the DATA_ARRAY at position POS. Then you connect modbus variables to control STORE, VALUE and POS. With a simple Python + PyModbus program you can send all the values for the array by just manipulating these variables.
Reply 1 0
Paolo
Nice !
Did you think that you can send me this function block ?
Reply 0 0
thiagoralves
I didn’t code the block, just created an empty one to draft the structure you could build. But if you know a little bit of ST, it should be fairly straightforward to code this block.
Reply 0 0
Paolo
I suspected this, so here's what I didOpenPLC-Editor---~gestion_debit~-08_03_2024-14_52_05.gif
Reply 0 0
Paolo
OpenPLC Editor - ~gestion_debit~ 08_03_2024 14_58_50.png
Reply 0 0
thiagoralves
This might work. The only adjustments I would make are
1. change your store condition to be rising edge triggered. Then you won’t have the issue of mistakenly modifying other positions in the array while the store is true.
2. check for the position boundaries BEFORE making the array assignment 
Reply 0 0
Paolo

Thanks, but I don't know how to program this language. So I'm learning by doing and following examples on the internet.  Unfortunately I can't find an example of edge detection to answer your first point. The second point is obvious, thank you!

Reply 0 0
thiagoralves
This is just logic, not a programming syntax. You will have to define a bool variable to "remember" the previous state of STORE. You can call it PREVIOUS_STATE_OF_STORE. Then you just check if PREVIOUS_STATE_OF_STORE is FALSE and STORE is TRUE (which means you just had a rising edge). If that's true, then you can do the array manipulation. Just remember to always end your code with PREVIOUS_STATE_OF_STORE := STORE so that your can keep the previous state of STORE on that variable.
Reply 1 0
Reply