String indexing

garlantm

Member
Join Date
Aug 2016
Location
Michigan
Posts
28
Hello all,

I would like to index through a string of numbers and compare them but I do not understand which command to use or how to get it to index. Could someone please help show me how to do it or tell me where I can get some good information on doing this.

Thank you
 
"String of numbers" is a little confusing. I'm not sure if you are referring to the STRING data type, or just an array. I guess either way the concept is similar.

In ladder logic, there is the FOR instruction (FOR/NEXT loop). Or you can use the FAL instruction. Or even a FSC. You could also do in the clunky way and have a counter increment, use it's .ACC tag to increment through your array. You could even use an ADD instruction to increment your index.

Or if your version of Logix supports Structured Text routines, you can use that language pretty easily to loop through an array.

If you want some specifics, describe exactly the problem you are trying to solve, what tags and data types are involved and someone will help you along.

edit: If you were talking about STRING data type specifically, you can access each character with "StringTag.DATA[index]
 
Last edited:
"String of numbers" is a little confusing. I'm not sure if you are referring to the STRING data type, or just an array. I guess either way the concept is similar.

In ladder logic, there is the FOR instruction (FOR/NEXT loop). Or you can use the FAL instruction. Or even a FSC. You could also do in the clunky way and have a counter increment, use it's .ACC tag to increment through your array. You could even use an ADD instruction to increment your index.

Or if your version of Logix supports Structured Text routines, you can use that language pretty easily to loop through an array.

If you want some specifics, describe exactly the problem you are trying to solve, what tags and data types are involved and someone will help you along.

edit: If you were talking about STRING data type specifically, you can access each character with "StringTag.DATA[index]

I am trying to use the FOR command as you can see in my pictures below. am I doing wrong? Also Here is my list of tags that I am trying to increment through. I want to go through the list and compare so when I find a High bit I can flag the error on that bit.

Thank you,



Capture.JPG part2.JPG
 
The FOR command

The 'Routine name' will be the name of a routine you create, probably not 'MainRoutine', which will perform the individual comparison and error flagging using the value of 'index_count'.

Your Initial Value and Terminal Value should be just '0' and '31'.

Perhaps if you provide an example string and an illustration of what you want to do we can help.
 
I am looking to go through that list one at a time so that I can look for a high bit or "1". Once I come to the bit that is High I want to send an alarm to my HMI
 
Do you need to know which bit is a 1, or just than any bit is a 1?

edit: if you need to know which bit, use the FBC. If you just want to know if there is a bit on, just use a NEQ to see if the .LEN is not equal to zero.
 
Last edited:
I need to know which bit it is that went high. each bit is tied to a different saftey device that flags a 1 when it is in error state.
 
I need to know which bit it is that went high. each bit is tied to a different saftey device that flags a 1 when it is in error state.

The list I need to scan once it detects that there is an error is the list above. those are all different slaves 1-31. After I that there is an error I want to go through that list until it finds the 1 bit and have that flag an error. I named it Delta_List_response because it is coming back to me from a cip message
 
The problem I am having is just like the FBC instruction a lot of these are requiring that I use an array and my values are coming in as a DINT of a String
 
The problem I am having is just like the FBC instruction a lot of these are requiring that I use an array and my values are coming in as a DINT of a String

I see. Try this. Create an array of DINTs, say, FBCDints. Maybe a length of 10. Move your string.LEN into [0]. In your reference use [2], and the result[4]. Make the length 32. Ok, it didn't need to be 10 DINTs but I like round numbers.

The bit that is on will be in [4]. In other words, if FBCDints[0].10 is on, then FBCDints[4] should have a 10 in it. Or at least that is the way it works in my head....
 
Maybe I'm just missing the concept here but:
You are using a string datatype - a string is an array of ascii characters (text).
You are searching for bits on - that doesn't make sense with a string.
You seem to be focusing on the .Len member of the string - this is a DINT holding the length of the string. Examining its bits shouldn't be useful.

If you explain what you are trying to accomplish, I'm sure someone can help. I mean explain what you intend to accomplish in the real world, not how you are trying to use this instruction.
 
Maybe I'm just missing the concept here but:
You are using a string datatype - a string is an array of ascii characters (text).
You are searching for bits on - that doesn't make sense with a string.
You seem to be focusing on the .Len member of the string - this is a DINT holding the length of the string. Examining its bits shouldn't be useful.

If you explain what you are trying to accomplish, I'm sure someone can help. I mean explain what you intend to accomplish in the real world, not how you are trying to use this instruction.

Yeah, I don't understan the string or the len part of it at all...

But.. If every bit means a specific alarm and you want just that so you can raise an alarm... Wouldn't a simple move from the buffer do the trick?
 

Similar Topics

Guys I know this has been talked about but I couldn't find it. I need to do a bunch of ASCII read and writes in a 1100. It doesn't support...
Replies
4
Views
2,566
I am creating a global object in FTView SE 13. I want to have a string read from the PLC and display (in this case the tagname). So lets say...
Replies
4
Views
150
So I had an odd request from a customer for the above. I have written the logic and tested it all in one PLC with only using 7 outputs and 7...
Replies
15
Views
423
Hello Inside a FB, I´m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i can´t determine the...
Replies
4
Views
125
As the title says, I'm using CCW with a PV800 (and Micro850). I've made a scheduler in which a user can choose a month, day (1-31), hour (0-23)...
Replies
15
Views
499
Back
Top Bottom