How to convert DINT array to STRING

hiroT

Member
Join Date
Jan 2010
Location
japan
Posts
10
I use CompactLogix L32E and bar-code scanner.
The read data of scanner is mapped to array of DINT.
The read data almost ASCII, so I want to use ASCII instruction.
Please teach me how to convert the array of DINT to STRING data type.

for exanple...
data is DINT[100]
data_string is STRING
Is there easy way to convert data to data_string.
 
I haven't done this...but I found the DTOS instruction might do it for you...

If your array is 100, then maybe you will have to do it 100 times..

dtos.jpg
 
How is the data presented in the DINT array?

Please show an example.....
 
data example

DINT[100] data includes ASCII data and size.
the lower 2byte of DINT[0] is ASCII data size.
the upper 2byte of DINT[1] and following DINT is ASCII data.

for example 5byte ASCII data. "ABCDE"
DINT[0] = 'B',A',x00,0x05
DINT[1] = 0x00,'E','D','C'
 
Last edited:
As Ian said I would use the command DTOS, and you will have to let it run it 100 times to get through your array.
I'd make a loop with a counter, if you know that there are always 100 DINT's to process.

But does the barcode scanner give you those 100 DINT's in one go? Or does it give you 1 or 2 DINT's every time it reads a barcode?
If you get onle a couple of DINT's, I'd let the DTOS process them as they come in and then store them in a STRING array instead.

But you say almost ASCII, what do you mean with that? Is the data all numbers or are there caracters like a, b or c in it as well?
 
Thank you.
I will use DTOS instruction.


But does the barcode scanner give you those 100 DINT's in one go? Or does it give you 1 or 2 DINT's every time it reads a barcode?

>In one time, scanner give all result data, less than 100 DINT.

If you get onle a couple of DINT's, I'd let the DTOS process them as they come in and then store them in a STRING array instead.

But you say almost ASCII, what do you mean with that? Is the data all numbers or are there caracters like a, b or c in it as well?[/quote]

>barcode data is almost ASCII character but sometime includes binary(less than 0x20, more than 0x70) data.
 
The DTOS will try to translate the numeric value of the DINTs into their ASCII equivalent. The 'A' would translate to the string '65'.

Try a COPy of the array of DINTs into a string with a length of 1.

If that doesn't work try CPS.
 
Bernie's COP or CPS solution will not work due to the first DINT containing both length and ASCII data. These need to be separated out.

Here is a working solution...

See attached images

readerdata.jpg readerstring.jpg barcode_udt.jpg code.jpg
 
Excellent Daba. For some reason (I'm away from access to RSLogix500 right now) I thought the LEN was an INT. I also thought of COPying his source to a UDT made up of an INT then all SINT's, Then MOV the first INT to the LEN and COPying the SINTs into their proper place in a standard string.
 
Bernie - Thank-you

hiroT - Are you sure the data from the scanner is (up to) 100 DINTS ? - it does seem to be a lot of data for any of the common barcodes.

And I forgot to mention that the UDT "Barcode" is a new STRING data-type - there is a separate data-type folder for STRING types, where you can make your own of any length.

I made it capable of containing 398 ascii characters, because the 100 DINT array (400 bytes) uses the first 2 bytes (an INT) for the length of the bar-code data, leaving 398 bytes for the data itself.

Note that being able to make your own STRING data-types is useful. Suppose you had HMI or similar String Data that were up to, say, 30 characters each, then using the pre-defined STRING (capable of holding up to 82 ascii characters), would be wasteful of memory usage.

If your bar-code data has a lower size limit (read the scanner documentation), then you can reduce the Barcode STRING udt size accordingly.
 
Thank you so much -Daba and barnie

As data size, I will select array of SINT or STRING.

I appriciate for your help.
 
....As data size, I will select array of SINT or STRING.

Sounds like you mis-understood...

The tag "ReaderString" is of data-type "Barcode".

"Barcode" is a new STRING UDT (look in the STRING folder of the Data-Types). A STRING data-type consists of two elements, .LEN (a DINT), and .DATA (a SINT Array). When you create a new STRING UDT, you specify the number of characters the tags can hold, which sets the size of the array.

I configured "Barcode" to accept a string length of 398 characters, since that is what your DINT[100] array could hold (4 ascii characters (bytes) per DINT, less the 2 bytes used as character count).

I then questioned whether this length is appropriate for your scanner, as it does appear to be very big.....
 
OK, I understand.

When less than 82 bytes, I will use STRING data type that is pre-defined.
When more than 82 bytes, for example 398 bytes, I will use UDT "barcode_data".

Thank you so much.
 
OK, I understand.

When less than 82 bytes, I will use STRING data type that is pre-defined.
When more than 82 bytes, for example 398 bytes, I will use UDT "barcode_data".

Thank you so much.

Not entirely sure you do.....

When you have discovered how many ASCII characters the scanner sends when it reads a barcode - then you can create a String Data-Type of your own to match...

Example 1 -

A common barcode is the Code128, which contains 128 "characters".
Simply create a new "String" Data-type with a length of 128.

Example 2 -

If your barcode contains 72 "characters".
Simply create a new "String" Data-type with a length of 72.

Example 3 -

If your barcode contains nn "characters".
Simply create a new "String" Data-type with a length of nn.
 

Similar Topics

I have a Structure in my project which has a few nested UDTs. They are ultimately of type DINT. What I would like to do is copy the values out of...
Replies
5
Views
2,246
Thank you so much for your help! I am trying to use an INT or DINT as a setpoint for my remote device using Modbus TCP/IP. My code is...
Replies
2
Views
2,371
Greetings fellow PLC programmers, I know there is a simple way to get the system date time of the RSLogix system. But, is there then a way to...
Replies
12
Views
8,530
I need to iterate though the bits in a DINT, but it seems you can't indirectly address a DINT at the bit level..... So my next thought was...
Replies
9
Views
3,421
I'm not a ladder or AB guy and the people asking me are using both, so this has me stumped. Long story short, they have several arrays of...
Replies
11
Views
5,311
Back
Top Bottom