LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

system exec vi to run/stop file depending on conditions

Hello

 

I would like to use the system exec vi to run a file and stop the file depending on conditions.

 

I have an exe file written in C# that makes a force feedback joystick to vibrate. I used the command line in exec vi to run the file and it works. Now I to open/close the file depending on the conditions. In the picture, there is a small square box which is where I want the joystick's cursor to be. Whenever the cursor goes outside the box, I want the labview to run the exe file(vibrates joystick). When the cursor comes back inside the box, I want exe file to close(turn off vibration).

 

Is it possible to do this using the system exec vi? If yes, can you guide me through it? I don't know what to do with the error in/out, etc. If no, do you know another way to do this? I tried making a DLL file and using constructor/invoke nodes but one guy told me that I have rewrite the code becaues the all the code is written under one class and I need to separate it into many classes to call each functions in labview. However, I showed the code to C# guy and he told me that I cannot separate the code because it's written as windows form...

 

Thank you!

0 Kudos
Message 1 of 6
(3,619 Views)

Your thinking in terms of DLL calls makes the most sense. If there are simply two functions such as StartVibration() and StopVibration(), you should be able to call those from LabVIEW. I'm not sure if your C# guy fully understands the issue, but without seeing the C# code I can't comment.

 

My second go to method if DLLs are unavailable is to setup a local network connection between two bits of software. It's as simple as opening a network port and sending a message through from LabVIEW to the external program, and then having the program parse and act on it. Again I'm not sure if your C# guy would approve.

 

In this case you can use the System Exec VI to call the Windows command line function taskkill. This command will kill a named process. For example:

 

cmd /c taskkill /IM notepad.exe

 

 

This will send a message to notepad.exe to shutdown. If you want/need to forcibly stop a process, use the /F option:

 

cmd /c taskkill /F /IM notepad.exe

 

 

Note in both of the examples they begin with cmd /c. This is necessary when making command line calls using the System Exec VI (see the help for info).




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
0 Kudos
Message 2 of 6
(3,591 Views)

Hello Michael,

 

Thank you for your response. I will try the taskkill tomorrow. I heard the phone notification and got out of the bed to attach the c# code.

Oh and the C# guy is just a person who responded to another forum page.

0 Kudos
Message 3 of 6
(3,578 Views)

I just decided to do it now. I tried it taskkill but doesn't work.

Are you saying that I need to have two system exec vi's, one for openning the exe file and another for closing the opened file? How can I do that I tried to add more system exec vi but it uses same command line as the first one.

 

cmd /c "C:\file location\effect.exe" this opens up the exe file and vibrates the joystick. I tried adding taskkill

 

ex. cmd /c taskkill "C:\file location\effect.exe", cmd /c "taskkill C:\file location\effect.exe", cmd /c taskill C:\file location\effect.exe

but none of those worked.

0 Kudos
Message 4 of 6
(3,568 Views)

Yes, you'll need two system exec VIs. One to start the vibration and one to stop it. The way you're calling taskkill isn't quite right. See the example below:

 

system_exec.png

 

In your case the closing command will be cmd /c taskkill /IM effect.exe




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
0 Kudos
Message 5 of 6
(3,545 Views)

I talked to my friend and he told me that I have to use string and boolean on this. I just double clicked the vi and typed the command line in there, so that was why it wasn't working + I thought "IM" was part of the notepad file name, so I didn't include that on mine.

 

Thank you for the example. Unfortunately, I didn't bring the joystick home today, so I cannot test it T.T

 

0 Kudos
Message 6 of 6
(3,513 Views)