Struggles with Strings

JE_Engr

Member
Join Date
Sep 2016
Location
Tennessee
Posts
9
I'm having some trouble working with some string files. I have a Keyence barcode scanner that I'm connecting to via E/IP. When I scan something, it dumps the read value into a series of elements starting at SR:I.Data[11] tag and going to about SR:I.Data[25], depending on the length of the code I am reading. The tags are DINT, but the code is actually ASCII characters. I use a COP instruction to copy the DINT values into a string tag to get the values in a string as ascii characters, and then I can search for specific items within the code using FIND and pull out sections of the code using MID. For some reason, I can't get it to work. If I open my string tag after executing the COP and look at the .data I can see my values in order minus the first element. It is setting the string .LEN as the entire first element. The first two characters in SR:I.Data[11] are "82", and I assume should be the length of the string. When it sets the length of the string to the whole first element, which is "825372725", this value is way too long and makes the string not work. Any idea what's going on?
 
Last edited:
The value of the SR:I.Data[11] tag is an output from the scanner. For me, it is "825372725"...because the scanner said so. After playing around with it some more, it appears that the "82" is just a coincidence. When I switch the tag style from decimal to ascii, then it displays '1205', which is the inverse of the first four characters in my barcode.
So it seems like the problem is when I use the COP instruction, it sets the length of the string to the decimal value of the first element in the source, which is not what I need it to do. I am fixing it by starting my copy an element early at SR:I.Data[10]. Then after my COP instruction has finished I use a MOV to reset the .LEN of my string tag to "82". This seems like a work around that would be very confusing to the next guy that looks at the program, though.
 
Can you post your code? Can you take the whole string from [0] to [25] and use the MID function to take extract the bit you want?
 
What PLC are you using? Are you using a Generic Ethernet module? I know for some of the readers Keyence provides EDS files that will put your barcode string in it's own array making it much simpler.
 
I will work on getting some code posted. The PLC is a CompactLogix 5370, scanner is a Keyence SR-2000.

I think my issue is more with how the copy function works when going from DINT to string. By default, it seems the copy function uses the first element as the .LEN value for the string, but the data in the tag does not start with .LEN data in the first element. Is there any way to change this? I will be chatting with Keyence to see how they intended the strings to be handled, maybe that will shed some light.
 
Here is some of my code. It does look like I am using a different method of transferring the data than on the Keyence example. Looks like I will need to chew the fat a bit on this Keyence example code. Thanks for the link to the barcodereader.com the_msp, I hadn't used that resource before!
 
When I did a CompactLogix and Keyence vision system I ended up using the DTOS instruction. The amount of instructions I needed was the length of the codes the customer used (12 or 13 I think)
It was a few years back and I remember having some struggles moving the data around

So maybe something like?
DTOS Source: SR:I.Data[10] Dest: Barcode_Raw_Read[0]
DTOS Source: SR:I.Data[11] Dest: Barcode_Raw_Read[1]
etc.
 
Try This: This copies the 0 the 8th the 16th and 24th bits of the DINT for a length of 8 bits and copies them to a string tag, Data[0] Data[1],Data[2],Data[3]

825272725 converts to 5021 in string

string_convert.jpg
 
Make the destination of the COP instruction BARCODE_RAW_READ.Data[0].

The Length of that COP instruction will need to be the number of bytes of data that you intend to move into BARCODE_RAW_READ.

The "1" for the COP length worked before because you were addressing the whole STRING datatype (one "element"), which is also why all four bytes in SR:I:Data[11] went into the .LEN subelement. Because you will be addressing the .DATA[x] array, which is an array of 1-byte SINT values, you need to make the Length of the COP instruction the number of 1-byte SINT elements.

If the length of the incoming barcode is presented elsewhere in the SR:I:Data tag, use that to manually set the BARCODE_RAW_READ.LEN length value.

The number 82 might show up in your learning about ControlLogix strings, either as a coincidence or for compatibility and legacy reasons. PLC-5 and SLC-500 controllers had an 82-character size limit for String datatypes, which is why the default STRING in ControlLogix has an SINT[82] data field. You can create your own STRING datatypes in Studio 5000 that are much shorter or longer.
 
To take a bit of a step back, the default STRING datatype in ControlLogix consists of two sub-elements:

.LEN DINT
.DATA SINT[82]

If you copy data into the String tag starting at the very beginning of the tag's structure (by just entering the tag name), it goes into the 4 bytes of the .LEN subelement first.

If you copy data into the String tag starting at the .Data[0] element, it goes into the .DATA portion where the actual characters are kept.

When I do logic like this, I empty out the String before I do the copy from the I/O tag, by using an FLL instruction to fill the .DATA[x] array with zeroes. That way there's no risk of "leftover" characters being in my string.
 
Bingo! Copying into the Barcode_Raw_Read.Data[0] put the data right where I want it without changing the .len value. I found by going through the Keyence example files that they configured the module to use SINT data type instead of DINT (they provide tag name files for both, as well as INT). When I did this, it gave me a usable result data length tag that I am now using both for the length section in the COP instruction and moving into Barcode_Raw_Read.len as you suggested. I will also look into using the FLL instruction to blank out the tag. I have been using COP to copy a blank string into the tag, but your way sounds a little cleaner. Thanks so much for the help!🍻
 

Similar Topics

I have a magelis XBTGT5330 that has a faulty backlight, I stuck a led strip in its place so I can see whats happening on the screen. Still needs...
Replies
18
Views
4,055
Hey all, was wondering if it was possible to shift values in an array of strings? I have a database that I am loading up with "Users" in the...
Replies
2
Views
293
hi All I am completely green in Mitsubishi PLC (i used to program siemens) but need kepware to connect to FX3U pls with ENET adp module. Could...
Replies
31
Views
7,070
Hi, I have a list selector which I want to display the recipe found inside a plc-5. The recipe is store in an ascii table with each character...
Replies
4
Views
1,400
I'm fairly new to View Studio SE. I'm trying to do a simple visibility animation, but I would like to do so with a string tag. The tag is one...
Replies
0
Views
1,209
Back
Top Bottom