Pointer data type - Separate 4 out of 6 bytes to 3 variables

Exactly man, u understood fully what I am up to.
My goal was that user enter easily address,
Not hex Dec number in dword part.
Intead of entering W#16#840005 I need more easier solution, DB number, mem area and bit address all should be separate numbers.
So it is just how to later combine them into one Dword,
I am speaking about Dword since DB number is standalone as word
 
You can build the pointer and store it in a DB in a list of pointers.
No can't enter directly as a tag, but can enter parts and have a function that builds the pointer and stores it in a db. Pointers are too big to exist in accumulator unless you break it into db number/mem area then the address.


On your HMI screen, have drop down list to select each memory area, then type in each address. Combine these in a function.

Drop down select db/I/Q/M...then enter 32.5...

(of course 32.5 is not a "real", it is a pointer DWORD so you have to assemble it correctly.)
L 32 // you would use a variable instead of 32 and 5.
SLD 3
L 5
AD
T Address.

or drop down list to show a list of approved choices.

The "pointer UDT" would be easy way to enter the values from the HMI. Load each part into the udt then feed the udt into the function and move the assembled pointer into a db.

Then you have your lookup table of re directed addresses.

Now when you look in db1.dbx0.0 byte 6 you will see the pointer for some address. Then you can decode that pointer.

Or store it as the udt also so it is easier to decode.
When u r saying POINTER_UdT, u mean custom designed Pointer cuz data type pointer is not allowed in UDT, also not in DB as well?
 
When u r saying POINTER_UdT, u mean custom designed Pointer cuz data type pointer is not allowed in UDT, also not in DB as well?

no I mean a udt that is used to reference a place a memory. A collection of pieces to build a "pointer"

like udtX := x.dbnumber, x. memarea, x.byte, x.bit.
Now make an array of udtX.
That is your list of "pointers"
There is no need for an actual pointer. You would just be building it , storing it, then reading it and deconstructing it anyway, so what's the point?

Just store the info of where the data is and then read it out.

HMI enter:
x.dbnumber
x. memarea
x.byte
x.bit

"Array" := Array [0..15] of udtX // stored in a db

copy "Array[mychoice]" into local memory then build "pointer" LAR1 and read data or write data.

then

L x.dbnumber //int
L 0
==I
JC notdb


L x.byte //dword
SLD 3
L x.bit // word or dword it is only 0-7
AD
LAR1
opn db[x.dbnumber]

L D [AR1,P#0.0] // your data is loaded in acc1
T NewPlace

or
L NewData
T D [AR1,P#0.0]

jmp end or beu


notdb:

L x.byte //dword
SLD 3
L x.bit // word or dword it is only 0-7
AD
L x.memarea
AD
LAR1

L D [AR1,P#0.0] // your data is loaded in acc1
T NewPlace

or
L NewData
T D [AR1,P#0.0]

This is not tested code, just threw this down to get the idea across.
Could need a few tweaks.
 
As you will have to determine what the variable type is (bool, int,real etc.) then why not use an ANY pointer?
 
My idea was to have UDT : DT_DISCRET_SIGNAL:
signalName : BOOL;
signalNegative : BOOL;
signalAddress : UDT_POINTER;
signalValue : BOOL;


UDT_POINTER:
address_P1 : DWORD; ( this would contain mem. area, byte address and bit address. )

address_P2 : WORD; ( this would contain DB number)



On this way USer would specify on HMI every DI/DO address, USER has to assign to the signal its address.
I can use ANY pointer but that would increase my final DataBlock.
 
As you will have to determine what the variable type is (bool, int,real etc.) then why not use an ANY pointer?


Was thinking a little bit of this what you have said.


For DI,DO, AI and AO I don't need ANY POINTER since data types are already known for me, bools and INTs. They are fixed. USer on HMI will not choice data type of the variable, he will choice its value only by choosing address of DI,DO, AI, AO. So user structures POINTER and on that way he chooses value for my variable. This code does that. A little bit different since here I assign value from variable inside DB not from DI,DO,AI or AO, but it should very similar.


Code:
 L     #DI_S.Address_P1       

T     #tmpAddress       

L     #DI_S.Address_P2       

T     #tmpDBNum       

OPN   DB [#tmpDBNum]       

A     DBX [#tmpAddress]       

=     #DI_S.Val
Code:
DI_S:UDT looks like this
 EN : BOOL; 

Val : BOOL; 

Address_P1 : DWORD; 

Address_P2 : WORD;
Even though JesperMP hates how does it looks like (I have to say I hate this topic name)

But I absolutely hate the way you are building addresses in code
It does what I need it for, I don't know what is ****ty there but it assigns value to the variable from location where POINTER actually points.


Dahnuguy gave me a couple of examples how to reduce "work under the hub"
There is no need for an actual pointer. You would just be building it , storing it, then reading it and deconstructing it anyway, so what's the point?
Now I need something else and it is related with this what L D[AR2,P#0.0] said.



This before works for lets say normal data types.
Let's say I have 5 variables MOTOR1,MOTOR2,MOTOR3,MOTOR4,MOTOR5, of data type FB_MOTOR.
Values of these variables (MOTOR1,MOTOR2,MOTOR3,MOTOR4,MOTOR5)
are stored in DB10("MOTORS_DATA" symbolic name) for an example. (Motor_Data1,Motor_Data2,Motor_Data3,Motor_Data4,Motor_Data5). Every single variable "Motor_DataX" is variable of data type DT_MOTOR, also every single variable "Motor_DataX" has got different values from other since Motors are not the same let's say( I wanna say that values inside Motor_Data1 and Motor_Data3 re not the same for an example). Since it is not possible to create inside DB variable of data type FB_MOTOR, FB_MOTOR contains IN_OUT variable of data type DT_MOTOR.

It is not necessary that Motor_Data1 corresponds to the MOTOR1 (MOTOR1 : FB_MOTOR), let it be chosen on HMI, maybe Motor_Data3 is better option.


My question is whether is ANY_POINTER answer for this question?
How to make USER on HMI to choice appropriate "Motor_DataX" for any of these variables (MOTOR1,MOTOR2,MOTOR3,MOTOR4,MOTOR5).
How user can for an example assign values from "Motor_Data3" to the MOTOR1 FB_MOTOR IN_OUT variable?


I'm not asking you guys to give me code for this, just tell me is this possible via ANY_POINTER. I will try to struggle about it and its applications, maybe later you can assist if it is necessary.


I keep reading this bit it has less and less sence, something is missing and idk what
 
Last edited:
As you will have to determine what the variable type is (bool, int,real etc.) then why not use an ANY pointer?

could use any, but pointer is less to deal with.

Any is better for area crossing of course.

Doesn't matter much either way.
 
Was thinking a little bit of this what you have said.


For DI,DO, AI and AO I don't need ANY POINTER since data types are already known for me, bools and INTs. They are fixed. USer on HMI will not choice data type of the variable, he will choice its value only by choosing address of DI,DO, AI, AO. So user structures POINTER and on that way he chooses value for my variable. This code does that. A little bit different since here I assign value from variable inside DB not from DI,DO,AI or AO, but it should very similar.


Code:
 L     #DI_S.Address_P1       

T     #tmpAddress       

L     #DI_S.Address_P2       

T     #tmpDBNum       

OPN   DB [#tmpDBNum]       

A     DBX [#tmpAddress]       

=     #DI_S.Val
Code:
DI_S:UDT looks like this
 EN : BOOL; 

Val : BOOL; 

Address_P1 : DWORD; 

Address_P2 : WORD;
Even though JesperMP hates how does it looks like (I have to say I hate this topic name)

It does what I need it for, I don't know what is ****ty there but it assigns value to the variable from location where POINTER actually points.


Dahnuguy gave me a couple of examples how to reduce "work under the hub"
Now I need something else and it is related with this what L D[AR2,P#0.0] said.



This before works for lets say normal data types.
Let's say I have 5 variables MOTOR1,MOTOR2,MOTOR3,MOTOR4,MOTOR5, of data type FB_MOTOR.
Values of these variables (MOTOR1,MOTOR2,MOTOR3,MOTOR4,MOTOR5)
are stored in DB10("MOTORS_DATA" symbolic name) for an example. (Motor_Data1,Motor_Data2,Motor_Data3,Motor_Data4,Motor_Data5). Every single variable "Motor_DataX" is variable of data type DT_MOTOR, also every single variable "Motor_DataX" has got different values from other since Motors are not the same let's say( I wanna say that values inside Motor_Data1 and Motor_Data3 re not the same for an example). Since it is not possible to create inside DB variable of data type FB_MOTOR, FB_MOTOR contains IN_OUT variable of data type DT_MOTOR.

It is not necessary that Motor_Data1 corresponds to the MOTOR1 (MOTOR1 : FB_MOTOR), let it be chosen on HMI, maybe Motor_Data3 is better option.


My question is whether is ANY_POINTER answer for this question?
How to make USER on HMI to choice appropriate "Motor_DataX" for any of these variables (MOTOR1,MOTOR2,MOTOR3,MOTOR4,MOTOR5).
How user can for an example assign values from "Motor_Data3" to the MOTOR1 FB_MOTOR IN_OUT variable?


I'm not asking you guys to give me code for this, just tell me is this possible via ANY_POINTER. I will try to struggle about it and its applications, maybe later you can assist if it is necessary.


I keep reading this bit it has less and less sence, something is missing and idk what

I already gave you pretty close to the actual code to use.
You are all making this way more complicated than it needs to be.

Any Pointer will not help you and only make it more complex and confuse you.

If the data is in an array of udt you can just use the array element as the whole pointer.

Motor[variable]

You could even switch it while it is running.
 
I already gave you pretty close to the actual code to use.
You are all making this way more complicated than it needs to be.

Any Pointer will not help you and only make it more complex and confuse you.

If the data is in an array of udt you can just use the array element as the whole pointer.

Motor[variable]

You could even switch it while it is running.
I fully agree with you.
My goal is like this. User on HMI specify/assign certain AI to some variable from drop down list. Once he has choose variable, he needs to configure FB_AI. HMI screen expands and then USER needs to specify/assign Motor[variable] to FB_AI. Once user has selected(Motor[0] or Motor[1] or...Motor[x]) from drop down list, HMI screen expands one more time with all the data inside selected (Motor[0] or Motor[1] or...Motor[x]) variable.

Yes (Motor[0] or Motor[1] or...Motor[x]) will be array of UDT


just to clarify Motor[x] is IN_OUT variable to FB_AI. Once all this has been done I can consider AI as fully configured.


So basically there are 3 steps.
1. Assign AI (PIW100 to a certain variable let's say MotorAIValue)
2. Assign FB_AI (Motor[variable] to a certain FB_AI)
3. Fill/check all components of Motor[variable] UDT


If I place MotorAIValue inside Motor[variable] UDT, maybe I can skip steps 2. and 3.

I mean once USER has done 1. Assign AI (PIW100 to a certain variable let's say MotorAIValue),
HMI can display immediately steps 2. and 3.
 
Last edited:

Similar Topics

Is it possible to make I/O filed on HMI of POINTER data type? Pointer data type can be either temp, IN or IN_OUT variable inside FB. it would be...
Replies
1
Views
1,774
Hi all, Can anyone tell me if the POINTER data type is available in TIA for S7-1200 and what the format looks like? It's not listed under Data...
Replies
2
Views
4,124
HI All, I am trying to set up a FB to pass details to to get Simocode data records 92, 94 amd 95. I have 30 motors to read. I can get it to...
Replies
8
Views
4,189
I need to send a pointer to an array to a function. The SCL manual gives that example: FUNCTION FC100 : VOID VAR_IN_OUT N_out : INT...
Replies
0
Views
4,916
Hi All, in many library function of TiaPortal some data must be write using the pointer format........ eg.: P#DB90.DBX0.0 WORD 10 is it...
Replies
5
Views
2,818
Back
Top Bottom