News:

  • August 19, 2026, 08:15:41 PM

Login with username, password and session length

Author Topic: STREAMOUT in a FOR-LOOP  (Read 7679 times)

jcottrill

  • Full Member
  • ***
  • Posts: 43
STREAMOUT in a FOR-LOOP
« on: December 20, 2017, 05:17:50 PM »
I have been using plcnut's web server code he provided to handle HMI functions and JSON requests.  It is working great with a few tweaks for my situation.  In one of the requests I need to serve, the JSON string I will return will be based on the number of elements filled in a memory block and could be anywhere from 200 to 15,000 chars in length.   I'd like to build the web response on the fly and send out each ~1,024 char block in a for loop.  Below is some rough pseudo code of what I have in my stage.  Unfortunately only the first block is sent.  I am guessing I need to do something to make sure the TCP device I am streaming to isn't still working on the prior request but am not sure.  I am hoping one of you can point me in the right direction or show me where I am being dumb.  Thanks in advance.

Code: [Select]

for(i = 0; i < numRecords; i++)
    curBlock = "{ id: i, state: 'Running', description: 'lorem ipsum...',...}"; 
    streamout(curBlock);
next   


BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: STREAMOUT in a FOR-LOOP
« Reply #1 on: December 20, 2017, 06:18:39 PM »
I only have a couple of minutes to answer, but look at the stage transition logic at the bottom of the STREAMOUT instruction...where it says "On Success" and "On Error". Build your loop out of stages and use the instruction to transition to the next loop iteration.
"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

jcottrill

  • Full Member
  • ***
  • Posts: 43
Re: STREAMOUT in a FOR-LOOP
« Reply #2 on: December 20, 2017, 06:47:45 PM »
This worked perfectly BobO.  Thanks again for the help.

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: STREAMOUT in a FOR-LOOP
« Reply #3 on: December 20, 2017, 07:08:01 PM »
I have done a lot of this just like BobO said.
Circumstances don't determine who we are, they only reveal it.

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