Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: jcottrill on December 20, 2017, 05:17:50 PM

Title: STREAMOUT in a FOR-LOOP
Post by: jcottrill 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   

Title: Re: STREAMOUT in a FOR-LOOP
Post by: BobO 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.
Title: Re: STREAMOUT in a FOR-LOOP
Post by: jcottrill on December 20, 2017, 06:47:45 PM
This worked perfectly BobO.  Thanks again for the help.
Title: Re: STREAMOUT in a FOR-LOOP
Post by: plcnut on December 20, 2017, 07:08:01 PM
I have done a lot of this just like BobO said.