News:

  • August 29, 2026, 12:30:16 PM

Login with username, password and session length

Author Topic: STRFIND in a Task  (Read 124494 times)

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
STRFIND in a Task
« on: December 26, 2012, 05:14:40 PM »
I have a STRFIND inside of a task that is called multiple times from different stages in another program block. The STRFIND only works when it is called from the first stage, and each subsequent call it doesn't set either of the delimiter found/not found flags. It appears this problem also exists with other edge triggered instructions as well. In the attached example I tried to get a simple STRPRINT to work.
Please help me with how to make an edge triggered instruction work properly on each call in the top of a task. I am probably just missing something simple, but right now I just can't see it.
Thank you
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6174
  • Yes Pinky, Do-more will control the world!
Re: STRFIND in a Task
« Reply #1 on: December 26, 2012, 09:31:52 PM »
Interesting. I had to study this one for a few minutes to figure it out, but I think I may know what is going on.

Programs, Tasks, and Stages all execute special logic on the scan following their completion. We call this 'termination'. Stage 1 gets the .Done indication and immediately jumps to Stage 2, which then re-arms the task to run. It appears that the termination logic is not running for the task prior to running the task a second time. One of the things that termination logic takes care of is edge states for edge triggered instructions. I reversed the order of stage execution, to execute the bottom stage first and then jump to the prior stage...which gives the termination a chance to run by inserting an extra scan between Stage 2 running the task and Stage 1 running it the second time...and it worked fine.

Truthfully? It sounds like a bug. I gotta scratch my head to see what it will take to fix it, but it may be pretty simple.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6174
  • Yes Pinky, Do-more will control the world!
Re: STRFIND in a Task
« Reply #2 on: December 26, 2012, 09:41:51 PM »
Yep...a brief study of the code agrees with my prior guess. Termination isn't running. Now just gotta figure out what to do about it... :-\
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: STRFIND in a Task
« Reply #3 on: December 27, 2012, 07:58:45 AM »
Thanks Bob!
Anxiously awaiting a fix  ;D
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: STRFIND in a Task
« Reply #4 on: December 27, 2012, 09:55:55 AM »
Anxiously awaiting a fix  ;D

Sounds like the short-term workaround is to have consecutive tasks (if they're always consecutive in the same order) in reverse order in the list.  That way an extra one-scan delay is imposed when switching which fixes the problem.  At least, if I was interpreting BobO's post correctly.

If the order isn't consistent, put a timer between each task pair (or just preceding each task) to enforce a short wait, 10ms or something.  That should do the same thing, as long as the task isn't nominally running while it waits for the timer expiration.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: STRFIND in a Task
« Reply #5 on: December 27, 2012, 10:05:04 AM »
Another work-around is to add an intermediate stage after the task is .Done that looks to see when .DoneThisScan is FALSE (i.e. NC CONTACT) along with a JMP to the next stage that has an ENTASK in it.

See attached screen shot.

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: STRFIND in a Task
« Reply #6 on: December 27, 2012, 01:34:40 PM »
It works perfectly with the .Done and NOT .DoneThisScan both on the rung with the JMP.

Thank you!
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: STRFIND in a Task
« Reply #7 on: December 27, 2012, 04:17:54 PM »
It works perfectly with the .Done and NOT .DoneThisScan both on the rung with the JMP.
Cool!  Even better!!

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6174
  • Yes Pinky, Do-more will control the world!
Re: STRFIND in a Task
« Reply #8 on: December 27, 2012, 04:24:00 PM »
I have a fix...but...we weren't planning on releasing new bits until DmD 1.1. Made worse by the fact that some stuff is in flux right now. I could probably cobble together something without too much pain, but it would need to go through some testing before we could release it. I completely understand the problem...it isn't scary...it just means that if you re-arm an edge-triggered task to run prior to running termination, termination doesn't happen. Verifying both .Done and !.DoneThisScan means that termination ran...and should be a very clean workaround. If you are happy with that for now, I won't push immediate release.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: STRFIND in a Task
« Reply #9 on: December 27, 2012, 04:43:33 PM »
I would run into the same type of problem in the DL Stage logic with timers. If the finish of a timer triggered the JMP out of a stage but the stage was re-enabled on the next scan the timer hadn't reset. Because I needed the stage structure as I had it I just added resets of the timer in the calling routines alng with the JMP.
« Last Edit: December 27, 2012, 05:03:15 PM by b_carlton »
An output is a PLC's way of getting its inputs to change.

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: STRFIND in a Task
« Reply #10 on: December 27, 2012, 04:53:51 PM »
If you are happy with that for now, I won't push immediate release.

I'm happy, The workaround is quick, easy, and reliable. :)

BTW, I'm amazed at how FAST this thing(H2-DM1E) is!
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6174
  • Yes Pinky, Do-more will control the world!
Re: STRFIND in a Task
« Reply #11 on: December 27, 2012, 05:43:24 PM »
I would run into the same type of problem in the DL Stage logic with timers. If the finish of a timer triggered the JMP out of a stage but the stage was re-enabled on the next scan the timer hadn't reset. Because I needed the stage structure as I had it I just added resets of the timer in the calling routines alng with the JMP.

I believe that. The resets occur as part of termination, which doesn't happen until the next scan, but the next stage (if it follows the first) happens immediately. I could probably run the termination at the time the stage is jumped out of. Not sure if there are any side effects, but it probably wouldn't be hard to do.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: STRFIND in a Task
« Reply #12 on: December 27, 2012, 07:01:34 PM »
I believe that. The resets occur as part of termination, which doesn't happen until the next scan, but the next stage (if it follows the first) happens immediately. I could probably run the termination at the time the stage is jumped out of. Not sure if there are any side effects, but it probably wouldn't be hard to do.
It's best to leave it how it is.  You can reset stages, not just JMP out of them.  This is also consistent with Task and Program termination (termination is done on the next scan).

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6174
  • Yes Pinky, Do-more will control the world!
Re: STRFIND in a Task
« Reply #13 on: December 27, 2012, 08:53:24 PM »
Yeah...stages would be hard. Tasks and programs would actually be the easier case, the termination could be performed in the TEND and PEND instructions. I would only consider doing it if I could do it everywhere, and without side-effects. I would also only consider doing it because it could potentially fix some of the possible confusion...make it work like I think it should without caveats. That said...I find this kind of change scary. So many possible gotchas...

The initial problem was easy to fix though. It just involved moving the termination test to the top...which is how it already was in Program.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: STRFIND in a Task
« Reply #14 on: January 01, 2013, 11:04:56 AM »
How do I make an edge triggered instruction work properly inside a For/Next loop?

I am trying to assemble a response back to a web server by using the STRPRINT instruction, and appending all the data into a string, it is simple to do in a for/next by using the loop index to increment through the data as I pack it in. The loops lose a lot of their attractiveness when I cannot perform these type of tasks inside of them...I know I can use a loop toggle bit, but then I have to do math on the index outside and inside the loop, which makes a mess quick.

Any advice for me on this?
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
https://premiersi.com