Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

How can i read data from a file into an array?

bogdaniovu
2021-08-06
2021-08-09
  • bogdaniovu

    bogdaniovu - 2021-08-06

    Hi,
    I just started learning how to program PLCs and I've been struggling with reading data from a file into an array.

     
  • h-hermsen

    h-hermsen - 2021-08-06

    short primer: on how to tackle this.

    1 choose the right language to implement the code, Structered Text is imho the most suited. FBD or CFC could also be used, but that is a matter of taste. In your case something visual like FBD or CFC is probably advised since you say you are a beginner and do not provide any previous programming experience.

    2 write an code (FB) that can open, close, read and write files from disk.
    If you need examples, try to google for it or ask your OEM supplier for examples

    3 read a file into memory and organise it using an array.

    good luck

     
    • bogdaniovu

      bogdaniovu - 2021-08-06

      I'm currently solving it using Ladder, but I can also try it in FBD. I transferred the file (which contains 15 numbers) into the PLC memory using FTP, used a function to open the file and read it. Right now i'm struggling to move the numbers from the file to an array.

       
    • bogdaniovu

      bogdaniovu - 2021-08-06
       

      Last edit: bogdaniovu 2021-08-06
  • h-hermsen

    h-hermsen - 2021-08-06

    If you can read the file, moving data to an array shouldn't be an issue.

    1) What does your data on disk look like?
    2) Build a struct element which can hold this re-occuring data
    3) Read from 1 to N elements data into array of struct element[N]

     

    Last edit: h-hermsen 2021-08-06
    • bogdaniovu

      bogdaniovu - 2021-08-06

      can you please be so kind and help me with the diagram or code, for the past 5 days i've been searching for a solution

       
      • h-hermsen

        h-hermsen - 2021-08-06

        Then you should at least post your code as .pro

         

        Last edit: h-hermsen 2021-08-08
        • bogdaniovu

          bogdaniovu - 2021-08-09

          Sorry for the late reply.

           
        • bogdaniovu

          bogdaniovu - 2021-08-09
           

          Last edit: bogdaniovu 2021-08-09

Log in to post a comment.