Posted 17 Nov 2017 Hi, I am receiving the following string from a serial port - +0153.8 +026.81 +0000.6 +0000.9 Air$R . I use 'Mid' instruction to separate the bold digits out of the string. Now I need to convert the separated value to Real format. How should I go about doing it? Thank You Regards Share this post Link to post Share on other sites
Posted 17 Nov 2017 I just discovered this awesome instruction. I tried converting the DWORD to REAL but it did not handle the Minus (-) value properly. Share this post Link to post Share on other sites
Posted 17 Nov 2017 There are commands in the CPU to convert a string to REAL or LREAL. STRING_TO_REAL STRING_TO_LREAL Share this post Link to post Share on other sites
Posted 17 Nov 2017 Just now, Crossbow said: STRING_TO_REAL Wow... much easier! I overlooked the Data Type Conversion menu in the Toolbox. I seem to have this knack for doing things the hard way. Share this post Link to post Share on other sites
Posted 18 Nov 2017 Thank you both of you, I'll try it out. Regards Share this post Link to post Share on other sites
Posted 18 Nov 2017 BTW, how to know the various functions available in the CPU. It doesn't reflect in the toolbox, right? I did look for available instructions in the toolbox Share this post Link to post Share on other sites
Posted 20 Nov 2017 It does. I was looking in the "Conversion" menu. The STRING_TO_REAL is in the "Data Type Conversion" menu. Also, sometimes I'll take a guess at an instruction name and begin typing it. You will get a drop down box with suggestions. Of course, some get overlooked just as I did. No one can be expected to know them all. This is why we browse these forums and share our experiences. Share this post Link to post Share on other sites
Posted 21 Nov 2017 Found a search box right below of the toolbox, - very handy to search for Functions, keyed in String and all the string related functions appeared Share this post Link to post Share on other sites
Posted 27 Nov 2017 All commands are in the toolbox. No exceptions. Share this post Link to post Share on other sites
Posted 3 Apr 2019 I also have this issue. working on Omron's CJ2M. String received can be +4.24737E-03 or +2.17737E+01 Somehow, the structure text function does not have STRING_TO_REAL. Share this post Link to post Share on other sites
Posted 3 Apr 2019 7 hours ago, nicepal said: I also have this issue. working on Omron's CJ2M. String received can be +4.24737E-03 or +2.17737E+01 Somehow, the structure text function does not have STRING_TO_REAL. This is an NJ / Sysmac Studio thread, so the instructions are not the same However, there is a String to Float instruction in the CJ2M, it is FVAL. Share this post Link to post Share on other sites
Posted 5 Apr 2019 Thanks. Just realized this is under NJ after I posted.:) Seems the FVAL is in the Ladder format. Under Structure Text, don't have direct. Anyway, I have work around this by extracting the Integer part to a DINT -> Real, the Decimal part to another DINT -> Real -> Convert into Decimal value. Add them together. Then check if it is E+ or E-, and Multiply or Divide according to the E number. Share this post Link to post Share on other sites