Jump to content

ASCII String Conversion to number


YINGD

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

Link to comment
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

Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
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.

  • Like 1
Link to comment
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?

Link to comment
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...