Drewdin

STRING TO HEX STRING

7 posts in this topic

I am using a 1769-ASCII card to talk to a Mass Flow Controller, the problem is that I need to send it a string of HEX characters. Initially I was sending a sting of '0221AD' and I found that the device was not responding. Then i sent a string of '$02$21$AD' and I got the response i was looking for.

There is one packet of data that i need to calculate so I cant manually add the dollar sign to the string, I have tried everything to add a concatenate $ to a string of AD to get $AD dynamically and I cant find anything that works. To get the hex, i am summing decimal values and them converting it to hex. The issue is that the $ is reserved char. Does anyone have any ideas or suggestions to get me over this hurdle?

Thanks!

Share this post


Link to post
Share on other sites

Try $24 for the ascii code for the dollar sign.

1 person likes this

Share this post


Link to post
Share on other sites

MicroLogix 1500 or CompactLogix controller ?

The RSLogix 500 and Studio 5000 syntax for hex characters is a little different, I think.  RSLogix 500 liked to use old conventions for some control characters.

In the Studio 5000 string browser, a dollar sign is done by doubling, i.e.   $$   means a single dollar sign character.

If you're concatenating or creating strings right in the SINT[x] elements, just use 16#24 to designate ASCII character 24, the dollar sign.

I'd first take a bit of a step back and be sure that the mass flow controller is really looking for hex characters, or if it is looking for ASCII representations of hex characters.

As pure hex, $02$21$AD is three bytes.    But as an ASCII representation of hex characters, it's nine bytes.

Share this post


Link to post
Share on other sites
22 hours ago, Ken Roach said:

MicroLogix 1500 or CompactLogix controller ?

The RSLogix 500 and Studio 5000 syntax for hex characters is a little different, I think.  RSLogix 500 liked to use old conventions for some control characters.

In the Studio 5000 string browser, a dollar sign is done by doubling, i.e.   $$   means a single dollar sign character.

If you're concatenating or creating strings right in the SINT[x] elements, just use 16#24 to designate ASCII character 24, the dollar sign.

I'd first take a bit of a step back and be sure that the mass flow controller is really looking for hex characters, or if it is looking for ASCII representations of hex characters.

As pure hex, $02$21$AD is three bytes.    But as an ASCII representation of hex characters, it's nine bytes.

I am using a Compact Logix L33ER, I tried using the $$ approach but it didn't work, when concatenated it removes it completely. I tried accessing the output channel of the ascii card and putting in the 16#24 but it didn't go through. It might be something I am doing, ill keep looking into that.

As for the complete hex string, I just gave a crappy example of what I needed, that is not my true packet being sent. What I have been dong is concatenating my string and then moving it to the ASCII cards output. The strings I have already have the $A9, etc... The problem is when I am calculating the HEX and then I need to move it into the string  with the dollar sign. The tricky part is that is is a Hex string, not hex. that's the curve-ball I cant hit. Thanks

Share this post


Link to post
Share on other sites

I was trying to set the individual bit using a MOV, COP and a CPS, but every time I try to move a 16#24 into stringbyte[5]. When i look at the stringbyte[5] = #, stringbyte[6] = 2, stringbyte[7] = 4. Any suggestions?

Thanks

Share this post


Link to post
Share on other sites
On 12/15/2016 at 1:23 PM, Ken Roach said:

...

As pure hex, $02$21$AD is three bytes.    But as an ASCII representation of hex characters, it's nine bytes.

Are you trying to send a 3 character string?  Where Str[0]=char(16#02), Str[1] = char(16#21), and Str[2] = char(16#AD), and Str[3] = char(D) ? If this is the case trying to build a string with a '$' is different than the characters represented by the hex values.  This is shown below.  I have an EQU instruction to display the current string value that was built using individual ASCII Char values.

Can you post a description of the mass flow meter's communication protocol to assist with what it might be expecting?

 

Ascii codes.JPG

Share this post


Link to post
Share on other sites

Thanks for the reply, a co-worker helped me get it working. Since my data was in form:

MassFlow.DATA[0] = $EF

MassFlow.DATA[1] = $01

MassFlow.DATA[2] = $D9

etc...

I ended up using a BTD command to distribute the bits from the MassFlow.DATA[0], etc... to a DINT and then back from a DINT to a string. It worked perfectly

Share this post


Link to post
Share on other sites

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