Esempio n. 1
0
int CVIFUNC mouth_OutBufferCommand (dnaBufferRF*buffer)
{
	int l;
	int err=0;
	require(0<buffer->CommandCounter);
	l = dna_LengthBufferRF (buffer);
	if (l) {
//		ibwrt (gpibDS345, buffer->Buffer+buffer->PosByte, l);
		ibwait (gpibDS345, 0);					// re-synch
		if (ThreadIbsta() & ERR)
			return -2;							// TODO BUG GOTCHA : make more verbose
//		errChk(mouth_Error("mouth_WriteDS345{ibwait call failed}",0,0));
		ibwrta (gpibDS345, buffer->Buffer+buffer->PosByte, l);
		if (ThreadIbsta() & ERR)
			return -3;
//		err = mouth_Error("mouth_WriteDS345{ibwrta call failed}",0,0);
#if VERBOSE > 1
		printf("%s\n",&buffer->Buffer[buffer->PosByte]);
		if (err)
			printf("mouth_OutBufferCommand{ibwrt call failed} %d %d %d %d %d\n",
				buffer->PosByte,buffer->PosCommand,ERR,ThreadIbsta(),ThreadIberr());
#endif
		if (err) goto Error;
		errChk(dna_AdvanceRunBufferRF (buffer));
	}
	else {
		errChk(dna_AdvanceRunBufferRF (buffer));
#if VERBOSE > 0
		printf("mouth_OutBufferCommand{Length was zero} %d %d\n",
				buffer->PosByte,buffer->PosCommand);
#endif
	}
Error:
	return (err?-1:0);
}
Esempio n. 2
0
int CVIFUNC mouth_AddBufferCommand (dnaBufferRF*buffer, double amp, double freq)
// Takes frequency in MHz, Ampl Vpp
{
	int err=0;
	if (freq!=LastFreq)
		if (amp!=LastAmp) {
			LastAmp=amp;
			LastFreq=freq;
			freq*=1000000.0;			// Convert to Hz
			Fmt(&buffer->Buffer[buffer->PosByte],"%s<AMPL %fVP;FREQ %f",amp,freq);
#if VERBOSE > 1
			printf("%s\n",&buffer->Buffer[buffer->PosByte]);
#endif
			// Order of the next two commands is important 
			buffer->NumberOfCommands++;
			errChk(dna_AdvanceBufferRF (buffer));
		}
		else
			errChk(mouth_AddBufferFreq(buffer,freq));
	else
		if (amp!=LastAmp)
			errChk(mouth_AddBufferAmp(buffer,amp));
		else {
			buffer->Buffer[buffer->PosByte]=0;
			// Order of the next two commands is important 
			buffer->NumberOfCommands++;
			errChk(dna_AdvanceBufferRF (buffer));
		}			
Error:
	return (err?-1:0);
}
Esempio n. 3
0
int CVIFUNC mouth_WriteDS345 (const char command[], int numberofBytes)
{
 	int err=0;

//	ibwrt (gpibDS345, command, numberofBytes);
	ibwait (gpibDS345, 0);					// re-synch
	errChk(mouth_Error("mouth_WriteDS345{ibwait call failed}",0,0));
	ibwrta (gpibDS345, command, numberofBytes);
	errChk(mouth_Error("mouth_WriteDS345{ibwrta call failed}",0,0));
Error:
	return (err?-1:0);
}
int __declspec(dllexport) __stdcall EditClassPath(CAObjHandle context)
{
    int         error       = 0;
    int         canceled    = 0;                      
    ERRORINFO   errorInfo;
    ErrMsg      errMsg      = "";
    CAObjHandle stepH       = 0;
    CAObjHandle seqFileH    = 0;
    TSModalData modalData   = InitialModalData;

    // Save the context for later reference
    seqContext = context;
  
    // Load the UI panel
    if ((panelHandle = LoadPanelEx (0, "JavaCall.uir", PANEL, __CVIUserHInst)) < 0)
        return -1;

    // Get current step object from sequence context
    tsErrChk(TS_SeqContextGetStep (context, &errorInfo, &stepH));
    
    // Transfer class path from properties of the Java step to the CVI user interface
    tsErrChk(TS_SetCtrlToPropertyVal (stepH, "ClassPath", panelHandle, PANEL_JAVA_CLASSPATH));

    // Start the UI
    tsErrChk (TS_StartModalDialog(context, &errorInfo, &modalData));
    errChk (InstallPopup (panelHandle));
    errChk (canceled = RunUserInterface());

    if (!canceled) 
    {
        TS_SetPropertyToCtrlValEx (panelHandle, PANEL_JAVA_CLASSPATH, stepH, "ClassPath", errMsg);
        // Update the sequence file change count
        TS_SeqContextGetSequenceFile (context, &errorInfo, &seqFileH);
        tsErrChk(TS_SeqFileIncChangeCount (seqFileH, &errorInfo));
    }

Error:  

    // Discard the panels loaded 
    if (panelHandle > 0)
        TS_EndModalDialogAndDiscard (&errorInfo, &modalData, panelHandle);
    
    if (stepH)
        CA_DiscardObjHandle (stepH);
    if(seqFileH)
        CA_DiscardObjHandle (seqFileH);

    // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if (error < 0)
        TS_SetStepError(context, error, errMsg);     
        
    return error;
}
Esempio n. 5
0
int CVIFUNC mouth_ZeroDS345 (void)
{
 	int err=0,l;
	char *command;

	mouth_MakeIdleCommand(&command,0.0,0.0,0.0);
	l=strlen(command);
//	ibwrt (gpibDS345, "OFFS, numberofBytes);
	ibwait (gpibDS345, 0);					// re-synch
	errChk(mouth_Error("mouth_ZeroDS345{ibwait call failed}",0,0));
	ibwrta (gpibDS345, command, l);
	errChk(mouth_Error("mouth_ZeroDS345{ibwrta call failed}",0,0));
Error:
	return (err?-1:0);
}
int CVI_YGraphPopup(struct IDispatch *engineDisp, char* title, double* numArray, unsigned int numElements) 
{
    int             error = 0;
    ERRORINFO       errorInfo;
    ErrMsg          errMsg = "";    
    TSModalData     modalData = INITIAL_MODAL_DATA;
    CAObjHandle     engine = 0;
    
    tsErrChk(CA_CreateObjHandleFromIDispatch (engineDisp, 0, &engine));
    // NOTE: For CVI Dialogs we must use the tsutil TS_StartModalDialog
    // and TS_EndModalDialog functions instead of using the Engine class
    // methods NotifyStartOfModalDialog and NotifyEndOfModalDialog
    // directly.
    tsErrChk(TS_StartModalDialog(engine, &errorInfo, &modalData));
    errChk(YGraphPopup(title, numArray, numElements, VAL_DOUBLE));

Error:

    TS_EndModalDialog(&errorInfo, &modalData);
    
    // NOTE: don't call CA_DiscardObjHandle on the engine
    // because it was passed in as a parameter and we didn't
    // add a reference to it with CA_CreateObjHandleFromIDispatch.
    return error;
}
void __declspec(dllexport) __stdcall Test(CAObjHandle seqContextCVI,  
    CAObjHandle thread,  short *errorOccurred,  long *errorCode,  char errorMsg[1024])
{
    double      currentTime, startTime, timeLimit = 8;      // in seconds 
    ERRORINFO   errorInfo;
    int         error = 0;
    char        statusMessage[512];
    CAObjHandle execution = 0;
    int         quit = FALSE;
    ErrMsg      errMsg = {'\0'};

        // Get the execution
    tsErrChkMsgPopup(TS_SeqContextGetExecution(seqContextCVI, &errorInfo, &execution));

    startTime = currentTime = Timer();
    while ((currentTime - startTime ) < timeLimit) 
        {
        errChk(CheckForUserTermination(execution, &quit));
        if (quit)
            break;
            
            // Update percent complete progress bar         
        tsErrChk(TS_ThreadPostUIMessage(thread, &errorInfo, TS_UIMsg_ProgressPercent, ((currentTime-startTime) * 100) / timeLimit, "", VTRUE));     
        
            // Display percent finished in Status Bar, in increments of 10   
        sprintf(statusMessage,"%d percent finished", 10 * RoundRealToNearestInteger(((currentTime-startTime) * 10) / timeLimit));
        tsErrChk(TS_ThreadPostUIMessage(thread, &errorInfo, TS_UIMsg_ProgressText, 0, statusMessage, VTRUE));

            // Simulate running test 
        Delay(1);      
        currentTime = Timer();
        }
    
    if (!quit)
        {
            // Display test complete message in the message bar             
        tsErrChk(TS_ThreadPostUIMessage(thread, &errorInfo, TS_UIMsg_ProgressText, 0, "Test Finished", VTRUE));
    
            // Display percent complete progress bar - 100% complete                                                
        tsErrChk(TS_ThreadPostUIMessage(thread, &errorInfo, TS_UIMsg_ProgressPercent, 100, "", VTRUE));
        }

Error:
    CA_DiscardObjHandle(execution);
    
        // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if (error < 0)
        {
        *errorOccurred = TRUE;
    
        *errorCode = error;
        strcpy(errorMsg, errMsg);
        }
}
void create_patterns(char *pattern_file,int no_of_exemplars)
{
    FILE *fp;
    float val;
    int setNo;

    if (!strlen(pattern_file) || !no_of_exemplars) 
	return; /* shortcut of no patterns */

    /*  create patterns with datas from pattern_file */
       
    if((fp=fopen(pattern_file,"r"))!=NULL){
	ret = krui_allocNewPatternSet(&setNo);
	errChk( ret );
	for (j = 1; j <= no_of_exemplars; j++){
	    for (i = 1; i <= IUnits; i++){
		ret = krui_setCurrentUnit(i);
		errChk( ret );
		fscanf(fp,"%s",string);
		val=atof(string);
		krui_setUnitActivation(i,val);
	    }
	    ret = krui_newPattern();
	    errChk( ret );
	}
    } else {
	printf("\n Pattern file %s could not be opened!\n",pattern_file);
	exit(1);
    }
    fclose(fp);
 
    printf("\nFilename of patterns to save: ");
    scanf("%s", name);
    strcat(name,".pat");
    printf("Save Patterns\n");

    /*  save the patterns  */

    ret = krui_saveNewPatterns( name, setNo );
    errChk( ret );
} /* end of create_patterns */
Esempio n. 9
0
int CVIFUNC mouth_InitRF (void)
// Same for all the GPIB modes
{
	int err=0;
	// We only need to do this once
	if (-1==gpibDS345)
		gpibDS345 = ibdev (0, gpibDS345Addr, NO_SAD, T3s, 1, 0);
	errChk(mouth_Error("mouth_InitRF{ibdev call failed}",0,0));
	LastAmp=NoValue;
	LastFreq=NoValue;
Error:
	return (err?-1:0);
}
Esempio n. 10
0
int CVIFUNC mouth_AddBufferAmp (dnaBufferRF*buffer, double amp)
{
	int err=0;
	Fmt(&buffer->Buffer[buffer->PosByte],"%s<AMPL %fVP",amp);
#if VERBOSE > 1
	printf("%s\n",&buffer->Buffer[buffer->PosByte]);
#endif
	// Order of the next two commands is important 
	buffer->NumberOfCommands++;
	errChk(dna_AdvanceBufferRF (buffer));
	LastAmp=amp;
Error:
	return (err?-1:0);
}
Esempio n. 11
0
int CVIFUNC mouth_AddBufferFreq (dnaBufferRF*buffer, double freq)
{
	int err=0;
	LastFreq=freq;
	freq*=1000000.0;					// Convert to Hz
	Fmt(&buffer->Buffer[buffer->PosByte],"%s<FREQ %f",freq);
#if VERBOSE > 1
	printf("%s\n",&buffer->Buffer[buffer->PosByte]);
#endif
	// Order of the next two commands is important 
	buffer->NumberOfCommands++;
	errChk(dna_AdvanceBufferRF (buffer));
Error:
	return (err?-1:0);
}
Esempio n. 12
0
int CVIFUNC mouth_AddBufferZero (dnaBufferRF*buffer)
{
	int err=0;
	LastAmp=0.0;
	LastFreq=0.0;
	Fmt(&buffer->Buffer[buffer->PosByte],"%s<AMPL %fVP;FREQ %f",0.0,0.0);
#if VERBOSE > 1
	printf("%s\n",&buffer->Buffer[buffer->PosByte]);
#endif
	// Order of the next two commands is important 
	buffer->NumberOfCommands++;
	errChk(dna_AdvanceBufferRF (buffer));
Error:
	return (err?-1:0);
}
Esempio n. 13
0
int ReleaseAllDataPackets (SinkVChan_type* sinkVChan, char** errorMsg)
{
INIT_ERR
	
	DataPacket_type**		dataPackets		= NULL;
	size_t					nPackets		= 0;

	errChk( GetAllDataPackets (sinkVChan, &dataPackets, &nPackets, &errorInfo.errMsg) );
	
	// release data packets
	for(size_t i = 0; i < nPackets; i++)
		ReleaseDataPacket(&dataPackets[i]);
	
Error:
	
	OKfree(dataPackets);
	
RETURN_ERR
}
Esempio n. 14
0
int	ReceiveWaveform (SinkVChan_type* sinkVChan, Waveform_type** waveform, WaveformTypes* waveformType, char** errorMsg)
{
#define		ReceiveWaveform_Err_NoWaveform			-1
#define		ReceiveWaveform_Err_WrongDataType		-2
#define		ReceiveWaveform_Err_NotSameDataType		-3
	
INIT_ERR	
	
	DataPacket_type*		dataPacket				= NULL;
	DLDataTypes				dataPacketType			= 0;
	DLDataTypes				firstDataPacketType		= 0;
	void*					dataPacketPtrToData		= NULL;
	char*					msgBuff					= NULL;
	
	
	// init
	*waveform = NULL;
	
	// get first data packet and check if it is a NULL packet
	errChk ( GetDataPacket(sinkVChan, &dataPacket, &errorInfo.errMsg) );
	
	if (!dataPacket) {
		nullChk( msgBuff = StrDup("Waveform received does not contain any data. This occurs if a NULL packet is encountered before any data packets") );
		SET_ERR(ReceiveWaveform_Err_NoWaveform, msgBuff);
	}
	
	// check if data packet type is supported by this function
	dataPacketPtrToData = GetDataPacketPtrToData(dataPacket, &firstDataPacketType);
	dataPacketType 		= firstDataPacketType;
	
	// check if data packet is of waveform type
	switch (firstDataPacketType) {
			
		case DL_Waveform_Char:
		case DL_Waveform_UChar:
		case DL_Waveform_Short:
		case DL_Waveform_UShort:
		case DL_Waveform_Int:
		case DL_Waveform_UInt:
		case DL_Waveform_Int64:
		case DL_Waveform_UInt64:	
		case DL_Waveform_SSize:
		case DL_Waveform_Size:
		case DL_Waveform_Float:
		case DL_Waveform_Double:
			break;
		
		default:
			
			nullChk( msgBuff = StrDup("Data packet received is not of a waveform type and cannot be retrieved by this function") );
			SET_ERR(ReceiveWaveform_Err_WrongDataType, msgBuff);
			break;
	}
	
	errChk( CopyWaveform(waveform, *(Waveform_type**)dataPacketPtrToData, &errorInfo.errMsg) );
	ReleaseDataPacket(&dataPacket);
	
	// get another data packet if any
	errChk ( GetDataPacket(sinkVChan, &dataPacket, &errorInfo.errMsg) );
	// assemble waveform from multiple packets until a NULL packet is encountered
	while (dataPacket) {
		
		// get waveform data from the first non-NULL data packet
		dataPacketPtrToData = GetDataPacketPtrToData(dataPacket, &dataPacketType);
		
		// check if retrieved data packet is of the same type as the first packet
		if (firstDataPacketType != dataPacketType) {
			nullChk( msgBuff = StrDup("Data packets must be all of the same type") );
			SET_ERR(ReceiveWaveform_Err_NotSameDataType, msgBuff);
		}
	
		errChk( AppendWaveform(*waveform, *(Waveform_type**)dataPacketPtrToData, &errorInfo.errMsg) );
	
		ReleaseDataPacket(&dataPacket);
		
		// get another packet
		errChk ( GetDataPacket(sinkVChan, &dataPacket, &errorInfo.errMsg) );
	}
	
	// check again if waveform is NULL
	if (!*waveform) {
		nullChk( msgBuff = StrDup("Waveform received does not contain any data. This occurs if a NULL packet is encountered before any data packets or the data packet doesn't have any data") );
		SET_ERR(ReceiveWaveform_Err_NoWaveform, msgBuff);
	}
	
	// assign waveform type
	if (waveformType)
		switch (dataPacketType) {
			
			case DL_Waveform_Char:
				*waveformType = Waveform_Char;
				break;
				
			case DL_Waveform_UChar:
				*waveformType = Waveform_UChar;
				break;
				
			case DL_Waveform_Short:
				*waveformType = Waveform_Short;
				break;
				
			case DL_Waveform_UShort:
				*waveformType = Waveform_UShort;
				break;
				
			case DL_Waveform_Int:
				*waveformType = Waveform_Int;
				break;
				
			case DL_Waveform_UInt:
				*waveformType = Waveform_UInt;
				break;
				
			case DL_Waveform_Int64:
				*waveformType = Waveform_Int64;
				break;
				
			case DL_Waveform_UInt64:
				*waveformType = Waveform_UInt64;
				break;
				
			case DL_Waveform_SSize:
				*waveformType = Waveform_SSize;
				break;
				
			case DL_Waveform_Size:
				*waveformType = Waveform_Size;
				break;
				
			case DL_Waveform_Float:
				*waveformType = Waveform_Float;
				break;
				
			case DL_Waveform_Double:
				*waveformType = Waveform_Double;
				break;
			
			default:
			
				nullChk( msgBuff = StrDup(" Data packet received is not of a waveform type and cannot be retrieved by this function") );
				SET_ERR(ReceiveWaveform_Err_WrongDataType, msgBuff);
		}
		
	return 0;
	
Error:
	
	// cleanup
	OKfree(msgBuff);
	ReleaseDataPacket(&dataPacket);
	discard_Waveform_type(waveform);
	
RETURN_ERR
}
Esempio n. 15
0
void create_network(char *weight_file)

{
 FILE *fp;
 float val;

/*  Allocate units (the user may or may not use this function, 
      there is no need to do this)  */

       ret = krui_allocateUnits( OUnits + HUnits + IUnits );
       errChk( ret );
       printf( "\n\nCreate Units now\n" );

/*  Create standard (input) Units  */

       unit_pos.x = 1;
       for (i = 1; i <= IUnits; i++)
	 {
	   unit_no = krui_createDefaultUnit();
	   if (unit_no < 0)  errChk( unit_no );
	   ret = krui_setUnitTType( unit_no, INPUT );
	   errChk( ret );

	   unit_pos.y = (IUnits<Y)?i+(Y-IUnits)/2:i;
	   krui_setUnitPosition( unit_no, &unit_pos );
	 }

/*  Create standard (hidden) Units  */
  
       for (i = 1; i <= Y; i++)
	 for (j = 1; j <= X; j++)
	   {
	     unit_pos.x = 4+j;
	     unit_no = krui_createDefaultUnit();
	     if (unit_no < 0)  errChk( unit_no );
	     ret = krui_setUnitTType( unit_no, HIDDEN );
	     errChk( ret );

	     unit_pos.y = i;
	     krui_setUnitPosition( unit_no, &unit_pos );
	   }

/*  Create standard (output) Units  */

       unit_pos.x = 4+X+3;
       if (OUnits) for (i = 1; i <= OUnits; i++)
	 {
	   unit_no = krui_createDefaultUnit();
	   if (unit_no < 0)  errChk( unit_no );
	   ret = krui_setUnitTType( unit_no, OUTPUT );
	   errChk( ret );

	   unit_pos.y = (OUnits<Y)?i+(Y-OUnits)/2:i;
	   krui_setUnitPosition( unit_no, &unit_pos );
	 }

/* Make Connections now */
/* Make connections between hidden units and output units first !  */

       for (i = IUnits + HUnits + 1; i <= IUnits + HUnits + OUnits; i++)
	 {  /*  Make output unit to current unit  */
	   ret = krui_setCurrentUnit( i );
	   errChk( ret );

	   for (j = IUnits + 1; j <= IUnits + HUnits; j++)
	     {  /*  connect current (output) unit with hidden unit. 
                    REMEMBER: The hidden unit #j is the predecessor of
                        the (output) unit #i (it is a backward connection) */
	       ret = krui_createLink( j, 0 );
	       errChk( ret );
	     }
	 }

/* Make connections between input units and hidden units
   and set link weight with datas from output_file   */

       printf("\nSet link weights now\n");
       if((fp=fopen(weight_file,"r"))!=NULL)
        for (i = IUnits + 1; i <= IUnits + HUnits; i++)
	 {  /*  Make hidden unit to current unit  */
	   ret = krui_setCurrentUnit( i );
	   errChk( ret );

	   for (j = 1; j <= IUnits; j++)
	     { /*  (backward) connect current (hidden) unit with input unit  */
	       fscanf(fp,"%s",string);
               val = atof(string);
               ret = krui_createLink( j,val);
	       errChk( ret );
	     }
	 }
        else{ /* set all link weights to zero */
	  for (i = IUnits + 1; i <= IUnits + HUnits; i++)
	    {  /*  Make hidden unit to current unit  */
	      ret = krui_setCurrentUnit( i );
	      errChk( ret );
	      
	      for (j = 1; j <= IUnits; j++)
		{/* (backward) connect current (hidden) unit with input unit */
		  ret = krui_createLink( j,0);
		  errChk( ret );
		}
	    } 
	  
	  printf("\nWeight file %s could not be opened!\n",weight_file);
	  printf("All weights have been set to zero!\n");
	}
       fclose(fp);

 
        /*  set the update function  */
       ret = krui_setUpdateFunc (KOHONEN_UPDATE_FUNC_NAME);
       errChk( ret );
        /* set the learning function */
       ret = krui_setLearnFunc (KOHONEN_LEARN_FUNC_NAME);
       errChk( ret );
        /* set the init function */
       ret = krui_setInitialisationFunc (KOHONEN_INIT_FUNC_NAME);
       errChk( ret );


       printf("\nEnter Filename of the Network to save: ");
       scanf("%s", name);
       strcat(name,".net");
       printf("Save Network\n");
      
/*  save the network  */

       ret = krui_saveNet( name, NULL );
       errChk( ret );
       printf( "\nCreate Patterns now\n" );

} /* end of create_network */
/* 系统初始化-新建并初始化线程池 */
int setupThreadPool (void){
    int error = 0;
    errChk(CmtNewThreadPool(MAX_THREADS, &poolHandle));
Error:
    return error;
}