Combining individual #'s to single integer

D. Helms

Member
Join Date
Feb 2004
Location
Denton, TX
Posts
2
I have a piece of equipment with a SLC 5/05 that reads a 6 digit barcode through a BASIC module. Each digit of the barcode is stored in a separate integer register, N24:121 thru N24:126 What is the easiest way to combine these numbers into one integer? e.g. if the registers look like this:

N24:121 8
N24:122 3
N24:123 4
N24:124 5
N24:125 6
N24:126 7

What instruction should I use to place '834567' in it's own register?

Thanks.
 
Assuming you can put a number that big into your integer, one way would be multiply and add.
Multiply your numbers by 1, 10, 100, 1000, 10000 etc to get the correct place values, then add them together to get your number.

Most integers are only 16 bit, however, so they would be too small.
A double (32bit) integer would be better.

I would also do this function in the basic module, as I find BASIC to be a bit easier to use for these types of functions than PLC logic. I would, however, still keep the individual registers, since this will make trouble shooting a bit easier.

Doug
 
That's the CMB (Combine) instruction, Panic. Too bad one doesn't exist... :D

I would approach it as Doug mentioned. I've never used it, but the CPT (Compute) instruction looks like it would be useable for this... :confused:

There's probably some elegant solution that will show up within the next 24 or so hours... :nodi:

beerchug

-Eric
 
That number would be too big for an AB integer file.(can't go above 32767) You could do the first 3 into one and the last 3 into another though.
 
Take the register containing 6 and multiply it by 10. Add the result and the register containing 7 together. For the next most significant digit, multiply by 100 and add to the running total, etc

I'm not familiar enough with the details of the SLC's math capabilities. Can it do 32-bit math? If not, convert each digit to floating point. Will floating point display all six digits?

If not, how about BCD? Convert each digit to BCD. Shift the MSD left by four places and OR the result with the second most significant digit. That gets the two most significant digits in one register. Now shift the third digit left by 12 places, the fourth digit left by 8 places, the fifth digit left by 4 places. OR all three of those the shifted registers together with the sixth digit, and you've got digits 3, 4, 5, and 6 combined into a single BCD word.
 
What are you doing with the final number, D. Helms? Do you need to use it in a calculation?... :confused:

beerchug

-Eric
 
A little more info...

I'm sending the number to another display panel (not AB) so the machine operators can see it. As a quick and dirty solution, I'm just displaying the number as the six individual values grouped together. I'm just looking for suggestions to clean it up a little. I suppose it really doesn't have to be an integer if something else would achieve the same result -- I don't need it for a calculation, so a string might also work. Thanks for the replies.
 
Yes, I agree, and you could do it all with the CPT instruction. In a CPT Just enter the formula: ((N7:121)+(N7:122*10)+(N7:123*100)+(N7:124*1000)+(N7:125*10000)+(N7:125*100000)) and make the destination word a floating point math word like F8:7
 
Last edited:
IF your not using it to compute any values, the SLC 5/05 has all the instructions needed to convert the digits to sting values and the combine or "Concatenate" those strings into 1.


AIC----INterger to String
ACN----String Concatenate

It may take quite a few lines of code and confuse someone trying to trouble shoot it but it can be done.

Tim
 
Combining two digits into one integer

Eric,
Here is a way to combine two digits into one integer in RSLogix.

[attachment]

combine digits.jpg
 
Last edited:

Similar Topics

Hi, I have a functions which extends codes generation for RFID tags. Basically it takes a char and splits it's hex value over 2 chars. I cannot...
Replies
24
Views
9,414
I'm onsite right now and I'm trying to decide how to proceed. I need to make some major edits to the Micrologix 1400 file, but the guy with the...
Replies
9
Views
1,153
Hello, I am trying to write a logic to control a pump. I have my logic as attached. Is there a way to do Auto and Manual control without having...
Replies
12
Views
2,717
Hi there, Quick Question. I have 2 PLCs and 2 solenoids. I would like to wire these up so that If either one turns on, it will turn on both...
Replies
17
Views
11,393
Hi all. I’m currently trying to combine 3 memory words in to a single display on a weintek hmi as I want to display running time. I have the...
Replies
4
Views
1,823
Back
Top Bottom