SINT to INT

MGuenette

Member
Join Date
Jan 2007
Location
Montreal
Posts
134
Hi,

I receive a barcode scan in a SINT type tag in my CLX. I want to extract a specific part of the code and transfer it into a INT.

I want to extract the product code (bit 12 to 16 of my SINT)

I've never did that before.

thanks
Martin.
 
The problem is that my tag (sint[35] type)is filled with ascii code. I would like to extract 5 ascii code (tag[12] to tag[16] and make a int or something like this...
 
Well, 5 bytes, is more than a DINT will hold, so maybe you need to explain more of what you are doing?

If you are trying to extract an ASCII formatted 5 digit string, either convert the SINT array to a string, use the MID function to extract the numeric substring, and then the STOD to convert that to a DINT.

Or, loop through the parts, subtract 48 (ASCII 0) from each one, multiply by the proper power for that position, and add it to a register.

Result = (Tag[12] - 48) * 10000
Result = Result + (Tag[13] - 48) * 1000
Result = Result + (Tag[14] - 48) * 100
Result = Result + (Tag[15] - 48) * 10
Result = Result + (Tag[16] - 48)
 
Almost working....(your 2nd method)

Here's an example of what I have
tag[12] : 48 (0 in ASCII)
tag[13] : 50 (2 in ASCII)
tag[14] : 51 (3 in ASCII)
tag[15] : 48 (0 in ASCII)
tag[16] : 57 (9 in ASCII).

I would like to store my product number incuding "0" (02309) in a tag. After that I will compare my scan with my products code list.
thank
Martin.
 
The only way to store the leading zero is to store a string or an array, you can't store a DINT, INT, or Float with a leading zero, that not how numbers work in a computer.
 
If you are only expecting the numerals 0,1,2,3,4,5,6,7,8,9 then you could do a comparison (would take a few lines of code, a bit crude but it will work)e.g
If tag[12] = 48 then copy (length 1) String_0 (string type tag with a "0" in it)to ProductCodeDigit_1 (another string type tag)
If tag[12] = 49 then copy String_1 (string type tag with a "1" in it)to ProductCodeDigit_1
If tag[12] = 50 then copy String_2 (string type tag with a "2" in it)to ProductCodeDigit_1 etc etc
Then do the same for tag[13] to ProductCodeDigit2, tag[14] to ProductCodeDigit3 etc etc.
Then Concantenate ProductCodeDigit1 with ProductCodeDigit2 etc to form your final string tag ProductCodeFinal, which will contain your product number in ascii "02309"
You can then compare that string to your array of product codes (in string fomat)
 
kiwi sparky said:
If you are only expecting the numerals 0,1,2,3,4,5,6,7,8,9 then you could do a comparison (would take a few lines of code, a bit crude but it will work)e.g
If tag[12] = 48 then copy (length 1) String_0 (string type tag with a "0" in it)to ProductCodeDigit_1 (another string type tag)
If tag[12] = 49 then copy String_1 (string type tag with a "1" in it)to ProductCodeDigit_1
If tag[12] = 50 then copy String_2 (string type tag with a "2" in it)to ProductCodeDigit_1 etc etc
Then do the same for tag[13] to ProductCodeDigit2, tag[14] to ProductCodeDigit3 etc etc.
Then Concantenate ProductCodeDigit1 with ProductCodeDigit2 etc to form your final string tag ProductCodeFinal, which will contain your product number in ascii "02309"
You can then compare that string to your array of product codes (in string fomat)


Thats exactly what I want to do. I already made it for 2 digit.

thanks a lot!!

Martin
 
Your barcode length is always 5 characters, so you can do this:-
Create a new STRING5 Data-Type, max length 5 characters

Then in ladder:-

MOV 5 Code.LEN
COP tag[12] Code.DATA[0] 5

where :-
Code : Data-Type STRING5
tag : your original SINT array

Now you have a STRING tag called Code containing the code part of your tag[x] array.

If you want your code as a number, add the instruction :-

STOD Code CodeDINT

where:-
CodeDINT : Numeric equivalent of your code string.
 
Last edited:

Similar Topics

Howdy, I am currently struggling with an array of values that I want to re-arrange in a programmatic way. My program is a mix of ladder and STX...
Replies
6
Views
392
Hello PLC folks, Could someone please help me out here? I am trying to convert SINT to STRING (rslogix5000) but could not get it to work. I used...
Replies
4
Views
1,099
All, i nto fully get it. I read trough some froums but not finaly make it running. so I try to ask. Hopefully anybody has the kindness to answers...
Replies
7
Views
1,192
Hello i have been trying to figure out a good way to take hex and convert it to an array of SINT[]. Here is what my failed attempt looks like.
Replies
5
Views
1,267
Hello! I am completely new to PLCs, so I apologize in advance if this is a dumb question. I have a device that sends out its data as a number of...
Replies
5
Views
2,134
Back
Top Bottom