Sign in to follow this  
Followers 0
DennisP

FactoryTalk View DINT to ASCII conversion

15 posts in this topic

Would someone please help me how to convert an integer to ascii?   For example if the output tag is an ascii string, of 3 characters and my numeric input is integer.   When user input a value of 5, I would like the input value to be convert and assign to output ascii string tag of "005".  How do I set the conversion format in either tag assignment or tag expression?

Edited by DennisP

Share this post


Link to post
Share on other sites

When you converted the DINT with value 5 to the ACSII string tag, what did the ACSII string tag read?

Share this post


Link to post
Share on other sites

ASCII tag reads as "5", I would like to format it to be 005, or if numeric input is 15, I would like ascii string tag to read as "015"

Share this post


Link to post
Share on other sites

Then you need to examine the string tags length then set up two dummy string tags with "0" and "00" to then concatenate the first result with to a third string that is transmitted out.

 

Or with comparative logic, i.e. DINT LES 9 you could insert "00"

DINT is between 10 and 99 then insert "0"

Greater than 99 don't insert anything.

Edited by pcmccartney1

Share this post


Link to post
Share on other sites

I have tried as an expression but it doesn't seem to work.

if dInput < 10 then sOutputTag = "00" + dInput
else if dInput < 100 then sOutputTag = "0" + dInput
else sOutputTag = dInput

Share this post


Link to post
Share on other sites

The reason you expression doesn't work is due to a mixing of data types.

Copy and paste the following into empty rungs:

DTOS Value StringInit 

BST LES Value 100 BST LES Value 10 CONCAT String00 StringInit StringOut NXB LIM 9 Value 100 CONCAT String0 StringInit StringOut BND NXB GEQ Value 100 COP StringInit StringOut 1 BND 

Share this post


Link to post
Share on other sites

Thanks.  Your logic would work if applies to an AB PLC rung.   However I am trying to apply the logic to AB FactoryTalk View Studio for AB PanelView Plus display.     I figure there is something wrong with my logic when assigning DINT to String.  However I am not sure how to do in an FT View expression

Share this post


Link to post
Share on other sites

Let me amend that statement, there is no equivalent to a DTOS (DINT to String) in the PV+.  You really are better off doing the logic in the PLC.

 

Edited by pcmccartney1

Share this post


Link to post
Share on other sites

Sorry for being a beginner but where do I get the expression builder to access and convert PV+ database tag?

Share this post


Link to post
Share on other sites

To my knowledge, there is no means to convert a DINT to a string in the expression builder.

Maybe someone else here knows a way to do that.

Still think you are better off doing it in the PLC.

 

Try this,

Change the object on the screen to a String Input Enable, on the "String" tab, change the number of characters to 3 and then change the Fill to zeros.

Edited by pcmccartney1

Share this post


Link to post
Share on other sites

I did use that approach, unfortunately the string input doesn't support left fill zero, as in numeric input, but it does right fill zero instead.

For example, input string of "1" will get fill with "100" instead.

Share this post


Link to post
Share on other sites

Then I'm out of ideas, hopefully one of the true brainiacs will have an idea for you.

Share this post


Link to post
Share on other sites

Thanks again for coming up with ideas.   I probably will have to implement the conversion/formatting logic in the PLC side in this case.

Share this post


Link to post
Share on other sites

Is it SE or ME?  Is there a PLC involved?  If so, what model?

Share this post


Link to post
Share on other sites

I have to sleep.

 

If you're using SE, you can convert ASCII characters to their decimal equivalent by using the Asc() function in VB, and vice versa using the Chr() function.

If you're using any controller that uses RSL5K (or now Studio 5K) you can use a DTOS instruction to convert a string to a DINT.

Edited by adohm
Clarification on program use

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0