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):
PLC_PRG.MyVar01=100PLC_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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
shooter hat geschrieben:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-11-14
Originally created by: scott_cunningham
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
scott_cunningham hat geschrieben:
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 "" 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 .
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-11-14
Originally created by: scott_cunningham
Yes, I see now that CASE needs a number in IEC61131.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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):
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.
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?
Originally created by: scott_cunningham
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 "" 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 .
Originally created by: scott_cunningham
Yes, I see now that CASE needs a number in IEC61131.
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
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.
you can use pointers to find where a var is located.
please have a look at w www.oscat.de w for ways to do this.
I have looked trougd OSCAT allready. Which OSCAT POU can find a variable's address using the variable name?
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.
It has been a few years since this topic. Any solutions?