Being a newbie on TestStand I've tried to use my Google-fu skills to solve this problem but it seems as my Google-fu skills does not help me in finding the answer to this question. Hopefully any of you knowledgeable guys know.
(Please note that my company still uses TS2012 so any fancy solutions using TS2019 won't work for me.... Sorry)
Anyway, here are my thoughts and first attempt :
I have a hardware button that needs to be tested. The operator is shown a UI and asking them to press that physical button. I also have a sequence that reads the state of the physical button so I know when the button is pressed and released. So far so good!
Now, I want the operator be able to cancel the process if the button for some reason does not work. The operator should then press the Cancel button in the UI.
In my subsequence I've started a thread (Use New Thread) and I have saved a reference to it. This thread looks at the status of the button (by polling) if it has been pressed and then released.
Directly after I've started another thread which displays the User Interface asking the operator to press the physical button. The user interface has a Cancel button to it so that the operator can cancel the process if the physical button does not work.
After these two threads have been started I thought of using the Wait statement to check if one of the two threads are signaled that they are done. (Either the physical button worked or the user gave up and pressed the Cancel button in the UI)
However, the Wait only takes a reference to one thread and I can't get my head around how to accomplish to wait for the first thread that is done and thus either say that the test was successful (and close the UI) or say that the test failed (operator pressed Cancel).
(Being a C# programmer this is a fairly trivial task in C# IMHO)
Where do I go wrong ? It there a better way ? Should I do this differently in some way ?
Thanks for your help !
I just realized that you could have two (or more I guess references) in the Wait.. Just separate them by comma... 😀
Now the next issue will be how to gracefully end the thread that did not get signaled.... I assume that there is some kind of Abort method....
Why are you trying to separate them into different threads in TestStand? I would have a single code module that displays the UI telling the user to press the button. Inside of that module I would poll the button and have an event for the cancel button. Either would trigger the UI to complete and return what was read from the button (either good or bad). Then in TestStand analyze to see if it passed. You could even put a timeout on there if needed.
This is a very common thing to do. I do it all the time. Especially when reading from a buffer from a UUT.
You yourself said this was trivial in C#. Don't complicate it.
Thanks Jigg for your answer 👍
My confusion if probably a result from bing a newbie on TS...
I used the "Show Popup" (not having it Modal) and I was under the impression that this call is blocked until the user closes it (by for example pressing a button named Cancel).
Due to this "blocking" I was thinking that I needed a separate thread to process the polling.
But if you say that this is not the case, there is definitively something I missed...
Back to the drawing board for me again I guess !
I may have misunderstood what you were doing. I didn't realize you were using the message popup step to display to the user. If so then multithreading in TestStand is needed.
I was probably a bit unclear in my description of what I wanted to achieve. 😔
I was under the impression that the popup message box is the only way (except for calling an external dll with a message handler) to show a dialog with user interaction.
Anyway, I'll pursue with my threading idea as it seems to be the only viable solution, but if anyone has alternative solutions / suggestions or a good code snippet I'm obviously interested ! 🙂
Regarding Waiting for multiple threads....
Even though you could supply multiple references it just seems to look at the last one. I've also tried an array of object references but this this is not valid as a parameter.
This seems like a "Houston, we have a problem" kind of situation.... 😰
If you want to try a different approach than waiting you could easily do this with the built in Notifiers. Just have each thread issue a Notification saying if they are done, and make sure they are looking for each other. I created a simple example that should run in 2012 (at least I saved it in that version). You could look at it to get ideas. It's setup to start a loop imitating button polling. The loop will last for 10 seconds. If you press cancel on the popup before 10 seconds, then both threads stop. If the button is detected it will close the popup.
One thing I had to do was make the popup run in a "New Execution" instead of a "New Thread". That way it was easier to close the popup if the button worked, and I wanted to programmatically kill the popup.
I originally did it with Queues, but Notifiers make more sense. That's why the sequence file is called what it is, and some of the comments say Queue ha.