YINGD Posted August 19, 2014 Report Posted August 19, 2014 I need to convert a number that is expressed as an ASCII String to a UINT32 value. The only FB I can find that appears to be intended for this purpose is the STRING to NUM function but I cannot find any examples or references to this block in the Help File. The FB appears to be looking for the ASCII Operand (A) and then outputs the "Resulting Number" (, and the "Factor" ©. I take it that B is where the Integer Value should output and I cannot figure out what C is other than possibly a multiplication factor? When I upload my program to the PLC and go online, My ASCII String Value (A) shows up fine but the FB will not output anything other than a "1" for the value and a "0" as the "Factor". I tried to override the output values to be sure they were actually being written to and I cannot change them. Can anybody give me some direction on this? A simple example file would be ideal. Joe
EduMarg Posted August 20, 2014 Report Posted August 20, 2014 Hi Y.Inds. Factor is use in case the ASCII number has a decimal point. the value in B can be integers So the number in factor will let you know if there is a decimal point and were should it go. Please se attahced example where a ASCII number with a decimal point is use string to num.ulpr
YINGD Posted August 20, 2014 Author Report Posted August 20, 2014 EduMarg, Attached is a picture of my screen for reference to what I am seeing. As you will notice, my string is not converting to a number as described in your example. Is there something I am missing? I am pulling out a section of the string that indicates the weight value I want to read. I tried to shift the string source and length to remove the spaces and that did not seem to help either. Joe
YINGD Posted September 7, 2014 Author Report Posted September 7, 2014 I am still having an issue converting an ASCII string to a Number. I am reading a weight signal and the range can be -2500 to +2500. The issue appears to be the leading zeros. The string I am reading replaces leading zeros with spaces so unless I set my source index and length to the exact number of spaces I am using while excluding the spaces, the conversion does not convert. Can somebody tell me how to handle leading spaces?
YINGD Posted September 8, 2014 Author Report Posted September 8, 2014 To add to my previous post, when I have the range set to read a three digit value like 123, all is good but when the weight value changes to a two digit value like _23 it will not convert the string to a numerical value.
Eyal Koren Posted September 8, 2014 Report Posted September 8, 2014 EduMarg, Attached is a picture of my screen for reference to what I am seeing. As you will notice, my string is not converting to a number as described in your example. Is there something I am missing? I am pulling out a section of the string that indicates the weight value I want to read. I tried to shift the string source and length to remove the spaces and that did not seem to help either. JoeCapture.PNG Hell Y.INDS. It does seem that when leading spaces are present in the string, the function will not convert (unlike leading zeros). Try to remove the leading spaces first. 1
YINGD Posted September 10, 2014 Author Report Posted September 10, 2014 I checked Mettler Toledo, who is the manufacturer of the IND131 Weigh Scale Reader and they have informed me that there is no way to change the leading spaces to leading zeros. They have said that their scale terminals have had this standard feature for the last 20 years and it has worked that way so I would imagine there is a way to get around this in Unistream (or there should be). Does anyone know how to handle this?
MVP 2023 Joe Tauser Posted September 12, 2014 MVP 2023 Report Posted September 12, 2014 You're going to have to do some more coding to search the returned string for spaces (20h) and replace them with zeros yourself (30h). A PITA, I know, but sometimes you just have to grab the bull by the horns. Joe T.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now