Hi. I have been working on an XOP that calls an executable program which in turn speaks to some hardware. The .exe file is called and the cmd window comes up for the duration of how long the hardware runs for. During this time the Igor window becomes frozen, and "Not responding" when I check it's status in the Task Manager. Then once the process is complete, my Igor environment goes back to normal. Does anyone have any suggestions or ideas that could possibly allow for me to keep using Igor while the process is going on?
Any help much appreciated,
I presume you are launching the .exe by calling the Windows CreateProcess routine. You then call GetExitCodeProcess in a loop until the process terminates.
If this is what you are doing, you are monopolizing Igor's main thread so Igor does not get a chance to run.
Instead, call CreateProcess and return to Igor. Then call GetExitCodeProcess when you receive an IDLE message from Igor.
Note that you will receive an IDLE message from Igor only when Igor is idling (not running a user procedure or built-in operation or function) or if a user procedure calls the DoXOPIdle operation to give time to XOPs.
Alternatively or in addition to using the IDLE message, you can create an operation or function in the XOP which, when called, calls GetExitCodeProcess. Then a user procedure would need to call either DoXOPIdle or your operation or function to allow you to check if the .exe has finished.
Well actually I am calling a batch file from the XOP (using the (void)system(//batchfile name) call) and just running the .exe from the batch file directly by "CALL //pathname".
Does this affect Igor's main thread in the same way?
I'm guessing yes, because the XOP will wait until the batch file finishes (unless you can run in the background in windows). Just as a matter of interest, what hardware are you speaking to?
Do you have to use an executable?
Can the hardware be controlled by a DLL?
Can the hardware be controlled via TCP/IP, RS232?
-OR-
create a thread inside your XOP (http://sourceware.org/pthreads-win32/) that you can create, inside which you call your system command, but will die by itself when your system call returns. However, it's harder to know if the command has finished and it's return code.
-OR-
can you use the ExecuteScriptText operation within IGOR.
Thanks for your help, How would I run in the background in Windows? Do you think I should attempt the first thing mentioned by hyrodstein or try and run the executable in the background in Windows?
I can't find documentation on the "system" routine. If it has a flag that tells it to return immediately (not wait for the call to finish), then you can try that.
Otherwise I would try using the CreateProcess call. Start by reading that documentation and perhaps looking for example code using it.
If you want to know when the .exe finishes, next try calling GetExitCodeProcess.
There may be other ways to do this but this is the way I am familiar with.
Sorry I didnt see the rest of your message before, thanks for all the suggestions.
Well the hardware comes with a .cpp file that controls it and it's values, so basically I am trying to run that. In the past I had an ExecuteScriptText from within an IPF and Igor was also freezing, because it was still opening the cmd window. I am not sure if the hardware can be controlled by DLL or TCP/IP, RS232.
I've looked at some of those links and it seems that there are API's to control your hardware. For example, this link http://spincore.com/support/spinapi/reference/production/2010-12-03/ind… shows how to control hardware from a normal C program. If you have some C experience it should be straightforward to use this API to control your hardware using an XOP to call the functions contained in their code.
My guess is that the hardware came with a pre-compiled program to control it and you're trying to use that.
Hmm, how strange, I have just incorporated the SpinAPI calls and methods into my XOP, and Igor is still Not Responsive during the running of the SpinCore.
Do you think the only thing left to do is to attempt the different threading processes?
Hmm, how strange, I have just incorporated the SpinAPI calls and methods into my XOP, and Igor is still Not Responsive during the running of the SpinCore.
Do you think the only thing left to do is to attempt the different threading processes?
If you run IGOR from the debugger supplied with your Compiler does the SpinAPI call return immediately, or does it not return until the scan has finished running? If it does not return immediately is there an asynchronous function that you can call (returns immediately, pick up the data later)? If not, then you will probably have to create a thread, either in IGOR or in the XOP. Either is not too difficult.
If this is what you are doing, you are monopolizing Igor's main thread so Igor does not get a chance to run.
Instead, call CreateProcess and return to Igor. Then call GetExitCodeProcess when you receive an IDLE message from Igor.
Note that you will receive an IDLE message from Igor only when Igor is idling (not running a user procedure or built-in operation or function) or if a user procedure calls the DoXOPIdle operation to give time to XOPs.
Alternatively or in addition to using the IDLE message, you can create an operation or function in the XOP which, when called, calls GetExitCodeProcess. Then a user procedure would need to call either DoXOPIdle or your operation or function to allow you to check if the .exe has finished.
February 8, 2011 at 09:05 pm - Permalink
Does this affect Igor's main thread in the same way?
February 8, 2011 at 09:19 pm - Permalink
Do you have to use an executable?
Can the hardware be controlled by a DLL?
Can the hardware be controlled via TCP/IP, RS232?
-OR-
create a thread inside your XOP (http://sourceware.org/pthreads-win32/) that you can create, inside which you call your system command, but will die by itself when your system call returns. However, it's harder to know if the command has finished and it's return code.
-OR-
can you use the ExecuteScriptText operation within IGOR.
February 8, 2011 at 10:14 pm - Permalink
It's a device that sends out radiowave pulses (http://www.spincore.com/).
February 8, 2011 at 10:12 pm - Permalink
Otherwise I would try using the CreateProcess call. Start by reading that documentation and perhaps looking for example code using it.
If you want to know when the .exe finishes, next try calling GetExitCodeProcess.
There may be other ways to do this but this is the way I am familiar with.
February 8, 2011 at 10:28 pm - Permalink
Well the hardware comes with a .cpp file that controls it and it's values, so basically I am trying to run that. In the past I had an ExecuteScriptText from within an IPF and Igor was also freezing, because it was still opening the cmd window. I am not sure if the hardware can be controlled by DLL or TCP/IP, RS232.
February 8, 2011 at 10:30 pm - Permalink
February 8, 2011 at 11:55 pm - Permalink
And this is the Spincore which contains the radio processor. http://www.spincore.com/CD/iSpin/iSpinManual.pdf
February 9, 2011 at 03:21 pm - Permalink
My guess is that the hardware came with a pre-compiled program to control it and you're trying to use that.
February 9, 2011 at 05:06 pm - Permalink
Do you think the only thing left to do is to attempt the different threading processes?
February 14, 2011 at 09:37 pm - Permalink
If you run IGOR from the debugger supplied with your Compiler does the SpinAPI call return immediately, or does it not return until the scan has finished running? If it does not return immediately is there an asynchronous function that you can call (returns immediately, pick up the data later)? If not, then you will probably have to create a thread, either in IGOR or in the XOP. Either is not too difficult.
February 14, 2011 at 09:45 pm - Permalink