You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old July 23rd, 2019, 11:16 AM   #1
BNA
Member
Denmark

BNA is offline
 
BNA's Avatar
 
Join Date: Sep 2003
Location: Give
Posts: 117
Search array Siemens S7-1500

Hi

I am stuck in trying to get my code search an array and retur an index number.

So, I have an array from 0 to 254 created from an UDT where I have a timer SP, a Timer ET, a scale of the timer and a manufactor item number like this.

Timer[0]
Timer_SP (DINT)
Timer_ET (DINT)
Scale (INT)
Item_NO (DINT)

Timer[1] And so on

What I am trying, is to make a small piece of SCL code that allows me to search my array for the item number and return the place number i my array (The value in []).

This is what I got so far:

FOR #Index := 0 TO 255 DO;
IF Array_DB.TIMER[#Index].Item_NO = #Value_to Search
THEN EXIT;
END_IF;
END_FOR;

Any suggestions

Best Regards
Brian
  Reply With Quote
Old July 23rd, 2019, 01:24 PM   #2
gclshortt
Member
Canada

gclshortt is offline
 
gclshortt's Avatar
 
Join Date: Dec 2014
Location: Cobourg
Posts: 2,884
http://www.plctalk.net/qanda/showthread.php?t=8850

http://www.plctalk.net/qanda/showthread.php?t=66415

The above threads may help you out.
Regards,
__________________
Garry
https://www.accautomation.ca
Connect with us on Facebook: facebook.com/accautomation/
  Reply With Quote
Old July 23rd, 2019, 01:39 PM   #3
BNA
Member
Denmark

BNA is offline
 
BNA's Avatar
 
Join Date: Sep 2003
Location: Give
Posts: 117
Hi Garry

Thank you for your reply, but it is not excactly what I am looking for, it is the other way around. I want to search a specific number i my array and return the matching number, if that makes sense.

So if I for example search for item_no XXXX and find a match, it should retur for example Timer[0]

/Brian
  Reply With Quote
Old July 23rd, 2019, 03:01 PM   #4
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,730
Your code works as expected - see my test call below:
Attached Images
File Type: jpg array1.jpg (69.1 KB, 47 views)
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com

Last edited by L D[AR2,P#0.0]; July 23rd, 2019 at 03:04 PM.
  Reply With Quote
Old July 23rd, 2019, 03:02 PM   #5
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,730
and the block I called....
Attached Images
File Type: jpg array2.jpg (108.7 KB, 45 views)
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old July 24th, 2019, 05:33 AM   #6
BNA
Member
Denmark

BNA is offline
 
BNA's Avatar
 
Join Date: Sep 2003
Location: Give
Posts: 117
Hi L D[AR2,P#0.0]

Thank you for the reply and thanks for testing.

It is a bit strange it is not working here, but at least I know the code is working so there must be a reference error somewhere.

I will start a search :-)

/Brian
  Reply With Quote
Old July 24th, 2019, 06:31 AM   #7
BNA
Member
Denmark

BNA is offline
 
BNA's Avatar
 
Join Date: Sep 2003
Location: Give
Posts: 117
Quote:
Originally Posted by BNA View Post
Hi L D[AR2,P#0.0]

Thank you for the reply and thanks for testing.

It is a bit strange it is not working here, but at least I know the code is working so there must be a reference error somewhere.

I will start a search :-)

/Brian
Problem solved: I had put 0 TO 255 in my array but the actual array were 0 TO 254
  Reply With Quote
Old July 24th, 2019, 09:08 PM   #8
mk42
Member
United States

mk42 is offline
 
Join Date: Jun 2013
Location: MI
Posts: 2,182
Quote:
Originally Posted by BNA View Post
Problem solved: I had put 0 TO 255 in my array but the actual array were 0 TO 254

I'm always amazed at the places those sorts of errors can sneak in.


I was upgrading some code a few months back where I thought it wasn't starting because of all these array bound errors I was finding every time i ran the code. It turns out that I was missing some config value that prevented the loops from ever getting high enough to notice that they didn't match, so the code had been "wrong" for the last 10 years at least, but ran just fine.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Communicate Citect 2016 with Siemens S7 1500 with S7TCP driver Eduardo Pelegrin LIVE PLC Questions And Answers 6 February 12th, 2019 10:28 PM
Siemens S7 1500 and FM350 aand74 LIVE PLC Questions And Answers 2 February 7th, 2018 01:34 AM
Siemens S7 to A-B ControlLogix EtherNet/IP Communications Robert.Yager@vw.com LIVE PLC Questions And Answers 7 January 9th, 2013 02:53 PM
siemens S7 PLC communication with computer panthripu LIVE PLC Questions And Answers 0 March 7th, 2012 09:56 PM
Siemens S5 and S7 Dual Masters for Profibus daveswerld LIVE PLC Questions And Answers 15 December 16th, 2008 02:15 AM


All times are GMT -5. The time now is 10:51 PM.


.