Guy Geva Posted July 11, 2018 Report Posted July 11, 2018 Code like this fail to compile, with the errors in the image below. The error lines are wrong (which I'll report to unitronics in a bit), but the code compiles without the lines I showed. static void Function3() { // User code starts below this comment float a = 50; float b = 3; if(IF_EQ(1, a, 4)) STORE(1, 4, b); // User code ends above this comment } Am I using IF_EQ wrong? The docs say that IF_EQ(1,a,b) is equivalent to a == b, so I assume that this is the correct syntax. 1
Saragani Posted July 11, 2018 Report Posted July 11, 2018 No, you are not using it correctly. The element does compare 2 numbers, but it accepts an RLO (the first parameter), and it overwrites its value. The correct code would be: Please note that I still had compilation errors, which were due to white spaces (or something), after deleting the tabs, then it worked correctly. I did not download the code in order to see that it works on the PLC, and that it doesn't cause CPU error. You must use volatile float static void Function3() { // User code starts below this comment volatile float a = 50; volatile float b = 3; int rlo = 1; IF_EQ(rlo, a, (volatile float)4.0); if (rlo) { STORE(1, (volatile float)4.0, b); } // User code ends above this comment } 1
Guy Geva Posted July 12, 2018 Author Report Posted July 12, 2018 Thank you very much for the quick reply. I did what you said and it compiles just fine. I have two additional questions about this topic - 1) Is every 1 at the beginning of a function call an output bit? 2) Where is this information available? The help manual (specifically the 'C' Functions page) doesn't say anything about that, and the only thing about it that I found in google is the same manual page.
Saragani Posted July 12, 2018 Report Posted July 12, 2018 I'm not sure I understand question #1, but if you ask about the (1, at the beginning of every element code, then it is the RLO bit. Since you want to run it, then you pass a cost 1, but on some cases, where the element is an element that affects the RLO, then you should pass the RLO instead (for example, in INC element, you can pass 1, since it does not affect the RLO, but compares for example does). You can see the code calls of elements if you put one on the ladder, fill the tags, and then view the structure text.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now