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...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.