Jump to content
Sign in to follow this  
Guy Geva

Unitronics C functions (IF_EQ and similar) does not work

Recommended Posts

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.

errors.png

  • Like 1

Share this post


Link to post
Share on other sites

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
}
  • Upvote 1

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...