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

  1. Sidnei Marcondes
  2. PLCnext Technology & PLCnext Controls
  3. Wednesday, 09 September 2020

Hi,

I have developed a app based in SampleRuntime app. In this app, I am using the Subscription function to read the value of some variables defined by the user.

In the firmware version 2020.0, the ReadVariablesInfo and ReadVariablesValue functions returns me a vector with the variables name and variables value in the same order that the variables was subscribed.

Ex: Subscribe : Var1, Var2, Var3 

       Read:         Var1, Var2, Var3

But in the firmware version 2020.6.1, the variables are been returned in decrescent order.

Ex: Subscribe: Var1, Var2, Var3

      Read:         Var3, Var2, Var1

Do you know if something changed with the Subscribe Service in the version 2020.6 ?

Is there any way to define the order of the variables will be returned by the ReadVariablesInfo and ReadVariablesValue functions ?

Thank you,

Sidnei Marcondes

 

Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Hi Sidnei,

When you say "ReadVariablesInfo", do you mean the GetVariableInfos method of the Subscription service?

(if not, please let us know)

If so, the documentation for that method indicates that the order of the variables returned by this method is not necessarily the same as the order that the variables were added to the subscription:


2020 09 09 14 50 19


(this has been in the documentation since at least version 2020.0 LTS).

It may be that the order of the variables has changed from version 2020.0 to version 2020.6, but the documentation is clear - there is no defined relationship between the order that the variables were added to the subscription, and the order that they are read.

Please let me know if I have misunderstood anything in your question.

Regards,
Martin.

 

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support

Sidnei Marcondes Accepted Answer Pending Moderation
0
Votes
Undo

Hi Martin,

You understand my question correctly. I mean GetVariablesInfo.

Then, regarding the manual, I can´t trust in the order of the received vector. I have to compare item by item to find the variable value in the vector. Is it correctly ?

This is not pratical. If I have 20 variables, I have to do 20 x 20 loops (400) to match all variables with its values in all app cycle. Maybe this could impact the performance of the app.

Could you give me a tip ? How do you read the variables in your MQTT Client app ?

Do you use the Subscribe Service or do you read the variables one by one with the DataAccess Service ?

Which Service Could have less performance impact in the app ?

 

Thank you,

Sidnei

 

Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Hi Sidnei,

Yes, the "old" (current) MQTT client app simply uses the Data Access service, which make things much simpler but much less efficient. The good news is that there is a completely new and much improved MQTT Client app on the way, which can be used directly from PLCnext Engineer, and does not use RSC services at all. So that solves the problem for me.   :-)

In your case, note that the order of the variables might not be the same as the order they were subscribed, but they will always be returned in the same order until "Resubscribe" is called. This means you do not have to check the position of the variables on every scan cycle, but you might be able to do something like:

  • Subscribe to the variables.
  • GetVariablesInfo. Store the "position" of each variable as an integer, corresponding to the position of the variable.
  • On each scan cycle: "ReadValues", and look up the value of each variable using the array index (integer) stored from the previous step.

In this way, you do not need to call GetVariablesInfo on each scan cycle, only ReadValues.

e.g.

- Subscribe: Var1, Var2, Var3

- GetVariablesInfo: Var2, Var3, Var1

... so you could assign an array of Ints, VarPositions := [3, 1, 2] corresponding to the location of variables Var1, Var2 and Var3.

- ReadValues returns three values e.g. Values := [42, 31, 87]

Var1 := Values [ VarPosition [1] ];
Var2 := Values [ VarPosition [2] ];
Var3 := Values [ VarPosition [3] ];

I would be interested to know if something like this works for you, or if you find a better solution.

Regards,
Martin.

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support

Sidnei Marcondes Accepted Answer Pending Moderation
0
Votes
Undo

Hi Martin,

Your solution was perfect to me.

As you suggested, I am identifying the correct position of the subscribed variables, once after to create the subscription. As my variable subscribed is organized in a struct, I had only to include one more parameter, readValuePosition. 

After, I had only to use the correct index in the vector of the Read Variables.

Thank so much for your help.

Sidnei

  • Page :
  • 1


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