NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling a command line interface with Teststand?

Hi. I am trying to control a USB high speed electrical test tool (HSETT) in a TestStand sequence. The test tool can be found here:

http://www.usb.org/developers/tools/

XHSETT 64-bit version

 

The HSETT executable has a GUI and a command line interface. I am attempting to run and control it with the CLI. I am able to succesfully start it using a "call executable" step by calling "XHSElectricalTestTool.exe" with a "/C" argument which starts the program using the CLI. Now after performing some other steps in my sequence, I need to send additional commands to the HSETT. To start with I am trying to send the "HELP" command to verify that it is working as expected.

 

I see that the "call executable" step has an option under "Wait Options" called "Store Process Handle." I expect I need to store the process handle in a variable and then use that process handle to send additinal commands to it, but I don't know how to do this. Is this the right approach, and if so, can you advise on how exactly to do this?

 

Thanks,

Philip.

0 Kudos
Message 1 of 8
(4,140 Views)

It depends how this HSETT executable was implemented. If they have something similar to the /useExisting argument that TestStand accepts, it will be pretty easy. If not, then you'll have to come up with a hack. The simple answer is this:

  1. Find out what commands you would type into cmd.exe to accomplish your goal
  2. Send the same commands from TestStand.

As for this:


@PhilipTI wrote:

 

I see that the "call executable" step has an option under "Wait Options" called "Store Process Handle." I expect I need to store the process handle in a variable and then use that process handle to send additinal commands to it, but I don't know how to do this. Is this the right approach, and if so, can you advise on how exactly to do this?

 


This is what i mean by hack. If it only accepts keyboard input, you could get the window handle and send keystrokes to it with the Windows API. To be clear, you would need to write code to do this and then call that code from TestStand. This is obviously not ideal.

 

I would recommend reaching out to your instrument vendor and seeing if they have an actual driver you can use.

 

Hope this helps!

Trent

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 2 of 8
(4,104 Views)

Thanks for the response Trent.

 

I did email the developers of the tool and it seems that there is no driver existing.

 

I attempted to launch the application with a pipe to the process's stdin by copying and modifying this sample code.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx

 

I am able to use that code to launch cmd.exe and send command to it through a pipe to stdin, so the code does work as expected. However it does not work for the HSETT application. It can lauch the HSETT CLI, but nothing happens when I attempt to send commands to the stdin pipe. It seems that the HSETT application either does not use stdin to accept commands, or it forks a new process which I don't have access to. I guess I will have to explore the hack option of getting the window handle and sending keystrokes to it.

0 Kudos
Message 3 of 8
(4,058 Views)

Here's my attempt at the hack. I'd call it risky at best:

  • It assumes that the correct window to send keys to is the Main Window
  • It assumes that Window will stay active. If that isn't the case, you'll be sending keystrokes to some other Window

Hope this helps!

Trent

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 4 of 8
(4,047 Views)

I did attempt my own keystrokes hack. I tested it with a notepad, cmd, and Chrome window, all working as expected. Strangely it does not work with the XHSElectricalTestTool.exe application. The command line window is brought to the foreground, but the text and enter keystrokes don't seem to do anything. I tested your sequence file and got the same result. There must be something different about the way this application accepts input which I don't understand.

0 Kudos
Message 5 of 8
(4,042 Views)

The only other thought I have is to use a tool like SPY++ to peek at the Process and see what window messages are being sent to it. There might be a hidden window that you need to get at.... at this point we're grasping at straws though.

 

If you're already in contact with the developers, see if they can share the source or provide a DLL interface instead.

 

-Trent

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 6 of 8
(4,034 Views)

I've been messing around with this some more and did manage to get the keystroke hack working. I needed to run Teststand as admin. Also, after bringing the HSETT window to foreground, I think Teststand was taking the foreground back again when it went to the next sequence step, so the keystrokes went to Teststand instead.

 

I created a C++ dll which will bring the window to foreground then send the keystrokes in one function call, so hopefully that should reduce the risk of something else taking foreground before the keystrokes are sent.

0 Kudos
Message 7 of 8
(3,993 Views)

Having to run TestStand as admin makes sense if the other application is in Program Files. Also, If you're already doing this in a C++ dll, you could try using SendMessage to send keystrokes to the specific window instead of whatever one is active. Once again, this may or may not work depending on how that app was developed.

 

Either way, i'm glad you got something working. 

 

-Trent

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 8 of 8
(3,980 Views)