Hi.
Im looking for a way to address variables in memory are. I know you can address it like %Mw0. Is it possible to make this with index like %mw(index) or should i use another way to read and write values. Any ideas would be great.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not exactly.
So i have my custom structure in global variables list. It goes like:
Analog_300_A13EGA10CF001
Analog_301_A13EGA20CF001 ect.
Since Scada system is goes over modbus, variables has to have address.
So my tag goes like Ana_list.Analog_300_A13EGA10CF001. I cant really use array, because it will impossible to code process.
And since i have more objects including valves, motors, that makes quite a lot of tags. So i was wondering if i could just copy of my item to HMI to configuration window and then read/write values over it.
First attempt
PROGRAM PLC_PRG
VAR
NR : INT; // number tage
A,B,C,D : Ana; // test objects
Indr: Ana;
Copy: Ana;
ptInt, ptInt2: POINTER TO Ana;
e : BOOL;
Before,after1 : real;
END_VAR
// program
CASE NR OF // selecting object from tag list
1: ptInt := ADR(A);
2: ptInt := ADR(B);
3: ptInt := ADR(C);
4: ptInt := ADR(D);
ELSE
ptInt :=ADR(Indr); // If none selected give spare copy
END_CASE
Copy:= ptInt^; // Write values from tag in GVL item to copy -part working
Before := Copy.Sim_value; // testing tag
ptInt^.Sim_value :=Copy.Sim_value; // Writing values from copy to tag inG VL- not working, too fast rewrites values
After1 :=Copy.Sim_value;// testing tag
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am a bit confused. The code you provide does not seem to reference your global variables list, there are no "AT" addresses. I do not understand what your intent is with the code at the bottom, or what you mean exactly by "working, too fast rewrites values".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Like i said, its just a test.
My structure looks like in picture. You can address it by using %MW or there is another way to address it. My test code was done with symbolic address. If i make break points and go line by line and i write value to Copy tag
Copy:= ptInt^;// <- here while program is halted
then this operation writes value from copy tag to tag in test area
ptInt^.Sim_value :=Copy.Sim_value; //
This idea comes from simatic where you can reach so called Data blocks with Area Registers (IL). Then you could read and transfer values in you data block
Now, define a union, which will give two "views" of the same memory area, so that we can see it both as an array and as a structure of individual entries.
TYPE Analog_300_union :UNION entries: Analog_300_entries; arrayed: ARRAY[0..3] OF Analog_300_A13EGA10CF001;END_UNIONEND_TYPE
You instantiate that union in a global variables list :
VAR_GLOBAL Analog_300 AT %MW0: Analog_300_union;END_VAR
In your program, you now have both the "individual variable view", the "arrayed view", and the "AT" addressing. Here is example code to show that both "views" really work on the same data.
Personally, I would forego the union and individual entry structures and only use the array. It is more concise, and allows adjusting array size with a "configurable constant" (no other code change). This still allows "AT" addresses for communication. I only use structured code, maybe this blinds me to cases where arrays are not as easy to code for.
However, if you prefer, or for some reason are forced, to have variables accessible in a way that does not use arrays, the above should work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi.
Im looking for a way to address variables in memory are. I know you can address it like %Mw0. Is it possible to make this with index like %mw(index) or should i use another way to read and write values. Any ideas would be great.
Do you mean something like this?
This will also work using a structure as a type rather than an "ARRAY OF", where said structure may itself recursively contain structures and arrays.
Maybe you could explain a bit why you want to use %M addresses to help us understand what you are trying to achieve?
Related
Talk.ru: 1
Not exactly.
So i have my custom structure in global variables list. It goes like:
Analog_300_A13EGA10CF001
Analog_301_A13EGA20CF001 ect.
Since Scada system is goes over modbus, variables has to have address.
So my tag goes like Ana_list.Analog_300_A13EGA10CF001. I cant really use array, because it will impossible to code process.
And since i have more objects including valves, motors, that makes quite a lot of tags. So i was wondering if i could just copy of my item to HMI to configuration window and then read/write values over it.
First attempt
PROGRAM PLC_PRG
VAR
NR : INT; // number tage
A,B,C,D : Ana; // test objects
Indr: Ana;
Copy: Ana;
ptInt, ptInt2: POINTER TO Ana;
e : BOOL;
Before,after1 : real;
END_VAR
// program
CASE NR OF // selecting object from tag list
1: ptInt := ADR(A);
2: ptInt := ADR(B);
3: ptInt := ADR(C);
4: ptInt := ADR(D);
ELSE
ptInt :=ADR(Indr); // If none selected give spare copy
END_CASE
Copy:= ptInt^; // Write values from tag in GVL item to copy -part working
Before := Copy.Sim_value; // testing tag
ptInt^.Sim_value :=Copy.Sim_value; // Writing values from copy to tag inG VL- not working, too fast rewrites values
After1 :=Copy.Sim_value;// testing tag
I am a bit confused. The code you provide does not seem to reference your global variables list, there are no "AT" addresses. I do not understand what your intent is with the code at the bottom, or what you mean exactly by "working, too fast rewrites values".
Like i said, its just a test.
My structure looks like in picture. You can address it by using %MW or there is another way to address it. My test code was done with symbolic address. If i make break points and go line by line and i write value to Copy tag
Copy:= ptInt^;// <- here while program is halted
then this operation writes value from copy tag to tag in test area
ptInt^.Sim_value :=Copy.Sim_value; //
This idea comes from simatic where you can reach so called Data blocks with Area Registers (IL). Then you could read and transfer values in you data block
Here is what I think you are trying to achieve :
Here is one way this may be done.
First, I will assume you have a structure for each of your analog values that looks like this :
Then, define a structure that has all the entries you need. Please note this is much like defining an array by explicitly instantiating each entry.
Now, define a union, which will give two "views" of the same memory area, so that we can see it both as an array and as a structure of individual entries.
You instantiate that union in a global variables list :
In your program, you now have both the "individual variable view", the "arrayed view", and the "AT" addressing. Here is example code to show that both "views" really work on the same data.
Is that close to what you want to do?
Related
Talk.ru: 1
Talk.ru: 3
Last edit: fajean 2022-08-31
Bingo. Thanks!
Bingo. Thanks!
Bingo. Thanks!
Bingo. Thanks
Sorry, crashed browser.
Personally, I would forego the union and individual entry structures and only use the array. It is more concise, and allows adjusting array size with a "configurable constant" (no other code change). This still allows "AT" addresses for communication. I only use structured code, maybe this blinds me to cases where arrays are not as easy to code for.
However, if you prefer, or for some reason are forced, to have variables accessible in a way that does not use arrays, the above should work.