You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
Thread Tools Display Modes
Unread October 9th, 2019, 09:58 AM   #1
wirelessliquid
Member
United Kingdom

wirelessliquid is offline
 
Join Date: Oct 2019
Location: UK - portsmouth
Posts: 2
Tech Allen Bradley SLC500 - STRING to INT

HI, My first post on here,

Using SLC500 I have a STRING LEN 30 that I need to convert just the first 2 characters (POS 0 , 1) into an INT. any help? I'm under the impression there is no function block for this.

I'm very unfamiliar with SLC500 and have only been programming for 4 months in Logix5000.

Thanks,
Tommy
  Reply With Quote
Unread October 9th, 2019, 10:58 AM   #2
Ken Roach
Lifetime Supporting Member + Moderator
United States

Ken Roach is offline
 
Ken Roach's Avatar
 
Join Date: Apr 2002
Location: Seattle, WA
Posts: 14,893
Welcome to the PLCTalk forum community !

The SLC-500 instruction set includes an String to Integer instruction, "ACI".

It will act on all the numeric characters in the string, starting at the beginning and continuing until the end or when it encounters a character other than "0"-"9".

A string that contained "123ABC456" would result in an integer = 123.

It's actually more work to parse out just the first two characters of that original string, if the string contains more numeric digits after the first two.
  Reply With Quote
Unread October 9th, 2019, 11:33 AM   #3
parky
Member
United Kingdom

parky is offline
 
Join Date: Oct 2004
Location: Midlands
Posts: 1,244
not too familiar with SLC as stopped using it many moons ago but Assume that the string is in an array of registers i.e. 32,33,34, 31 (int. 2341)
then take word containing the two chars you want, AND the word with Hex F or Dec 15 this will give you the lower decimal value of 1 (units), then swap bytes in the word using SWP instruction AND this with Hex F this will give you the tens value (4)
multiply this by 10 then add to the units word.
instructions Move reg containing the two Chars into N7:0
AND N7:0 H0F N7:1 (units store)
SWP N7:0 Len 1 (Swap bytes)
AND N7:0 H0F N7:2 (tens store)
MUL N7:2 10 Dest N7:3 (multiply to get tens value)
ADD N7:2 N7:1 Dest. N7:3 (add units & tens and store in N7:3
N7:3 contains 41 the decimal value of the two chars
  Reply With Quote
Unread October 9th, 2019, 12:17 PM   #4
Ken Roach
Lifetime Supporting Member + Moderator
United States

Ken Roach is offline
 
Ken Roach's Avatar
 
Join Date: Apr 2002
Location: Seattle, WA
Posts: 14,893
The ACI instruction does all that masking and moving and multiplying automatically. You just need to have a String that includes the to-be-converted numeric characters.
Attached Images
File Type: png ACI_Example.PNG (38.4 KB, 38 views)

Last edited by Ken Roach; October 9th, 2019 at 12:50 PM.
  Reply With Quote
Unread October 10th, 2019, 02:44 AM   #5
wirelessliquid
Member
United Kingdom

wirelessliquid is offline
 
Join Date: Oct 2019
Location: UK - portsmouth
Posts: 2
Quote:
Originally Posted by Ken Roach View Post
Welcome to the PLCTalk forum community !

The SLC-500 instruction set includes an String to Integer instruction, "ACI".

It will act on all the numeric characters in the string, starting at the beginning and continuing until the end or when it encounters a character other than "0"-"9".

A string that contained "123ABC456" would result in an integer = 123.

It's actually more work to parse out just the first two characters of that original string, if the string contains more numeric digits after the first two.
an example of the STRING I need to turn into INT is "P7AX051" which should translate to INT 20535. If the ACI stops on characters, it would return a null as soon as it got to the first character P?
  Reply With Quote
Unread October 10th, 2019, 03:07 AM   #6
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is offline
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 13,917
What is the logic behind that the string "P7AX051" translates into the integer 20535 ?
In the 1st post you mentioned only the 2 first characters should be converted. That would be "P" and "7". How does that become 20535 ?
__________________
Jesper
See my profile interests for Q&A
  Reply With Quote
Unread October 10th, 2019, 04:04 AM   #7
parky
Member
United Kingdom

parky is offline
 
Join Date: Oct 2004
Location: Midlands
Posts: 1,244
The first two characters as Jesper suggests are not both ascii characters that are decimal values. what is the reasoning behind converting a string that contains alpha & numbers this does not make sense to most people.
If you mean the first characters (right to left i.e. 51) then this would be easy by using ACI on the last word of the array.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Allen Bradley SLC500 with Schneider HMI norman oliver LIVE PLC Questions And Answers 4 January 5th, 2017 05:08 AM
Allen Bradley SLC500 EZtouch beginner plcguy7 LIVE PLC Questions And Answers 11 March 8th, 2012 10:16 AM
allen bradley slc500 abl0076 LIVE PLC Questions And Answers 3 September 8th, 2004 11:37 AM
Profibus SST card and Allen Bradley SLC500 Derick123 LIVE PLC Questions And Answers 8 July 14th, 2004 09:42 AM
Allen Bradley slc500 Shift register help. ScottC LIVE PLC Questions And Answers 8 July 10th, 2003 02:48 AM


All times are GMT -5. The time now is 05:22 PM.


.