Esempio n. 1
0
////////////////////////////////////////////////////////////////////selfdefined function//////////////////////////////////////
static int ExecutableProcess(char *cmd, char *checkpoint)
{
	 FILE    *hFile;
    char    buffer[300]; // long enough for single line of output from ipconfig
    char    tempFileName[L_tmpnam];
    char    command[L_tmpnam + 25];
    int     hProc;
   
    int     res=0;  int checkflag = 0; 
    
    tmpnam(tempFileName);
    sprintf(command, "cmd.exe /C %s > %s", cmd,tempFileName); 
//     sprintf(command, "cmd.exe /C %s", cmd);
 //   if (LaunchExecutableEx(command, LE_SHOWNORMAL, &hProc) >= 0)
	if (LaunchExecutableEx(command, LE_HIDE, &hProc) >= 0)   
    {
		SetLed("running...please wait...",0);
		ProcessSystemEvents ();   
		WriteLog();
		ResetTextBox (panelHandle, PANEL_TEXTBOX, "");    
        while (!ExecutableHasTerminated(hProc));
		{
        	RetireExecutableHandle(hProc);
		}
    
        if (hFile = fopen(tempFileName, "r"))
        {
            while (fgets(buffer, (int)sizeof(buffer), hFile))
            {
               
				SetCtrlVal (panelHandle, PANEL_TEXTBOX, buffer); 
				if (!checkflag)
				{
					if(NULL != strstr (buffer, checkpoint))
					{
						checkflag = 1;
						res = 1;
					}
				}
            }
            fclose(hFile);
        //    DeleteFile(tempFileName);
			remove (tempFileName);
        }
    }
	return res;
}
Esempio n. 2
0
void KillSubprocess(void)
{
    char    command[300];
    int     hProc;

    
	memset(command,0,300);
	strcpy(command,"cmd.exe /C TASKKILL /F /IM RemoteAction.exe");
	if (LaunchExecutableEx(command, LE_HIDE, &hProc) >= 0)   
    {
		WriteLog();
        while (!ExecutableHasTerminated(hProc));
		{
        	RetireExecutableHandle(hProc);
		}
    }
}
/*****************************************************************************
  FUNCTION NAME          : CviVeristandOpen
  DESCRIPTION            : Creates New Veristand objects, obtains handle(s) to object(s). 
  PARAMETERS DESCRIPTION : 
  						 : 
						 : C:\Users\Public\Documents\National Instruments\NI VeriStand 2011\Examples\Stimulus Profile\Engine Demo\Engine Demo.nivssdf 
						 : 
						 : 
  						 : pcBuffer:  Returns name of call that failed.
  Return Value           : HRESULT:  0 = Success, Negative = Failure
******************************************************************************/
int CviVeristandOpen()
{

	int Hstatus = 0;
	char	cdescription[300];
	const char *pcdescription;
	static int                                  error = 0;

	pcdescription = cdescription;
	
	LaunchExecutableEx (VSfilename, LE_SHOWNORMAL, &VSHandle);
	//Delay (5.5);
	
//	Hstatus = Initialize_NationalInstruments_VeriStand ();
//	if (Hstatus != 0 ) { strcpy	(pcBuffer, "Initialize_VeriStand"); goto Error; }

//	Hstatus = Initialize_NationalInstruments_VeriStand_APIInterface ();
//	if (Hstatus != 0 ) { strcpy	(pcBuffer, "Initialize_APIInterface"); goto Error; }
		 
	Hstatus = Initialize_NationalInstruments_VeriStand_ClientAPI ();
	if (Hstatus != 0 ) { strcpy	(pcBuffer, "Initialize_ClientAPI"); goto Error; }

	Hstatus = NationalInstruments_VeriStand_ClientAPI_Factory__Create (&instance_handle, &exception_Handle);
	if (Hstatus != 0 ) { strcpy	(pcBuffer, "ClientAPI_Factory_Create"); goto Error; }
	
	Delay (1.5);
	
	//Test of VS startup
	
	for (int i = 1; i <= 50; i++) 
	{

		Hstatus = NationalInstruments_VeriStand_ClientAPI_Factory_GetIWorkspace2 (instance_handle,
															&VSworkspace2_Handle,&exception_Handle);
		if (Hstatus == 0) break;
		Delay (1);
	
	}
	
	
	Hstatus = NationalInstruments_VeriStand_ClientAPI_Factory_GetIWorkspace2 (instance_handle,
															&VSworkspace2_Handle,&exception_Handle);
	if (Hstatus != 0 ) { strcpy	(pcBuffer, "ClientAPI_Factory_GetIWorkspace2"); goto Error; }
	
	Hstatus = NationalInstruments_VeriStand_ClientAPI_Factory_GetIChannelFault (instance_handle,
															&VSchannelfault_Handle,&exception_Handle);
	if (Hstatus != 0 ) { strcpy	(pcBuffer, "ClientAPI_Factory_GetIChannelFault"); goto Error; }

	return Hstatus;
	
Error:
       // Handle error
        sprintf(cdescription, "Error (%d): %s\n", error, CDotNetGetErrorDescription(error));
		printf(cdescription);
		strcat(pcBuffer,cdescription);
        if(Hstatus <0)
	{
		if (exception_Handle)
	       	 {
			char * exceptionMessage = 0;
			char * source = 0;
			char * stack_trace = 0;
	            		CDotNetGetExceptionInfo(exception_Handle, 0, &exceptionMessage, &source, &stack_trace, 0, 0);
			sprintf(cdescription,"Exception: %s\n", exceptionMessage); 
			printf(cdescription);
			if (POPUPDEBUGDLL) MessagePopup ("CVI DLL",cdescription);			
			fprintf(stderr, "Source: %s\n", source);
			fprintf(stderr, "Stack Trace: %s\n\n", stack_trace);              
	            		CDotNetFreeMemory(exceptionMessage);
	       	 }
	}	

return Hstatus;
}