Read out the value of the first 25 bits of a DINT value S7-1200 Tia portal

smf

Member
Join Date
Jun 2006
Location
Växjö
Posts
71
Hi


I have a value stored within the first 25 bits of a DINT value and i'm wondering how to move/extract those 25 bits to another DINT?


I'm using tia portal 15.1 with s7-1200
 
You need to know some Binary maths and how Siemens represents numbers of different base types, the simplest way to understand is to keep everything in binary format with 0s and 1s. As cardosocea said you create a mask, a mask here is just like a mask in photo editing, it lets some bits through and hides the rest. To create a 25 bit mask you declare a 32 bit double word and give it a value like this in SCL:
Code:
doubleWordVariable := 2#0000_0001_1111_1111_1111_1111_1111_1111;
'AND' that with your original number and only the values where there are 1s in the mask will keep there original values, the rest are set to 0.

http://www.plcdev.com/step_7_elementary_data_types


You could have declared the mask using hexadecimal using
Code:
doubleWordVariable := W#16#*01FFFFFF
cardosocea had his mask in Octal, not sure how you write that in Siemens terminology.
The zeros in my mask aren't needed, they just help me to understand.


Windows calculator has a Programmer setting that allows easy conversion between number Bases. Go to the 3 lines top left and choose 'Programmer'.

 
Last edited:
Great stuff and fast answers, thanks BryanG and cardosocea!


I'm a ladder guy, not used to doing stuff like this at all so i'll give it a try and return here if i fail :)
 
With "first 25 bits", do you mean when reading the bits from the left (starting with the MSB) or do you mean when reading the bits from the right (starting with the LSB) ?




Bits 0 to 24 contains the data i want . So i guess from the right
?
The mask provided from BryanG seems to work so he was spot on.

mask.png
 
Ok, just wanted to be sure.
Because of the arabs, numbers increase from right-to-left.
But when we read some text, it goes from left-to-right.
So "first 25 bits" can be interpreted both ways.
 
You can also do same on ladder with SHL and SHR commands (Shift left and then back to right 7bits of Dint)
 
Bits 0 to 24 contains the data i want . So i guess from the right
?
The mask provided from BryanG seems to work so he was spot on.


Since you mentioned being a LAD guy above, there is an AND instruction in LAD as well, under Basic Instructions -> Word Logic Operations.
 

Similar Topics

Hi, I allways used libnodave, but now trying snap7. However this code doesn't work: int intValue = 0; int Area = 0x84...
Replies
6
Views
2,606
Hello friends; I found a code for VBA use in excel to read the Tags values from RSlogix 5000 through RSlink. The code is here: Dim OPCServer1 As...
Replies
9
Views
3,849
Goodmorning Everyone, I was wondering if anyone knew how to read an integer value from the plc on the hmi. Im using RS micrologix and Advanced...
Replies
4
Views
1,595
Hello, I'm having a problem with configration and programming of modbus in SoMachine. My project contains HMISCU8B5 (HMI with PLC) and I've...
Replies
4
Views
5,325
Back
Top Bottom