Jump to content

Recommended Posts

Posted

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" (B), 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

Posted

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

post-20108-0-10437400-1408522755_thumb.j

string to num.ulpr

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

 

Joepost-1173-0-26385000-1408546763_thumb.png

  • 3 weeks later...
Posted

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?

Posted

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.

Posted

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.

 

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

  • Like 1
Posted

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
Posted

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.

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.