String indexing

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.

Mellis, I am trying to my string that I am receiving from a safety gateway. Once i get this string I want to compare each bit to 0. When it finds a bit that is 1 I need to pull that number and put it on my hmi with a message that says " Slave 15 is faulted"
 
Mellis, I am trying to my string that I am receiving from a safety gateway. Once i get this string I want to compare each bit to 0. When it finds a bit that is 1 I need to pull that number and put it on my hmi with a message that says " Slave 15 is faulted"

Why not move string (why string?) and define bit by bit what is the alarm?

(you are still answering what you want to do in programming, not what you want to do in function)
 
Can you provide some examples of what you expect to have in this string?

The reason everyone is having a hard time with this is because the Length property of your string typically isn't what you'd use to figure out what is in the string. It only tells you how many characters are in the string, it tells you nothing about what the value of the string is.

Now if your string is always a number ("135", "222", "42", etc), then you can use a STOD to convert it to an integer, then use the FBC to figure out what bits are on.
 
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....

Thank you Dmroeder this did exactly what I was looking for. I guess it was hard to describe what I was looking for because it really isn't something that everyone would do. It was relatively specific to my project making examples hard to give. Thank you everyone for your input!
 

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,585
All, I am trying to reset timers when a Work Order change occurs. The Work Order comes in as a string and I am comparing it to a tag...
Replies
2
Views
86
Hello, I am using studio 5000 pro and am trying to figure out the structured text. Here's my scenario: An operator scans a barcode, the barcode...
Replies
15
Views
284
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
189
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
448
Back
Top Bottom