Jump to content

HEX to ASCII


Dave

Recommended Posts

I have 6 consecutive INT16 type tags that contain 2 characters each of ASCII characters in HEX format. I would like to convert/concactenate them all to a single ASCII type tag.

Is there a simple way to do this? I couldn't find any conversion instructions and the sample project  I looked at (UniStream_070_Num_To_ASCII) seems to be an incredible amount of code to do a simple conversion.

Link to comment
Share on other sites

Hello Dave

 

Then only way I see in this is to copy the Integer tag values into a buffertag and then copy the

 buffer tag into the string tag.

Let’s say you have a tag called “stringvalue_int” and type is INT16[0..5] and the result must be placed in a string tag called “text”and type is STRING-ASCII length 6

Then you have to create a buffer tag  let’s say “bufmemory” type is BUFFER[0..11]

 

First you do is copy the value from the integer tags into the buffertag by calling six times a “copy tag to buffer” instruction.

 

First tag=offset in buffer 0

Second tag=offset in buffer 2

Third tag=offset in buffer 4

Fourth tag= offset in buffer 6

Fifth tag = offset in buffer 8

Sixth tag = offset in buffer 10

 

Then you can copy the contense of the buffertag into the string tag with instruction “copy buffer to tag”

If the value of a integer is OX3031 then string value will be “10” so if you want it to be 01 then you have to use extra dummy tags for byte swapping and  use these dummy tags in the “copy tag to buffer” instruction.

Kind regards

Henny

 

 

 

 

 

Link to comment
Share on other sites

Thanks Henny.

That's pretty much what I ended up doing. Except I used the same offset(0), and used the insert option instead of overwrite, for the "copy tag to buffer" instructions. I was hoping for a single "convert"instruction where I could specify the source tag, offset & length. The bar code reader(which is what is sending me the HEX data) has a nice feature that allows you to select byte swapping via a simple checkbox, so I didn't need to concern myself with that task.

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...