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

naturephoenix

Member
Join Date
Jan 2015
Location
Vienn
Posts
181
http://www.plccenter.cn/Siemens_Step7/Format_des_Parametertyps_POINTER.htm


Since I can not declare inside DB or UDT POINTER data type,
I made custom:


Address_P1 : DWORD;
Address_P2 : WORD;
These two variables combined should represent POINTER TAG.


Now I want to separate Address_P1 : DWORD to 3 variables
so they can be easily entered via HMI.


1. variable is Memory area and its size is 8 bits so

MemoryArea : Byte;
2. variable is Byte address and its size is 16 bits so

ByteAddress : WORD;
3. variable is bit address and its size is 3 bits...maybe i can make an array of 3 bools.
BitAddress : array [0..2] of bool;


How can I combine and separate these 3 variables to make possible something like this:
Address_P1 := MemoryArea + ByteAddress + BitAddress;
MemoryArea:= Address_P1+...;
ByteAddress:= Address_P1+...;
BitAddress := Address_P1+...;
 
What is it that you want to achieve ?

I dont like what looks as is you want to make some kind of indirection by manipulating absolute addresses.
If it is just for taking the bitpattern of one or variable and look at it as one or more different variables, then I would use an AT view. That is what AT view is for. You take the same data at the same address, and looks at it different ways.
Say you have a DWORD, and you want to split it into 2 BYTES and an INT, then that is what you do with AT.
 
What is it that you want to achieve ?

I dont like what looks as is you want to make some kind of indirection by manipulating absolute addresses.
If it is just for taking the bitpattern of one or variable and look at it as one or more different variables, then I would use an AT view. That is what AT view is for. You take the same data at the same address, and looks at it different ways.
Say you have a DWORD, and you want to split it into 2 BYTES and an INT, then that is what you do with AT.


This is what I'm trying:


Code:
L     #DI_S.Address_P1
      T     #tmpAddress
      L     #DI_S.Address_P2
      T     #tmpDBNum
      OPN   DB [#tmpDBNum]
      A     DBX [#tmpAddress]
      =     #DI_S.Val
DI_S is UDT type

Code:
EN : BOOL;
Val : BOOL;
Address_P1 : DWORD;
Address_P2 : WORD;
Address_P1 and Address_P2 configures 1 variable of POINTER DATA TYPE. Means user needs to enter address from HMI to the Address_P1 and to the Address_P2.
IS there a way to enter directly as a POINTER TAG.


I want to read Value of the TAG which address is inside Data Block and its address has been entered from user via HMI.


I test this code and it works, but it kills me that I need to read/writte POINTER value(Address_P1+ Address_P2) from HMI separatelly
 
Last edited:
I dont know what you want to achieve (I dont mean what code you have made so far, that is not what is meant by "achieve"). So I have no idea if there is a better way.
But I absolutely hate the way you are building addresses in code (pointers as you call them), that be in the PLC or in the HMI.
In the other thread that you have started, and which seems to have to do with the same topic, I have answered that you can define indirection on the HMI side if you so wish.
 
I dont know what you want to achieve (I dont mean what code you have made so far, that is not what is meant by "achieve"). So I have no idea if there is a better way.
But I absolutely hate the way you are building addresses in code (pointers as you call them), that be in the PLC or in the HMI.
In the other thread that you have started, and which seems to have to do with the same topic, I have answered that you can define indirection on the HMI side if you so wish.


I want to read Value of the TAG which address is inside Data Block and its address has been entered from user via HMI.


So for example:

YOu have variable DB1.DBX0.0 with simbolic name GateClosed type bool.


Value of this variable has to be specified by the POINTER value and it has to be specified by USER.
So if POINTER points to the DB10.DBX20.0 , i want
DB1.DBX0.0 := DB10.DBX20.0;


DB10.DBX20.0 -> This has to be entered by USER on HMI
 
I have answered that in the other thread.

I am curious..
What happens if a user inputs an address that does not exist ?
Or, what happens if a user inputs an address that exist but is for a completely different function ?

You still have not answered what you want to achieve.
What you describe is some ideas about code. Let me ask in another way, what is the code supposed to achieve ?
 
I have answered that in the other thread.

I am curious..
What happens if a user inputs an address that does not exist ?
Or, what happens if a user inputs an address that exist but is for a completely different function ?

You still have not answered what you want to achieve.
What you describe is some ideas about code. Let me ask in another way, what is the code supposed to achieve ?

Purpose of the code is that user link specific DI, AI, AO, DO to a certain variable, no matter what does the wire says. Purpose is that electrical engineers are capable to check DI, DO, AI, AO via HMi without Tia or Simatic. There many other useful things as well for control but I think this is more than enough.

User will have listed options of addresses what to choose, linked with circuit diagrams, and it won't be possible to use non existing addresses, even if it is there are OBs which prevents CPU going to stop. Ofc option will be protected and allowed just to specific users.
Purpose is to configure control system program via HMi as much as possible.
In correct system all significant stuffs are protected by hard wire or accessory device with specific function. Not much of protection that depends on CPU, at least in hydropower plants
 
Purpose is that electrical engineers are capable to check DI, DO, AI, AO via HMi without Tia or Simatic.


If you have Siemens HMI you have the already built in "Watch table" that does exactly that without any coding in the PLC. But perhaps you have another HMI?
 
If you have Siemens HMI you have the already built in "Watch table" that does exactly that without any coding in the PLC. But perhaps you have another HMI?

No it is Siemens HMI, TP1200,
Good, I didn't know about that feature.
What does that watchable do exactly, you means it is possible to assign variable to different AI for an example?
 
As far as I understand: You want to be able to specify "any" I/O address to display, and only by code in the HMI. So the operator must type in the address to display. Sounds very cumbersome to me, if there are many addresses to display. I think the operator will get tired of that real fast.
Why not just display all the available addresses ?

Anyway, you can setup a BOOL tag with absolute addressing to point to an address by indirection.
For inputs: %I["byte_address"].["bit_address"].
byte_address and bit_address being INT tags.

For analog signals you are out of luck. It only works with I/O that is part of the process image. Analog signals are (usually) outside the process image.
 
Regarding the Watch table, then you can also setup a Watch table in the PLC, and use the PLC webserver to display it.
I think this is the better solution. If you create a Watch table in the PLC you will get both the physical address and the symbolic name. The symbolic name being much more meaningful to an operator (if the symbol is defined in a good way). I always make symbols for I/O exactly as the connected device is called in the schematics (i.e. "=C2+CC1-T1").
If you make a watch table in the HMI, you will get the name and addresses as they are defined by the HMI tag list. Could be the same as the PLC symbols, but all I/O has to be setup as HMI tags, even if they are not used elsewhere in the HMI program.

edit: Maybe Bratt means that the HMI can display a watch table setup in the PLC ?
I dont have experience with that.
If that is the case I would like to hear about it.
 
Last edited:
Regarding the Watch table, then you can also setup a Watch table in the PLC, and use the PLC webserver to display it.
I think this is the better solution. If you create a Watch table in the PLC you will get both the physical address and the symbolic name. The symbolic name being much more meaningful to an operator (if the symbol is defined in a good way). I always make symbols for I/O exactly as the connected device is called in the schematics (i.e. "=C2+CC1-T1").
If you make a watch table in the HMI, you will get the name and addresses as they are defined by the HMI tag list. Could be the same as the PLC symbols, but all I/O has to be setup as HMI tags, even if they are not used elsewhere in the HMI program.


Inside symbol table I do have something like this:
simbol-------address--data type

AI_INPUT_1 - PIW100 : INT

AI_INPUT_2 - PIW102 : INT


In program I got already prepared FB_GEN_TEMPERATURE
One of the inputs to the FB is INT type (AI_INPUT_1 or AI_INPUT_2...)


Now I want that Input to my FB is my new variable, lets say
GEN_TEMP( DB500.DBW0)


Inside code I want to make Value of GEN_TEMP is value of AI_INPUT_1 or AI_INPUT_2. USER will choice on HMI
GEN_TEMP := value of address where POINTER points (can be AI_INPUT_1 or AI_INPUT_2)


Is this possible?
 
OK, so this is a new requirement. That the analog I/O of the PLC program must be configured from the HMI.

Look into PEEK and PEEK_WORD to load a hardware address
#InputWord := PEEK_WORD(area:=16#1,dbNumber:=0,byteOffset:=#Byte_address);

area = 16#1 specifies it must be peripherial inputs.
#Byte_address would be the input from your HMI.

About the Watch tables in PLC and HMI:
The Watch table in the PLC and accessed via the Webserver is predefined by the programmer. The watch table will display both the symbol and the hardware address.
The Watch table in the HMI is a dialog that allows you to specify any address to be displayed (not sure if that includes :p addresses outside the process image).
So it is two different things. I would go for the PLC Watch table.
 
OK, so this is a new requirement. That the analog I/O of the PLC program must be configured from the HMI.

Look into PEEK and PEEK_WORD to load a hardware address
#InputWord := PEEK_WORD(area:=16#1,dbNumber:=0,byteOffset:=#Byte_address);

area = 16#1 specifies it must be peripherial inputs.
#Byte_address would be the input from your HMI.

About the Watch tables in PLC and HMI:
The Watch table in the PLC and accessed via the Webserver is predefined by the programmer. The watch table will display both the symbol and the hardware address.
The Watch table in the HMI is a dialog that allows you to specify any address to be displayed (not sure if that includes :p addresses outside the process image).
So it is two different things. I would go for the PLC Watch table.

My final idea is to complete, configure whole control program via HMI, first step is to properly configure DI, DO, AI, AO. Ofc first, initial setup is done from step 7 or tia, but later when commissioning starts I want non software specialist to be able to modify some things(control logic, di, do, AI, Ao, alarms...) Next step is to make custom defined alarms from HMI inside PLC, with some "smarts" templates
 
Last edited:
I want to read Value of the TAG which address is inside Data Block and its address has been entered from user via HMI.


So for example:

YOu have variable DB1.DBX0.0 with simbolic name GateClosed type bool.


Value of this variable has to be specified by the POINTER value and it has to be specified by USER.
So if POINTER points to the DB10.DBX20.0 , i want
DB1.DBX0.0 := DB10.DBX20.0;


DB10.DBX20.0 -> This has to be entered by USER on HMI

This is what I'm trying:


Code:
L     #DI_S.Address_P1
      T     #tmpAddress
      L     #DI_S.Address_P2
      T     #tmpDBNum
      OPN   DB [#tmpDBNum]
      A     DBX [#tmpAddress]
      =     #DI_S.Val
DI_S is UDT type

Code:
EN : BOOL;
Val : BOOL;
Address_P1 : DWORD;
Address_P2 : WORD;
Address_P1 and Address_P2 configures 1 variable of POINTER DATA TYPE. Means user needs to enter address from HMI to the Address_P1 and to the Address_P2.
IS there a way to enter directly as a POINTER TAG.


I want to read Value of the TAG which address is inside Data Block and its address has been entered from user via HMI.


I test this code and it works, but it kills me that I need to read/writte POINTER value(Address_P1+ Address_P2) from HMI separatelly

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.
 

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,766
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,120
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,913
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,817
Back
Top Bottom