Searching array for multiple values in a row using FSC

threetrey

Member
Join Date
Feb 2020
Location
USA
Posts
18
Good morning everyone,

I'm working on a project where I am recording data from a machine by sending it message packets. Most of the time the data comes back to me correctly, but sometimes (about 20%) the received message comes back with extra characters at the beginning of it.


I have the data coming into a UDT that can store 256 SINT's and the data I need is only using about 122 of those. When the message comes in with the extra characters, the data I need may get shifted down to Data[50] or so.

I know the beginning characters of where the good data begins will always be these values "-33 -5 -3". I created a new tag DataMSG_Start and input these 3 SINT values.

I've been trying to use an FSC instruction to search the UDT to find the position where this pattern begins, but I can only get it to work when searching for one of the values. I can't figure out how to get it find the full pattern? Or is this not possible with the FSC instruction?

I can use the following FSC setup to find a match for one of the single values:

Control: DataSearch
Length: 256
Position: 0
Mode: All
Expressions: Data.SINT[DataSearch.POS] = DataMSG_Start[0]

I've tried using DataMsg_Start[0] AND DataMSG_Start[1] AND DataMSG_Start[2]

but not getting anything with that

Any help would be greatly appreciated!
Thanks
 
Last edited:
From the instructions after the compare is found the instruction sets the .FD and the .IN bits to continue the search just clear the .IN bit
don't forget to record the pos. for each valid for each found search
 
Have you tried something like '(Data.SINT[DataSearch.POS] = DataMSG_Start[0]) AND (Data.SINT[DataSearch.POS+1] = DataMSG_Start[1]) AND (Data.SINT[DataSearch.POS+2] = DataMSG_Start[2])' ?

If that doesn't work you could match the first one, then use CMP instructions to check POS+1 and POS+2, resetting .IN if both don't match.
 
Last edited:
Hmm no I had not tried anything like that yet. I just tried the first way in the FSC instruction but it won't let me do that, I guess because of the multiple ='s?


This makes sense though, I'll play around with using the compare instructions after it and see if I can get it.


Thanks for the help!
 
Right, AND in that context is a bitwise comparison operator, not boolean. My mistake. Yeah, you can only do a single comparison within the FSC.
 
So I would use Indirect addressing. Using your original expression.

Expressions: Data.SINT[DataSearch.POS] = DataMSG_Start[0]

Once this position is found then compare.

IF XIC DataSearch.FD EQU Data.SINT[DataSearch.POS +1] -5 And EQU Data.SINT[DataSearch.POS +2] -3 Then Read from DataSearch.POS

IF XIC DataSearch.FD NEQ Data.SINT[DataSearch.POS +1] -5 OR NEQ Data.SINT[DataSearch.POS +2] -3 Then (U) DataSearch.IN


You could use DataMSG_Start[1] and [2] to replace -5 and -3
 
Last edited:
Yep I believe I got it now.


Leaving the FSC instruction the same but only searching for the first value.
Then use the compare instruction:
Data.SINT[DataSearch.POS+1]=DataMSG_Start[1] and another one with .POS+2
Thank you!
 

Similar Topics

I'm looking to see how I can search an array of DINTs to see how many occurrences of a certain value there are in the array. My thought was a FSC...
Replies
4
Views
1,359
How would I search an array of 52 SINTs for an available space (0) then move a (1) into the first available space?
Replies
29
Views
9,622
I am using a UDT that has tool data. I need to query based on three values within an array of 43. ex. ToolData[43] DataType - udt_tool...
Replies
14
Views
5,036
Hi Guys, Is there an instruction suitable for searching an array of UDTs for lowest value? I can achive using a loop but figure theres an...
Replies
1
Views
2,556
is it just me, or has something happened with the google search when using chrome? looks likes safari on mac is ok, but edge/chrome on windoze has...
Replies
10
Views
833
Back
Top Bottom