Sign in to follow this  
Followers 0
RickyQ

PARSING ASCII STRINGS INTO UINTS, WORDS, FLOATS

11 posts in this topic

Guys, I've been playing around with some instructions and have come to a minor road block, i need some help here... I'm receiving an ASCII String via TCP to a CJ2, for the purposes of this discussion lets say the string looks like this: "@IdNum1234" I'm using MOVD to organize the "1234" into a couple of words. How would you guys go about turning the "1234" in ASCII to a UNIT value? any help would be greatly appreciated!

Share this post


Link to post
Share on other sites
Use the HEX (or NUM4, I think) code to convert 1234 ASCI to 1234 Hex. Then use the BIN command to convert the 1234 Hex (which is a BCD number actually) to a binary number (decimal).

Share this post


Link to post
Share on other sites
Perfect, i knew i was missing something that was staring right at me. It's HEX to make 4 nibbles or (omron digits): 1234 Then BIN to make BCD to UINT. Now i have to get to the strings that look like this : "1234.12" THANK YOU!

Share this post


Link to post
Share on other sites
How would you go about the sign? eg: +1234 Vs -1234 i found the BISL instruction to do signed BCD but im wondering if theres a better way to go about it... Edited by RickyQ

Share this post


Link to post
Share on other sites
Is the sign going to be in the same place each time? If so, compare that part of the address to the hex code for minus. If the hex code for minus is there, multiply the conversion by -1 using a multiply instruction.

Share this post


Link to post
Share on other sites
Hi FLTL converts directly from ASCII to REAL. Works for scientific notation, too. Pp

Share this post


Link to post
Share on other sites
Thank you all for your help!

Share this post


Link to post
Share on other sites
I think Pp might be referring to FVAL not FLTL. Used it on a recent project, works a treat.

Share this post


Link to post
Share on other sites
Hey guys, i have all the conversion working and am now diving into how fast i can process all of this stuff... i have what may be a silly question but i want to make sure: Let's say for arguments sake that the PLC is set to run at 30ms, and i am using the TCP FB from the library to receive data. If i use the status of the data received flag to trigger the FB to receive the data from the buffer, does that mean that i can only receive data at 30ms?

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
Sign in to follow this  
Followers 0