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.
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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,
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.
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.
Hello,
Thank you! for your input we will go ahead with using array.
Warmest regards,