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

Table of unit conversion

open
2023-01-10
2023-01-11
  • open - 2023-01-10

    Hi,

    I am new to Codesys Forge not sure if this is the right place to post this.

    I am using Codesys for PLC programming and we have a specific table of unit conversion (see attached) to convert the unit, however the lines will be very long if we were to use the IF Else function for conversion.

    Are there any other ways to simplify the process?

    Warmest regards,

     
    • nothinrandom - 2023-01-10

      This is just a lookup table. Are you interested in all columns or just the angle and stroke?

      If only angle and stroke, then simply create a REAL array with index of 0 (e.g. myTable: array[0..33] of REAL := [0, 27.88, 55.77, 83.66, (fill in the rest here)].

      If you're interested in all columns, then probably need to create multiple arrays (e.g. one for angle, one for stroke, one for difference) since angle is INT, and the other two are REAL. Anyway, then just index through them.

       
      πŸ‘
      1
  • ojz0r - 2023-01-10

    How about a CASE statement?
    Or maybe put the data in an array and loop through it to find the match. This is probably the shortest code.

    But usually you only write the code once and maybe using brute force IF Else statements is easier to maintain.

     
    πŸ‘
    1
  • open - 2023-01-11

    Hello,

    Thank you! for your input we will go ahead with using array.

    Warmest regards,

     

Log in to post a comment.