Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: plcnut 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?
-
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.
-
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).
-
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.
-
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".
-
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.
-
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?
-
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.
-
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.
-
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
-
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?
-
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.
-
Cool, Thanks Bob.