Store PLCnext CommunityPLCnext on LinkedInPLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

  1. Arne Smets
  2. PLCnext Engineer
  3. Tuesday, 23 February 2021

Hello,

I wanted to use methods on the HMI, but I heard that it's not possible (yet).. (Thread: https://www.plcnext-community.net/en/discussions-2-offcanvas/use-functionblock-methods-directly-on-ehmi.html)

So I was trying to make a workaround today. What I wanted to do is define FB1 globally. I am able to go to the PLCvariables and create a variable FB1. (The type is not in the dropdown list, but if I write it manually it is not giving an error..) But when I'm trying to use it in a program, it gives me errors that the local variable does not excist.

I can create the local variable with the same name, but then the global variable is unused. It's also not possible to change the usage of the variable in the program to something else then local. Is it possible to declare it globally?

 

The main goal of the way I try to program is OOP. I thought the methods could really help me out with that. But since the HMI is not able to use them, I have to make a link between variables of the HMI and the FB1. I've done this with a struct, defined as InOut. The FB1 communicates via the InOut with all values, which are stored in the GDS. After this I wanted to declare the FB1 globally. These are all workarounds, so I would prefer a different solution..

Does anybody has some experience with OOP in PLCnext Engineer?

Arne...

Frank PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Hey Arne,

interesting request and we've discussed this post a lot yesterday late evening in the support channel :-).

We've udnerstood of course that you like to use methods like getter/setter to manipulate or to read data from your functionblock (which is unfortunatly not possible with the HMI),
but now we are struggeling a bit why the functionblock should be acting like a global defined variable.

A functionblock in terms of PLCnext Engineer is not just somekind of udt, it has to be instanciated and executed, means bound to a program.
Otherwise will the functionblock not even be constructed.

Than we were thinking in the direction of OPC UA Method calls (OPC UA external information models (plcnext.help)) which relates also to fixed instances of a FB...

Hmm, you see, we are very interested in what you are doing, but please give us a bit more insight :-).

Frank

Phoenix Contact Electronics Headquarter - PLCnext Runtime Product Management and Support
  1. one week ago
  2. PLCnext Engineer
  3. # 1
Arne Smets Accepted Answer Pending Moderation
0
Votes
Undo

Hey Frank,

 

Thanks, I appreciate that Phoenix is discussing this very quickly. I try to explain a bit more. Maybe I've been thinking to much and missing something easy. I planned a sketch session this morning to clear my mind. Later this day I will discuss again with a collegue, maybe he has something to add to this answer..

So the main goal is/was making a functionblock which handles all data aswell. With that, future steps will be easy and very modulair. The only thing what's necessary is declaring an instance. Later, for all actions it's possible to use the methods. In PLCNext Engineer, no variables have to be created, since every instance will have their own fields where the data is stored. 

Since the HMI is not capable of handling the methods, I was thinking about a workaround. Because the GDS is available in HMI, I wanted to save the whole functionblock there. Maybe that wasn't the best idea, but then the instance will be available all over the program. But as you mentioned, a FB does not really work like that. I am also trying to create a parameter on the HMI as UDT, and then copy all data to the HMI, and copy the inputs of the HMI to the FB. But I was struggeling with that a bit. It could be a solution. (But it's not very nice as programmer haha).  What we also have in mind right now is creating a struct in C#, and make an InOut Port from that UDT. Then in PLCNext Engineer, define the UDT as external (thus globally). Then it's possible to write/read that data and also get the input from the HMI.

The downside of this is that we have to create variables in PLCNext Engineer if we want to use that FB, since it has some kind of interface. Otherwise it's impossible to use it. The goal is actually putting everything in the 'black box' FB, so there is no need to add all stuff outside that black box to make it work.

I will take a look at the OPC UA aswell, but maybe that's also to much of extra work when adding the FB. It's our goal to make it easy, not complicated;).

If I've news or more insights/questions I will let you know in this thread.

Arne

  1. one week ago
  2. PLCnext Engineer
  3. # 2
Arne Smets Accepted Answer Pending Moderation
0
Votes
Undo

So we decided to define a InOut port to make a link between a global PLCnext variable that belongs to an instance of the FB. This way it can be modified by the FB and is available in the other programs and HMI.

So in C#:

[InOut]

public STRUCT data;

In Engineer global variable:

DataInstance1, type STRUCT.

The problem I have now is that the [Initializaton] part of the C# block is not executed. I wanted to write init values directly to the STRUCT (for exemple: data.Iecstring80.ctor(); data.integer = 100;). Does it not work like that? All other variables remain zero, and it seems not possible to write something in the string. When is the Initialization executed? Or how should I do that?

Or maybe, how can I initialize it in PLCnext engineer? Because there is only 1 box as initvalue for the whole struct.... 

Arne

 

EDIT

I've made a init ifstatement in the execution. I made a private int a = 0, and at the end of the if statement (if a = 0), I execute a++; So a will never be 0 again and the FB will never execute that code again. But this is obviously not the best way to go...

  1. one week ago
  2. PLCnext Engineer
  3. # 3
Frank PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Hey Arne,

gues this can be easily resolved by having the code.

Can we come back to you directly by mail? 

We can also talk directly about the general requirement.

What do you think?

Have a great weekend,

Frank

Phoenix Contact Electronics Headquarter - PLCnext Runtime Product Management and Support
  1. one week ago
  2. PLCnext Engineer
  3. # 4
Arne Smets Accepted Answer Pending Moderation
0
Votes
Undo

Hello Frank,

Yeah that's fine. I have some restrictions to sharing code, but I can definetly send a small program to shows what's going wrong.

Since we have a deadline, we made some decisions. So not everything in this thread has to be resolved anymore (However I would like to be updated if the method functionality is expanded for personal interest)

But I still have the string problem, so I would like to share that.

Which email adress can be used? I can't upload the whole zip here.

Thanks

Arne

 

  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.