Author Topic: Difference Function/Function block  (Read 13842 times)

Offline swordfeather

  • PLUS+1 Developer
  • ***
  • Posts: 14
  • Karma: +1/-0
Difference Function/Function block
« on: October 28, 2020, 06:45:41 PM »
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 




Offline G30RG3

  • PLUS+1 Expert
  • ****
  • Posts: 74
  • Karma: +3/-0
Re: Difference Function/Function block
« Reply #1 on: November 11, 2020, 07:30:43 PM »
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

Offline Tor

  • Administrator
  • PLUS+1 Guru
  • *
  • Posts: 296
  • Karma: +28/-1
Re: Difference Function/Function block
« Reply #2 on: November 13, 2020, 10:47:59 AM »
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.
« Last Edit: November 13, 2020, 11:24:14 AM by Tor »
Best regards,
Tor
PLUS+1® SW PAE Team

Offline G30RG3

  • PLUS+1 Expert
  • ****
  • Posts: 74
  • Karma: +3/-0
Re: Difference Function/Function block
« Reply #3 on: November 13, 2020, 11:49:44 AM »
Hi Swordfeather,

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


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 :)
« Last Edit: November 13, 2020, 11:51:40 AM by G30RG3 »

Offline jashom1

  • PLUS+1 Expert
  • ****
  • Posts: 80
  • Karma: +6/-0
Re: Difference Function/Function block
« Reply #4 on: December 11, 2020, 04:48:41 AM »
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.

Offline swordfeather

  • PLUS+1 Developer
  • ***
  • Posts: 14
  • Karma: +1/-0
Re: Difference Function/Function block
« Reply #5 on: May 10, 2021, 10:06:15 PM »
Hi,

Long time since I've been here.
Thanks for all the help but I've switched to STL cause I needed to move fw.

Again my appreciation.

grt