You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old June 23rd, 2022, 04:59 AM   #1
SVJA
Member
Sweden

SVJA is offline
 
Join Date: Jun 2022
Location: Västerås
Posts: 5
Studio5000 Convert HEX to STRING

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 ?

Help appreciated
  Reply With Quote
Old June 23rd, 2022, 05:30 AM   #2
saultgeorge
Lifetime Supporting Member
United States

saultgeorge is offline
 
saultgeorge's Avatar
 
Join Date: Jul 2015
Location: Detroit
Posts: 502
Quote:
Originally Posted by SVJA View Post
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 ?

Help appreciated
Hi I was looking at the instruction help in Studio V. 32 and there are ASCII conversion instructions. Click the drop down and select "Dint to String". You would probably have to convert the hex to a Dint but maybe not. I remember doing some of this converting a hex to decimal in alarm logic for a job I did last summer however I've misplaced the copy of the program. Hope this helps.
__________________
"Instant success teaches one nothing. Failure provides the tools and instructions one needs to succeed."

Last edited by saultgeorge; June 23rd, 2022 at 05:30 AM. Reason: Typo
  Reply With Quote
Old June 23rd, 2022, 05:40 AM   #3
SVJA
Member
Sweden

SVJA is offline
 
Join Date: Jun 2022
Location: Västerås
Posts: 5
Quote:
Originally Posted by saultgeorge View Post
Hi I was looking at the instruction help in Studio V. 32 and there are ASCII conversion instructions. Click the drop down and select "Dint to String". You would probably have to convert the hex to a Dint but maybe not. I remember doing some of this converting a hex to decimal in alarm logic for a job I did last summer however I've misplaced the copy of the program. Hope this helps.
I have tried DTOS instruction and it unfortunatly only returns the decimal value to the string, I have not found a way to force it to report HEX.

Thanks for the reply.
  Reply With Quote
Old June 23rd, 2022, 07:12 AM   #4
SVJA
Member
Sweden

SVJA is offline
 
Join Date: Jun 2022
Location: Västerås
Posts: 5
Quote:
Originally Posted by SVJA View Post
I have tried DTOS instruction and it unfortunatly only returns the decimal value to the string, I have not found a way to force it to report HEX.

Thanks for the reply.
I ended up creating my own AOI for converting a DINT to a HEXSTRING by extracting every 4 bit data value and converting it to a HEX value e.g if the decimal value is 10 from the 4 bits i copy 16#41 which is A in a string and so on.

A dint can contain 8 HEX values so i start from Bit 4-7 for first char then bit 0-3 for second, Bit 12-15 for third, bit 8-11 for fourth and so on.
  Reply With Quote
Old June 23rd, 2022, 04:54 PM   #5
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 5,138
Yup, that is the way to do it!

Maybe you did this, but we can put the sixteen hexadecimal digits into an array of 1-character strings ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"] and CONCAT them one at a time using the 4-bit values as the index as we extract them. So the sequence would be summat like

MOV dint_tag tmp_dint_tag CLR string_tag.LEN 0

AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag


AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag


AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag


AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag


AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag


AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag


AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag


AND tmp_dint_tag 15 tmp_4_dint_tag CONCAT string_array[tmp_4_dint_tag] string_tag string_tag SUB tmp_dint_tag tmp_4_dint_tag tmp_dint_tag DIV tmp_dint_tag 16 tmp_dint_tag



It could be done in a loop but this is just as good.

I suspect OP used an array of SINTs [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70] and MOVed them into each position of the 8-character string, instead of the CONCAT.
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good

Last edited by drbitboy; June 23rd, 2022 at 05:24 PM.
  Reply With Quote
Old June 23rd, 2022, 06:51 PM   #6
ASF
Lifetime Supporting Member
Australia

ASF is offline
 
Join Date: Jun 2012
Location: Australia
Posts: 3,559
This is definitely the sort of task that's best done at the HMI or SCADA level, but failing that, an AOI like you ended up creating would be my fallback plan.
  Reply With Quote
Old June 27th, 2022, 02:36 AM   #7
SVJA
Member
Sweden

SVJA is offline
 
Join Date: Jun 2022
Location: Västerås
Posts: 5
Yes I agree but in this case I don't have a choice.

Thanks for all reply's
  Reply With Quote
Old June 27th, 2022, 02:39 AM   #8
SVJA
Member
Sweden

SVJA is offline
 
Join Date: Jun 2022
Location: Västerås
Posts: 5
Ladder is used everywhere so I have to go there, thanks for taking interest
  Reply With Quote
Old Yesterday, 11:07 PM   #9
5618
Lifetime Supporting Member
United States

5618 is offline
 
5618's Avatar
 
Join Date: Oct 2017
Location: York, PA
Posts: 228
I did something similar to this today and remembered this post. This is based on Rockwell terminology. Adjust as needed.

AND your DINT with 15 to Temp (or other means to get working with the four least significant bits for 0 to F)

LIM 0 - 9 Temp, ADD Temp & 48 to String.Data[0] (ASCII 0 - 9 are 48 - 57)
LIM 10 - 15 Temp, ADD Temp & 55 to String.Data[0] (ASCII A - F are 65 - 70)

Shift your DINT bits right 4 positions with BTD or other method to get the next four bits and repeat for String.Data[1]

Repeat to String.Data[7]
MOV 8 to String.LEN

…or get fancier for varying lengths.

Last edited by 5618; Yesterday at 11:51 PM. Reason: 57, not 58
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Studio5000 V32 String LEN JGax LIVE PLC Questions And Answers 10 April 7th, 2022 11:58 AM
Studio5000 Convert a UDT array to a DINT array timryder LIVE PLC Questions And Answers 5 March 2nd, 2022 11:17 AM
How to read out varying string equations in Studio5000 taylor70 LIVE PLC Questions And Answers 13 October 29th, 2017 03:22 AM
Convert Hex to Binary Kev77 LIVE PLC Questions And Answers 40 April 22nd, 2016 08:14 PM
How To Convert Leader To Hex Code (Please help..) genhits LIVE PLC Questions And Answers 5 July 3rd, 2002 09:00 AM


All times are GMT -4. The time now is 09:58 AM.


.