HEX string value > 2^31 issue.

Latzi

Lifetime Supporting Member
Join Date
Nov 2007
Location
Brisbane
Posts
118
Hi Guys,

I have a problem with reading the following HEX string into a CompactLogix PLC. The HEX string is "D852268A" which if converted to a number using UINT32 - Little Endian (DCBA) gets me the 3629262474 . Which is bigger than the 2^31 = 2147483648 which is what a DINT can take.

Now the issue is that this comes from a vehicle's GPS as the Longitude and I am supposed to multiply this number with 10^-7 then subtract 210 and that will give me the longitude. The latitude works as the number I got from the truck (the four HEX groups) are smaller than 2^31 so I can fit it into a DINT and no issues. But the Longitude and the GPS time both bigger than 2^31.

Not sure if there is something I could do ? I tried the LINT but my f/w doesn't allow Rev 32 or bigger of Logix ,where apparently, there are inbuilt instruction for LINT data types, and also other data types to handle this ? It would be nice if I could do that multiplication on the two integers which I receive before copying them into the DINT or should I try to do this on the HMI? I am running FTViewSE and maybe there is some VBA code able to do this? All I have to do with this is to display it on a screen at this stage.

Anyone came across something like this before?

So once again I receive from the truck 4 HEX groups which are 4 X SINT . The gateway which puts these into the PLC gives the data as two integers . First integer for the example above is -21059 the second is -10315. The two combined (use an online converter like https://www.scadacore.com/tools/programming-calculators/online-hex-converter/ ) give you the 3629262474 value * 10^-7 = 362.9262474 - 210 = 152.9262474 which is the exact latitude.

Thanks for reading this and hopefully someone has an idea
 
Then what? All the CompactLogix can do it copy the LINT to two DINT's which puts me back to square one . LINT operations (apart from COP and something I can't remember now ) are not allowed.

I could perhaps create a FTViewSE tag then convert that LINT into a number by doing an operation on it to get that 3629262474 . Not sure how to convert it but.
 
Maybe you could try this:

a) Shift the word one bit to the right using a BTD instruction (D852268A -> 6C291345)
b) Divide this new value by 5 * 10 ^ 6. If you use a DIV instruction, write 5000000.0 and use a REAL as destination.
c) Subtract 210.

You'd have to prove whether the error introduced in the first step is acceptable or not.
 
Maybe you could try this:

a) Shift the word one bit to the right using a BTD instruction (D852268A -> 6C291345)
b) Divide this new value by 5 * 10 ^ 6. If you use a DIV instruction, write 5000000.0 and use a REAL as destination.
c) Subtract 210.

You'd have to prove whether the error introduced in the first step is acceptable or not.

Hi. Unfortunately I only have access to the two integers which make up that HEX STRING of D852268A but I think I can do that shift . The decimal value of the shifted bytes (6C291345) in decimal is 1,814,631,237 which is smaller than the 2^31 (2,147,483,648‬) so it fits into a DINT . After diving with 5*10^6 I get 362.9262474‬ -210 = 152.9262474 !!! Which is exactly what I need. In fact I am "ahead " of the vehicles GPS in terms or resolution as the vehicle only shows 152.9262 four decimal points.

The only thing I have to work out is where did you get the 5 * 10^6 from?

Thanks I'l try to implement in the PLC and provide feedback if it works :) .
 
Last edited:
You can add the 64-bit math instructions for firmware before v32 by importing them from the "Process Library", which is a free download from the Product Compatibility and Download Center part of the RA website.
 
You can add the 64-bit math instructions for firmware before v32 by importing them from the "Process Library", which is a free download from the Product Compatibility and Download Center part of the RA website.

Oh. That'd be helpful . Do you have a link?
 
The Compatibility and Download Center starts here:

https://compatibility.rockwellautomation.com/Pages/Home.aspx

I used "Process Library" as my search term.

What you're looking for is the "PlantPAX Process Library 4.10", which is (I think) the current version. There's a lot more in there than 64-bit math, but you should be able to find the LINT related instruction in their own folder.
 
Oh. That'd be helpful . Do you have a link?


I can only find PlantPAx_Process_Library_v4.10.00.zip and Studio_Architect_Library_Update_v4.10.00.zip available for download .Not sure how to import them either.
 
The Compatibility and Download Center starts here:

https://compatibility.rockwellautomation.com/Pages/Home.aspx

I used "Process Library" as my search term.

What you're looking for is the "PlantPAX Process Library 4.10", which is (I think) the current version. There's a lot more in there than 64-bit math, but you should be able to find the LINT related instruction in their own folder.

As far as LINT goes math operations are only allowed from V31 (0r V32 ) and above
 
I just did this a few days ago... it's the Process Library you want, not the Architect stuff.

The individual Add-On Instructions will have a *.L5X extension and you'll import them as AOIs in Studio 5000, I think by right-clicking in the AOI part of the controller organizer.

Edit: When I let the download manager put the Process Library into my Windows 10 default Downloads folder, the LINT instructions were in:

C:\Users\kroach\Downloads\RA\PlantPAx_Process_Library_v4.10.00\v4.10.00\Other Add-On Instructions\LINT and LTIME
 
I just did this a few days ago... it's the Process Library you want, not the Architect stuff.

The individual Add-On Instructions will have a *.L5X extension and you'll import them as AOIs in Studio 5000, I think by right-clicking in the AOI part of the controller organizer.

Edit: When I let the download manager put the Process Library into my Windows 10 default Downloads folder, the LINT instructions were in:

C:\Users\kroach\Downloads\RA\PlantPAx_Process_Library_v4.10.00\v4.10.00\Other Add-On Instructions\LINT and LTIME

Yes thank you. I just tried that but still no good when I copy the array of two INT's into the LINT I get a horrendously huge number. So INT[0] = -21059 and INT[1] = -10315 . COP Int_Array[0] LINT 1 Gives me 7836402632443145661 which is not what I expect. I should have 3629262474 as the result :-( . It's doing my head right in
 
Maybe you could try this:

a) Shift the word one bit to the right using a BTD instruction (D852268A -> 6C291345)
b) Divide this new value by 5 * 10 ^ 6. If you use a DIV instruction, write 5000000.0 and use a REAL as destination.
c) Subtract 210.

You'd have to prove whether the error introduced in the first step is acceptable or not.

Oh I understand now. If you shift the bits to the right the LSB is discarded and the MSB gets a 0 instead. This actually divides the original number by two . Given that I had to multiply the number by 10^-7 I know have to multiply 20^-7 which is the same with dividing with 5*10^6 .

Thanks for that works OK but I am not sure how much I lost from the GPS accuracy . I don't have access to the vehicle right now. I decoded the coordinates using this method with values found in the PLC when I saved the program last and that puts the vehicle ~300 m longitude out . Latitude appears accurate enough.

Once again I appreciate you time and help .
 
OK, if your PLC version doesn't support operations with LINT or UDINT you can try this.
- Convert the DINT to LREAL
- If the result is less than zero add 2^32
- Then continue multiplying by 10^-7 and 210 subtract
 
OK, if your PLC version doesn't support operations with LINT or UDINT you can try this.
- Convert the DINT to LREAL
- If the result is less than zero add 2^32
- Then continue multiplying by 10^-7 and 210 subtract

there is no such thing as LREAL . This is a CompactLogix PLC running f/w 24.02. DINT is as high as I can go.
 

Similar Topics

Hi guys. Sorry if I am asking for something solved, but I cant find any useful and easy information for me. I am looking for some solution how to...
Replies
5
Views
6,451
Hi I need to convert a DINT with HEX value e.g A0F15663 to a string with the same value 'A0F15663'. Any tips of good instructions to use ...
Replies
11
Views
3,372
Hello everyone, I'm working in RSLogix 5000. I have an ASCII string of letters & numbers (call it String_3) which I have used INSERT to add a...
Replies
3
Views
2,312
I'm trying to display a Allen Bradley Controller Serial Number that's in HEX to String for my SCADA to display. Any ideas?
Replies
3
Views
2,834
Hello friends I am reading 32 bytes from a display through ML1500 COM1, configured as ascii and storing in ST file What I am reading is...
Replies
8
Views
3,764
Back
Top Bottom