News:

  • May 02, 2026, 08:11:03 PM

Login with username, password and session length

Author Topic: STREAMIN Serial in a stage  (Read 29532 times)

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
STREAMIN Serial in a stage
« on: January 16, 2013, 09:00:31 AM »
I am using a STREAMIN for a serial port on a H2-SERIO-4 in a stage. Does it tie up resources when I close the stage before the STREAMIN can complete (by recieving a delimiter or timing out)? Or is the STREAMIN instruction merely monitoring a buffer for data?

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

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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: STREAMIN Serial in a stage
« Reply #1 on: January 16, 2013, 09:47:45 AM »
The STREAMIN instruction must continue to execute until it completes (either successfully or in error).  Hence, you should keep its SG ENABLED until the STREAMIN is done.

If you jump out of a Stage prematurely, the "termination" of the Stage includes CANCELING the STREAMIN operation.  This "termination" is the same mechanism that turns OUT coils OFF when you transition out of a Stage.

This is one reason why we added the Jump To Stage options for the On Success and On Error events in asynchronous instructions like STREAMIN.  You don't HAVE to transition out of the stage when its done, but typically, the completion of an asyncronous operation like STREAMIN fits well in a typical stage-flow diagram.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: STREAMIN Serial in a stage
« Reply #2 on: January 16, 2013, 09:52:30 AM »
I may have mis-understood your question.  Yes, you CAN JMP out (or SGRST or even EXIT/HALT the PROGRAM code-block that contains the Stage containing the STREAMIN), and the STREAMIN instruction will properly "terminate" and clean up any resources it was using (specifically the serial port).

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: STREAMIN Serial in a stage
« Reply #3 on: January 16, 2013, 11:05:24 AM »
I may have mis-understood your question.  Yes, you CAN JMP out (or SGRST or even EXIT/HALT the PROGRAM code-block that contains the Stage containing the STREAMIN), and the STREAMIN instruction will properly "terminate" and clean up any resources it was using (specifically the serial port).

Thanks Franji1, This is what I needed to know. In my testing it does set an error whenever I JMP out of that stage, but I can live with that.
Circumstances don't determine who we are, they only reveal it.

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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: STREAMIN Serial in a stage
« Reply #4 on: January 16, 2013, 11:35:31 AM »
However, the physical port may continue to receive characters from the remote device, so you want to do a DEVCLEAR to flush any "straggling characters" if you ever "prematurely" cancel a STREAMIN.  There is also an option on a STREAMOUT to "Flush INPUT Device First".

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: STREAMIN Serial in a stage
« Reply #5 on: January 16, 2013, 11:41:47 AM »
I think this has already been explained...but...a triggered STREAMIN should complete normally before leaving the stage that it is in. We added some exception handling that will clean it up if you do not let it finish, but that really is bad form and will give you a warning, which is what you are seeing.

As for resources, yes, the instruction locks the device and holds it until complete. This is what eliminates the external interlocking that used to be a big issue with DL CPUs.
"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: 814
    • premiersi.com
Re: STREAMIN Serial in a stage
« Reply #6 on: January 16, 2013, 07:55:04 PM »
I have a device that may take 2 seconds to respond, or it may take only 400msec. to respond, all depending upon a variable conveyor speed. How do I properly terminate a streamin that needs to have a variable timeout?
Circumstances don't determine who we are, they only reveal it.

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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: STREAMIN Serial in a stage
« Reply #7 on: January 16, 2013, 08:24:27 PM »
If you know the speed immediately before needing to use the STREAMIN, you will need to use two instances of the STREAMIN instruction. One speed use the "fast" STREAMIN, the other uses the "slow" STREAMIN.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: STREAMIN Serial in a stage
« Reply #8 on: January 16, 2013, 09:08:10 PM »
Simple. Don't invoke the STREAMIN until the data is available. Look in the port device's structure. There is a member that contains the number of bytes currently in the input queue. Wait for one or more bytes to show up, applying whatever timing control you wish in that logic, then invoke the STREAMIN after the data is coming in. I rarely use the built in timeout for protoccol timing...I normally verify that the data I'm expecting is already available before I call 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: 814
    • premiersi.com
Re: STREAMIN Serial in a stage
« Reply #9 on: January 17, 2013, 07:39:53 AM »
Thank you Bobo!

I remembered seeing that you did that in the HttpGET example, but had since forgot about it. You guys thought of about everything! I will make the change to my program this morning and see how it goes.
Thanks again.  ;D
Circumstances don't determine who we are, they only reveal it.

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

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: STREAMIN Serial in a stage
« Reply #10 on: January 17, 2013, 10:43:44 AM »
What about OPENDEV and CLOSE with a serial device? Do I need to open and close my serial port?
It works fine and I haven't programmed an OPENDEV for the port, so why and when are these instructions necessary?
Circumstances don't determine who we are, they only reveal it.

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

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6154
  • Yes Pinky, Do-more will control the world!
Re: STREAMIN Serial in a stage
« Reply #11 on: January 17, 2013, 10:50:42 AM »
You do not.

OPENDEV is for creating a device handle...an indirect reference to a device...for cases where you would like to develop a protocol in a generic way and then specify the device at runtime.

CLOSE is for closing any device opened with an OPENXXX call like OPENDEV, OPENTCP, or future handle centric devices like files.
"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: 814
    • premiersi.com
Re: STREAMIN Serial in a stage
« Reply #12 on: January 17, 2013, 02:09:26 PM »
Cool, Thanks Bob.
Circumstances don't determine who we are, they only reveal it.

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