The PLC I am working with will receive a string of text. The format of the text string is:
'variable_name,variable_type,variable_value'.
What I need to do is to use the variable type and variable value information to update the variable that has the value 'variable_name'. I can convert the variable_value string to a number based on the variable_type string, but when the variable name can be one of a thousand variables or more, then this becomes a real challenge.
Is there a way to convert a string to a variable? For example, can I take the string value 'temperature_var' and change the value of the variable temperature_var?
I don't see a function to do that and am not sure that it would be a great way to code the project anyway. I haven't used structured programming like C or pascal in 15 years or more and am new to CoDeSys. Any input from those who are wise would be greatly appreciated!
Steve
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
you can not declare a variable inside a running program, however you can make a array with all the names inside and compare them to the incoming text,
like arraylong 1..1000 (name,type,variable)
find string inside your array and change the value.
if not found add string to array etc.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What are you ultimately trying to accomplish? You can use the CoDeSys gateway and DDE to accomplish communication to the PLC by directly read/write variables. Look at the CoDeSys manual under the DDE section. Otherwise you can point structures at memory addresses and you will only need to read/write the memory address.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your input. I was trying to create my own retain variable save and restore programs. But then I found the functions syssaveretains and sysrestoreretains. These functions MOSTLY work. I have started another post for the questions I have about implementing those function blocks. If you have experience with those functions, please read and reply to that post!
Thank you both for taking the time to consider and respond to my newbie question!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What PLC are you using? What communication buses are available? Where are you trying to read/write the values from? A PC connected to the PLC? I may have some solutions but more information is needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The PLC I am working with will receive a string of text. The format of the text string is:
'variable_name,variable_type,variable_value'.
What I need to do is to use the variable type and variable value information to update the variable that has the value 'variable_name'. I can convert the variable_value string to a number based on the variable_type string, but when the variable name can be one of a thousand variables or more, then this becomes a real challenge.
Is there a way to convert a string to a variable? For example, can I take the string value 'temperature_var' and change the value of the variable temperature_var?
I don't see a function to do that and am not sure that it would be a great way to code the project anyway. I haven't used structured programming like C or pascal in 15 years or more and am new to CoDeSys. Any input from those who are wise would be greatly appreciated!
Steve
you can not declare a variable inside a running program, however you can make a array with all the names inside and compare them to the incoming text,
like arraylong 1..1000 (name,type,variable)
find string inside your array and change the value.
if not found add string to array etc.
What are you ultimately trying to accomplish? You can use the CoDeSys gateway and DDE to accomplish communication to the PLC by directly read/write variables. Look at the CoDeSys manual under the DDE section. Otherwise you can point structures at memory addresses and you will only need to read/write the memory address.
Thank you for your input. I was trying to create my own retain variable save and restore programs. But then I found the functions syssaveretains and sysrestoreretains. These functions MOSTLY work. I have started another post for the questions I have about implementing those function blocks. If you have experience with those functions, please read and reply to that post!
Thank you both for taking the time to consider and respond to my newbie question!
What PLC are you using? What communication buses are available? Where are you trying to read/write the values from? A PC connected to the PLC? I may have some solutions but more information is needed.