siemens data types not in order

adamplc

Member
Join Date
Dec 2009
Location
usa
Posts
92
I have just noticed after trying to figure out why my data is going into the wrong location that data blocks don't always align in sequential order.
I post a screen shoot of my problem, I have a byte of bools then a int. My byte of bools starts at byte 0, 0.0-0.7 my next data type is a int but starts at 2.0 not 1.0 can anybody explain why this is the case?
If I cannot align the data correctly I will have a pointer nightmareo_O

Thanks for any help

data wrong.jpg
 
I don't work with Siemens but this alignment would be true in Allen Bradley RSLogix 5000, a tag in a structure will align on the next boundary which is equal to its size. To lessen visual confusion add eight padding bits (who knows, you may need to use them later) so that the position of the 16 bit INT seems more obvious.
 
Last edited:
Siemens usually meshes nicely, is it possible you have logic referencing a bit (M1.0-M1.7) and the software estimated you were using MB1 as bools?
 
I have just noticed after trying to figure out why my data is going into the wrong location that data blocks don't always align in sequential order.
I post a screen shoot of my problem, I have a byte of bools then a int. My byte of bools starts at byte 0, 0.0-0.7 my next data type is a int but starts at 2.0 not 1.0 can anybody explain why this is the case?
If I cannot align the data correctly I will have a pointer nightmareo_O

Thanks for any help


Your screen shot shows a word at 2.0, not an int. The next free address for an int/dint after a boolean declaration will always be a multiple of 2 bytes after the start of the declaration and there is no way of changing this.

This appears to be an instance DB. Refer the variables by name in the FB when generating a pointer reference, you should avoid needing to know the absolute address of data as it will more than likely catch you or someone else out in the future.
 
Your screen shot shows a word at 2.0, not an int. The next free address for an int/dint after a boolean declaration will always be a multiple of 2 bytes after the start of the declaration and there is no way of changing this.

This appears to be an instance DB. Refer the variables by name in the FB when generating a pointer reference, you should avoid needing to know the absolute address of data as it will more than likely catch you or someone else out in the future.

I guess I need to explain exactly what I'm trying to achieve.
I have a profinet card that is reading profinet I/O. I use FC11 PNIO_send and FC12 PNIO_recv standard blocks.
I put this received data into the data type that is inside the stat area FB.
My main issue is some data (the result array of chars input)is in the wrong area by 1 byte when I view the data block online. That is why I think that some data is going into the wrong place due to the gaps.
What is the best way to realign the data? I am assuming the pointer is the way to go?
I have attached a library that has the data type, but would really appreciate some help with using a pointer this way.
 
You could put a spare byte in address 0. Then the bools would shift to address 1, and the gap is gone. Update the start address in the data copy/receive function accordingly.

Kalle

That is exactly what I have done but thought there would be a better way.
Thanks for your input.
 
what if you change your 2nd word address to 2 bytes, then structure would be first 8 bits (adresses 0.0-0.7) then byte1 (address 1.0) byte2 (address 2.0).

Then copy these two bytes somewhere else location?

p.s If I understanded it right, you actually have allready your data at addresses at datablock, but because of data structure your variable points to wrong area. Look directly dbx.dbw1, there should be your data also now...


p.s Kalle allready posted this, start with 1 byte...
 
That was my workaround, all the ints I changed to bytes and it works fine but I thought that was the wrong approach.
All the data is there, it was just in the wrong location using ints.
That was when I saw the data block reserves 2 bytes for words, ints etc.
 

Similar Topics

I've got some minimal C code that I wrote some time ago to talk to Siemens PLCs. I used it with a 1200. At the time I only hit I, M, and Q...
Replies
5
Views
1,855
I am trying to compare two values, one comes from modbus via a datablock in the range of 0 - 65535. "Int" in the datablock. This is displayed on a...
Replies
3
Views
3,741
Hello I have a s7-1200 and I would like to read the tags present in this controller with my controllogix controller. The two controllers don't use...
Replies
5
Views
179
Dear Experts, Please, kindly guide me through how to read data from ABB PLC to S7-1200 Siemens PLC. I want to use Siemens S7-1200 PLC to read data...
Replies
1
Views
460
Looking for options to write data to Siemens PLC. Looking for something closest to way we were doing it with AB PLC and excel sheet. Old way...
Replies
7
Views
916
Back
Top Bottom