CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Mon May 29, 2017 12:20 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Fri Nov 11, 2016 4:19 pm 
Offline

Joined: Wed Nov 09, 2016 8:15 am
Posts: 7
Hello experts,

I need to be able to apply variable value sets by uploading a file via FTP to a WAGO 750-831 controller.
You can simpli imagine this file as a name-value pair set like an INI.

Let's say the file contains these (but might be several hundreds of them, and it will not contain always all variables):
Code:
PLC_PRG.MyVar01=100
PLC_PRG.MyVar02=200

I have seen that parsing the file won't be a problem in CoDeSys v2.3.

But supposing that I have the name of the variable to be updated in a string variable (VARNAME) and the new value in an other (NEWVALUE), what is the best (resource and coding friendly) way to set the variable? I can imagine a big IF-THEN, but I hope that is not the best solution. I was thinking about some workarounds but first I want to ask if there is any direct solution.

Thank you in advance.

[Edit 11.11 16:44]
Unfortunately SysLibGetSymbolAddress is not available on the target.


Top
   
PostPosted: Sat Nov 12, 2016 10:52 pm 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 974
you can NOT change variable names, however in an array you can store any names set and the values too.
or you can just put them in designated places in an array

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


Top
   
PostPosted: Sun Nov 13, 2016 5:30 pm 
Offline

Joined: Wed Nov 09, 2016 8:15 am
Posts: 7
shooter wrote:
you can NOT change variable names, however in an array you can store any names set and the values too.
or you can just put them in designated places in an array


Hello,
I don't want to change the name of a variable, only the value.
Ok. This is one option I was thinking about. Although it has some drawbacks. First of all, in my case the high number (200-300) of variables makes this approach error prone.

I was thinking to get the address of the variable by parsing the symxml.SYM_XML symbol table. It is a promising approach. Still, it's content looks confusing. The SymbolVarList/Var/@Offset looks correct but relative to SysLibGetAddress(DATAID_GLOBVARS), but these are not globals. And the segment base addresses in the symxml look totally unrelated to the base address returned by SysLibGetAddress. See attachment.
Do you have any idea how to interpret symxml correctly?


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Mon Nov 14, 2016 4:08 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 218
I think you will need a big case statement. (Tip - Use MS Excel to build you case statement lines). When you send the file, the variable name would be a string for the case statement.


Top
   
PostPosted: Mon Nov 14, 2016 9:20 am 
Offline

Joined: Wed Nov 09, 2016 8:15 am
Posts: 7
scott_cunningham wrote:
I think you will need a big case statement. (Tip - Use MS Excel to build you case statement lines). When you send the file, the variable name would be a string for the case statement.

Thank you. The "big IF-THEN option" I was hoping not to need :) But if I have to stick to that, I was also thinking of generating it.

Anyway, CASE itself looks not to be an option, as when I tried to use it with strings, I got the error message, that CASE requires selector of type integer.


Top
   
PostPosted: Mon Nov 14, 2016 2:23 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 218
Yes, I see now that CASE needs a number in IEC61131.


Top
   
PostPosted: Mon Nov 14, 2016 11:25 pm 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 974
if the names are always same (only the number is different please use an array and get the number from the string.
if the names are all different and you do not want to use pointers, make an big array with all the names and a for next loop to find every string, and update the value

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


Top
   
PostPosted: Tue Feb 14, 2017 10:22 am 
Offline

Joined: Wed Nov 09, 2016 8:15 am
Posts: 7
What I have done is that I made my own symbol file from symxml. As there is a function that can return the starting address of the memory areas, I am storing in binary format in my file the symbol name, the memory area index, area relative memory offset and a code for the variable type (I am expanding all arrays and structures as needed even if they are not expanded in symxml). At PLC startup I am loading the content from this file into an array in memory. When I need to change a variable by name, I look for it in this array. As I know the type, I can now easily calculate the address, and it is now simple to set it.


Top
   
PostPosted: Wed Feb 15, 2017 10:06 pm 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 974
you can use pointers to find where a var is located.
please have a look at www.oscat.de for ways to do this.

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


Top
   
PostPosted: Fri Feb 17, 2017 7:55 am 
Offline

Joined: Wed Nov 09, 2016 8:15 am
Posts: 7
shooter wrote:
you can use pointers to find where a var is located.
please have a look at http://www.oscat.de for ways to do this.


I have looked trougd OSCAT allready. Which OSCAT POU can find a variable's address using the variable name?


Top
   
PostPosted: Mon Feb 27, 2017 5:54 pm 
Offline

Joined: Wed Dec 28, 2016 11:00 pm
Posts: 18
Bump!

I am also very interested in this Technique. I see possibilities in combining this with a protocol format like JSON would be very useful.
E.g. finding a varname out of a file and searching for it in the runtime and read/write it.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 11 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited