PLUS+1™ Tools > PLUS+1™ and C

Difference Function/Function block

(1/2) > >>

swordfeather:
Tried to build a small program in c code but I get compiling errors. When I use a function block I get compiling errors as shown below.
When I change the function block to a function the program compiles but it does not work. It gives an error about the Out1 being a pointer instead of a normal INT.

Anyone can explain why it works this way and how i fix it?

Thanks in advance


-------------------------Interface
VAR_INPUT
  int1 : INT;
  int2 : INT;
END_VAR
VAR_OUTPUT
  out1 : INT;
END_VAR

------------------------------------Code itself
//Write the C Code function body here.
//You have access to everything defined in any of the available header files listed under the PLC Units node in the Project Manager


out1 =  int2 - int1;


-----------------------------------------Compiling error
-ffreestanding -nostdinc -D CHAR_BIT=16 -IC:\ProgramData\Danfoss\PLUS1\12.1\Data\Precompile Analysis\
Translation unit: _PLCprecomp.c

3 Errors:
 - use of undeclared identifier 'Out1' In: AddFunction Line: 4 Column: 1 Category: Semantic Issue
 - use of undeclared identifier 'INT1' In: AddFunction Line: 4 Column: 8 Category: Semantic Issue
 - use of undeclared identifier 'int2' In: AddFunction Line: 4 Column: 15 Category: Semantic Issue 



G30RG3:
Hi SwordFeather,

I'm by no means a specialist, and hoped some of those would've helped you along by now, but since this is too quiet, I've tried to help you get started.
One might hope that someone else can add to this, or correct whatever I've done that can be done in a better way...
I've made a simple app with three types of "call POU"'s, which should all do their job.
In this sample, I made a "Call POU" Function in C, one Function in Structured text and a small Function Block in C...
Check the Help files in the PLC/C Editor.

B.R.  G3ORG3

Tor:
Hi Swordfeather,

I am not a C expert so I will point you to the User manual for this. You'll find the GUIDE User Manual in the Help drop down.
If you search for C Code in PLUS+1 GUIDE you'll find the parts.
The difference between Functions and Function Blocks is on page 414 in my version. I have also attached an image of this part.

If you don't find the answers in the manual please let us know. Either here or to plus1helpdesk@danfoss.com.

Have a nice day.

G30RG3:

--- Quote from: Tor on November 13, 2020, 10:47:59 AM ---Hi Swordfeather,

 You'll find the GUIDE User Manual in the Help drop down.


--- End quote ---

It would help a lot if the info in the guide user manual / helpfile is 100% up to date.
As far as i know, Menu's have been changed, details differ...
A few samples with "best practice advice" here and elsewhere would help a lot :)

jashom1:
Hi,

My quick glance at this - should you be using ":=" instead of just "="

eg:
-------------------------Interface
VAR_INPUT
  int1 : INT;
  int2 : INT;
END_VAR
VAR_OUTPUT
  out1 : INT;
END_VAR

------------------------------------Code itself
//Write the C Code function body here.
//You have access to everything defined in any of the available header files listed under the PLC Units node in the Project Manager


out1 :=  int2 - int1;

Would that make the difference?

John.

Navigation

[0] Message Index

[#] Next page

Go to full version