Jump to content
YINGD

ASCII String Conversion to number

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...