CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri Jul 21, 2017 11:38 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Compare array
PostPosted: Tue May 02, 2017 2:20 pm 
Offline

Joined: Mon May 01, 2017 11:27 am
Posts: 10
Hi all.
I am new to codesys but I am getting the hang of it. I only struggle with the arrays. Now i need to do some actions with arrays and i have no idea how to start.
Here's the situation:
I want to put 50 codes into the plc (these will never change). When someone scans an article, a code is given in the plc with an "array [0..3] of byte".
Now I want to compare this result with the 50 other codes. All codes are the same length.
But i have no idea how to compare the array of byte with the codes. How to convert the array to a string? Or are there other options? Does anyone knows a solution with this problem?
All has to be done in ST btw :)


Many thanks.


Top
   
 Post subject: Re: Compare array
PostPosted: Tue May 02, 2017 2:54 pm 
Offline

Joined: Wed Dec 09, 2015 4:05 am
Posts: 31
Hi,

I would stick the codes into an array of dwords, a pointer to dword to the 4 bytes that come from the scanner and then a for loop to look through the array to see if you find a match.

Heinz

Sent from my SM-G935F using Tapatalk


Top
   
 Post subject: Re: Compare array
PostPosted: Tue May 02, 2017 3:10 pm 
Offline

Joined: Mon May 01, 2017 11:27 am
Posts: 10
teichhei wrote:
Hi,

I would stick the codes into an array of dwords, a pointer to dword to the 4 bytes that come from the scanner and then a for loop to look through the array to see if you find a match.

Heinz

Sent from my SM-G935F using Tapatalk



I could check that :)
Do you know if it is possible by converting it into a string or whatever? It could be easy to know when i have to work on other projects if there are more bytes.
Thanks in advance


Top
   
 Post subject: Re: Compare array
PostPosted: Wed May 03, 2017 12:36 am 
Offline

Joined: Wed Dec 09, 2015 4:05 am
Posts: 31
You can also leave the codes as an Array of string and use oscat basic Chr_to_string and concat in a loop to build your string from bytes. Or you do a pointer to string with an address of aByte[0..79] and load your four bytes into [0..3] and make sure the rest stays 0. Then it's flexible with the lenght as well.

Sent from my SM-G935F using Tapatalk


Top
   
 Post subject: Re: Compare array
PostPosted: Wed May 03, 2017 10:22 am 
Offline

Joined: Mon May 01, 2017 11:27 am
Posts: 10
Thanks for the reply :) I'll work on it


Top
   
 Post subject: Re: Compare array
PostPosted: Fri May 05, 2017 11:05 am 
Offline
User avatar

Joined: Tue Jun 28, 2016 2:45 pm
Posts: 34
Hello NBCC,

check out the CAA Memory Library. There is a Compare function under the category "CAA_Memory" --> "Analysis" -->"ARRAY and MemoryBlock". With this function you can compare arrays and find the first position of the change.

Code:
wPosition := MEM.Compare(ADR(arrArray1),ADR(arrArray2),SIZEOF(arrArray1));

IF wPosition >= 1 THEN
    ; // difference on position X
END_IF


Regards,
KevinR


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited