Help on hex thing ;=)

Coralreef

Member
Join Date
May 2006
Location
Dk
Posts
23
In a Siemens S7-400 i have the following in a DB :

DB1.DBB 127 = 78
DB1.DBB 128 = 80
DB1.DBB 129 = 00
DB1.DBB 130 = 01
DB1.DBB 131 = 27

Ofcause the values change some times when new data arrives(via RS232).

The values are in hex - but the thing is the number i need from the example above IS 7880000127 in real world numbers :D

So how do i get from the hex stuff over, and get them together in one ?
 
try BCD_INT or bcd_DINT

The value are in BCD in think. So you can convert word by word with the instruction BCD_INT

DB1.dbw128 -> BCD_INT -> MW0

DB1.dbw130 -> BCD_INT -> MW2

DB1.dbw132 -> BCD_INT -> MW4 (be carefull, DB1.DBb132 must be 0)



Check that you have the right value in MW0, MW2, MW4. If it's not correct you may have to swap db0 and db1 (same for the other byte) in a temporary word before convert in INTEGER



After you have to do

MD10 = MW0 + MW2 * 1000 + MW4*1000 0000

 
To give a definitive answer, we need a bit more info.

Having said that, 5 Bytes of data is not a normal form for representing a number (other than as ASCII text). The normal formats are Byte, WORD (Integer) and DWORD (double precision Integer or REAL).

You can get an idea of the possibilities if you look at the values in a VAT. Normal convention is to start WORDS and DWORDS on an even boundary address, so try looking at DB1.DBB128, DB1.DBW128 and DB1.DBD128 and see what shows up. In the latter case you can change the display format from decimal to REAL and see if anything makes sence.

Otherwise, let us know where the data is coming from (and why you reckon the interesting area begins at DBB127), and what you want to do with it.
 
What sort of real world numbers do you require ?

If you want an integer then the biggest signed integer you can store in a double is word is 2147483647

If you want a floating point number then you will lose some precision.

What processing are you going to do with the resultant numbers ?
 
Last edited:
Cta said:
The value are in BCD in think. So you can convert word by word with the instruction BCD_INT

DB1.dbw128 -> BCD_INT -> MW0

DB1.dbw130 -> BCD_INT -> MW2

DB1.dbw132 -> BCD_INT -> MW4 (be carefull, DB1.DBb132 must be 0)



Check that you have the right value in MW0, MW2, MW4. If it's not correct you may have to swap db0 and db1 (same for the other byte) in a temporary word before convert in INTEGER



After you have to do

MD10 = MW0 + MW2 * 1000 + MW4*1000 0000

That did the trick - thanks all !
 
Dont know what you mean ??

I found out that i only needed the first XXXX and the last XXXXX(1-99.999), so this is what i did and it works great :

OPN #Send_DB // Open data DB


L DBB 127 // Load the first data byte
BTD // Convert from BCD to double int
L L#10000000 // Move into place
*D
T #Tmp_DINT


L DBB 128 // Load the second data byte
BTD // Convert from BCD to double int
L L#100000 // Move into place
*D
L #Tmp_DINT
+D
T #Tmp_DINT


L DBB 129 // Load the theird data byte
BTD // Convert from BCD to double int
L L#1000 // Move into place
*D
L #Tmp_DINT
+D


L 10 // Move out X to get ID from 1-99999
/D
T #Tmp_DINT


L DBB 130 // Load the fourth data byte
BTD // Convert from BCD to double int
L L#10 // Move into place
*D
L #Tmp_DINT
+D
T #Tmp_DINT


L #Tmp_DINT
L 10 // Move back for last byte
*D
T #Tmp_DINT
L DBB 131 // Load the fifth data byte
BTD // Convert from BCD to double int
L #Tmp_DINT
+D
T #ID_No // Output ID number
 
SimonGoldsworthy said:
Your posted code produces the number 788000127 - hence my confusion.

Ahh okay - well that changes all the time ;)

Its a code comming from a tag read by an RS232 ID reader !!
 

Similar Topics

New Forum member Lima0411 recently posted this question to an old thread that had evolved to a discussion of New Zealand rugby, so to start off on...
Replies
3
Views
3,251
Good Evening Gentlemen, I am reading in a string into a ST9 file. The string has variable HEX charachters. I am extracting the four digits to...
Replies
11
Views
3,565
Converted a program from a Plc-2/17 to a Mitshubushi Q01 program works and runs machine great except for 1 thing. I have a sequencer with no...
Replies
7
Views
5,092
G
Now I have project for Test in my university, I want to convert Lader Code to Hex Code Ex.. LD ====> 0XXX How to convert sulution if...
Replies
5
Views
7,391
I'm fairly new to Rockwell software, I've had some basic training in the past but nothing too advanced. My company and I use Reliable products for...
Replies
9
Views
149
Back
Top Bottom