⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 carl.c

📁 此代码是我做练习的CVI的才鸟代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			fgetpos (stream, &currentpo2);  
		}
		ASKend:
		if ( CompareStrings(temp,0,"Test Result:PASS.\n",0,1)!=0 )
		{
			MessagePopup("","     ASK 测试未完成     ");
			return 0;
		}
	}
	//FSK judge
	{
		fpos_t currentpo,currentpo2;
		int handle;
		FILE *stream;
		sprintf(temp,"%s\\%s\\%s",DataDirName, serial,"fsk.txt");
		stream = fopen (temp, "r");
		if (stream==NULL)
			goto FSKend;
		
		fseek (stream, 0, SEEK_END);
		fgetpos (stream, &currentpo);
		fseek (stream, 0, SEEK_SET);
		fgets (temp, 50, stream);
		fgetpos (stream, &currentpo2);
		while (currentpo2._offset != currentpo._offset)
		{
			fgets (temp, 50, stream);  
			fgetpos (stream, &currentpo2);  
		}
		FSKend:
		if ( CompareStrings(temp,0,"Test Result:PASS.\n",0,1)!=0 )
		{
			MessagePopup("","     FSK 测试未完成     ");
			return 0;
		}
	}
	return 1;
}



int read_mac_address(char *serial,char *address)
{
	char cellrange[300];
	int error;
	int filesize,exist ;
	char position[20][80];
	int rownumber;
	char excelfilename[300];
	//="d:\\testdata\\testdata\\mac.xls";
	char temp[300];
	
	sprintf(excelfilename,"%s\\%s",DataDirName,"mac.xls");
	//connect excel
    SetWaitCursor (1);
	error = Excel_NewApp (NULL, 0, LOCALE_NEUTRAL, 0, &ExcelAppHandle);
    SetWaitCursor (0);
    if (error<0) 
    {
		goto quitexcel;
	}
	error = Excel_SetProperty (ExcelAppHandle, NULL, Excel_AppVisible, CAVT_BOOL, VFALSE);
    if (error<0) 
    {
		goto quitexcel;   
	}
    MakeApplicationActive ();
    excelLaunched = 1;
    
    error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppWorkbooks, 
            CAVT_OBJHANDLE, &ExcelWorkbooksHandle);
    if (error<0) 
    {
		goto quitexcel;   
	}
	exist = GetFileInfo (excelfilename, &filesize);
	
	if (exist==0)
	{
		MessagePopup(""," MAC 地址文件未找到\n");
		goto quitexcel;   
		
	}
	if (exist==1)
	{
    	error = Excel_WorkbooksOpen (ExcelWorkbooksHandle, NULL, excelfilename, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, &ExcelWorkbookHandle); 
	}
    error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets, 
            CAVT_OBJHANDLE, &ExcelSheetsHandle);
    error = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(1), 
            &ExcelWorksheetHandle);
    error = Excel_WorksheetActivate (ExcelWorksheetHandle, NULL);
	
	status = ExcelRpt_Find (ExcelWorksheetHandle, ExRConst_dataString, serial, "A1", ExRConst_Values, ExRConst_Whole,
						ExRConst_ByColumns, ExRConst_Next, 1, 1, cellrange);
	if (status>=0)
		rownumber = strtol (&cellrange[3], NULL, 10);
	else 
	{
		MessagePopup("","  在MAC地址文件中未找到此整机序列号\n");
		goto quitexcel; 
	}
	sprintf(position[0],"B%d",rownumber);
	ExcelRpt_GetCellValue (ExcelWorksheetHandle, position[0], ExRConst_dataString, address);

	SetWaitCursor (1);
	//if (exist==1)
    //	Excel_WorkbookSave (ExcelWorkbookHandle, NULL);
	ShutdownExcel();  
	Delay(0.5);  
    SetWaitCursor (0);
	return 1;
	
	//quit file
	quitexcel:
    ShutdownExcel();  
	Delay(0.5);
    SetWaitCursor (0);
	return 0;
}

int board_read_mac_address(char *ctserial,char *address)
{
	char cellrange[300];
	int error;
	int filesize,exist ;
	char position[20][80];
	int rownumber;
	char excelfilename[300];
	//="d:\\testdata\\testdata\\misc_mac.xls";
	char temp[300];
	
	sprintf(excelfilename,"%s\\%s",DataDirName,"misc_mac.xls");
	//connect excel
    SetWaitCursor (1);
	error = Excel_NewApp (NULL, 0, LOCALE_NEUTRAL, 0, &ExcelAppHandle);
    SetWaitCursor (0);
    if (error<0) 
    {
		goto quitexcel;
	}
	error = Excel_SetProperty (ExcelAppHandle, NULL, Excel_AppVisible, CAVT_BOOL, VFALSE);
    if (error<0) 
    {
		goto quitexcel;   
	}
    MakeApplicationActive ();
    excelLaunched = 1;
    
    error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppWorkbooks, 
            CAVT_OBJHANDLE, &ExcelWorkbooksHandle);
    if (error<0) 
    {
		goto quitexcel;   
	}
	exist = GetFileInfo (excelfilename, &filesize);
	
	if (exist==0)
	{
		MessagePopup(""," MISC MAC 地址文件未找到\n");
		goto quitexcel;   
		
	}
	if (exist==1)
	{
    	error = Excel_WorkbooksOpen (ExcelWorkbooksHandle, NULL, excelfilename, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                     CA_DEFAULT_VAL, &ExcelWorkbookHandle); 
	}
    error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets, 
            CAVT_OBJHANDLE, &ExcelSheetsHandle);
    error = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(1), 
            &ExcelWorksheetHandle);
    error = Excel_WorksheetActivate (ExcelWorksheetHandle, NULL);
	
	status = ExcelRpt_Find (ExcelWorksheetHandle, ExRConst_dataString, "Not used", "B1", ExRConst_Values, ExRConst_Whole,
						ExRConst_ByColumns, ExRConst_Next, 1, 1, cellrange);
	if (status>=0)
		rownumber = strtol (&cellrange[3], NULL, 10);
	else 
	{
		MessagePopup("","  在MISC MAC地址文件中无可用MAC地址\n");
		goto quitexcel; 
	}
	sprintf(position[0],"A%d",rownumber);
	ExcelRpt_GetCellValue (ExcelWorksheetHandle, position[0], ExRConst_dataString, address);

	sprintf(position[0],"C%d",rownumber);
	ExcelRpt_SetCellValue (ExcelWorksheetHandle, position[0], ExRConst_dataString, "used");
	
	sprintf(position[0],"D%d",rownumber);
	ExcelRpt_SetCellValue (ExcelWorksheetHandle, position[0], ExRConst_dataString, ctserial);
	
	
	SetWaitCursor (1);
	//if (exist==1)
    //	Excel_WorkbookSave (ExcelWorkbookHandle, NULL);
	ShutdownExcel();  
	Delay(0.5);  
    SetWaitCursor (0);
	return 1;
	
	//quit file
	quitexcel:
    ShutdownExcel();  
	Delay(0.5);
    SetWaitCursor (0);
	return 0;
}


int write_mac_address(ViSession analyzerid, char *mac_addresss)
{
	viPrintf(analyzerid,":INITiate:CONTinuous OFF\n");
	Delay(2.5);
	sprintf(mac_temp,"%s",mac_addresss);
	//write the MAC address
	//viPrintf(analyzerid,"");
	return 1;
}



int Board_MAC_address_mapping(ViSession analyzerid,char *serial,char *ctserial)
{
	char *mac_address="1111111111111";
	if ( board_read_mac_address(ctserial,mac_address) !=1 )
		return 0;
	if (strlen(mac_address)!=12)
	{
		MessagePopup(""," MAC 地址长度不等于12\n");
		return 0;
	}
	if (write_mac_address(analyzerid,mac_address)!=1)
		return 0;
	
	return 1;
}



int MAC_address_mapping(ViSession analyzerid,char *serial)
{
	char *mac_address="1111111111111";
	if ( read_mac_address(serial,mac_address ) !=1 )
		return 0;
	if (strlen(mac_address)!=12)
	{
		MessagePopup(""," MAC 地址长度不等于12\n");
		return 0;
	}
	if (write_mac_address(analyzerid,mac_address)!=1)
		return 0;
	
	return 1;
}


int temperature_judge(ViSession analyzerid)
{
	char temperature[300];
	char temp_temperature[300];
	char low_temperature[5]="36.0";
	char high_temperature[5]="41.0";
    
    viPrintf(analyzerid,":INITiate:CONTinuous OFF\n");
    Delay(2.5);	
	status = viQueryf (analyzerid, ":DEBug:REMote:TEMPerature?\n","%s",temperature);  
    Delay(1);
	viPrintf(analyzerid,":INITiate:CONTinuous ON\n");     
	Delay(2);
	temp_temperature[0]=temperature[7];
	temp_temperature[1]=temperature[8];      
	temp_temperature[2]=temperature[9];      
	temp_temperature[3]=temperature[10];  
	temp_temperature[4]='\0'; 
	low_temperature[4]='\0';
	high_temperature[4]='\0';
	if (CompareStrings (temp_temperature, 0, low_temperature, 0, 1)<0 || CompareStrings (temp_temperature, 0, high_temperature, 0, 1)>0 )
	{
		MessagePopup("Warning","   请确认射频板温度(36---41)!\n");
		return 0;
	}
	return 1;
}




int Reset(ViSession analyzerid,int panel,int control)
{
	  ViUInt32 returncount;
	  int status=0;
	  char temperature[300],temp[300];
	  //Delay(0.5);
	  status = viPrintf (analyzerid, "*RST\n"); 
	  Delay(2);
	  viPrintf(analyzerid,":INITiate:CONTinuous OFF\n");
	  Delay(2.5);	
	  status = viQueryf (analyzerid, ":DEBug:REMote:TEMPerature?\n","%s",temperature);  
	  Delay(1);
	  sprintf (temp, "****HouYi Temperature: %s\n",temperature);
	  SetCtrlVal (panel, control, temp); 
	  Delay(0.2);
	  
	  //status = viQueryf (analyzerid, ":DEBug:REMote:VERsion?\n","%s",temperature);  
	  //Delay(2);
	  viWrite (analyzerid, ":DEBug:REMote:VERsion?\n", sizeof(":DEBug:REMote:VERsion?\n"), &returncount);
	  Delay(1);
	  viRead (analyzerid, temperature, 100, &returncount);
	  sprintf (temp, "****HouYi Version: %s\n",temperature);
	  SetCtrlVal (panel, control, temp); 
	  sprintf(temp, "\n----------------------------------------------------------------\n");
	  SetCtrlVal (panel, control, temp);
	  viPrintf(analyzerid,":INITiate:CONTinuous ON\n");
	  Delay(0.1);	
	  return 0;
}

int record_time(int y,int x)
{
	long sizeoffile;
	int present;
	int ar;
	int hidden;
	int s;
	int readonly;
	int file;
	char record_file[300],temp[300];
	double curtime;
	char date[300],time[300],m[300];
	int i=0;
	GetCurrentDateTime (&curtime);
	FormatDateTimeString (curtime, "%Y-%m-%d", date, sizeof(date));
	FormatDateTimeString (curtime, "%H:%M:%S", time, sizeof(time));
	
	for(i=0;i<7;i++)
		m[i]=date[i];
	m[i]='\0';
	sprintf(record_file,"%s\\%s\\%s\\%s",DataDirName,m,date,"test_record_B.txt");
	
	present = GetFileInfo (record_file, &sizeoffile);
	if (present)
	{
		GetFileAttrs (record_file, &readonly, &s, &hidden, &ar);
		while (hidden)
			GetFileAttrs (record_file, &readonly, &s, &hidden, &ar);
		SetFileAttrs (record_file, -1, -1, 1, -1);
	}
	file = OpenFile (record_file, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
		sprintf(temp,"%12s %39s %8s %13s-%8s %8d\n",serial,testitemname[y],username,date,time,x);  
	WriteFile (file, temp, StringLength(temp));
	CloseFile (file);
	SetFileAttrs (record_file, -1, -1, 0, -1);
	
	
	return 1;
	
}

int cal_record_time(int y,int x)
{
	long sizeoffile;
	int present;
	int ar;
	int hidden;
	int s;
	int readonly;
	int file;
	char record_file[300],temp[300];
	double curtime;
	char date[300],time[300],m[300];
	int i=0;
	GetCurrentDateTime (&curtime);
	FormatDateTimeString (curtime, "%Y-%m-%d", date, sizeof(date));
	FormatDateTimeString (curtime, "%H:%M:%S", time, sizeof(time));
	
	for(i=0;i<7;i++)
		m[i]=date[i];
	m[i]='\0';
	sprintf(record_file,"%s\\%s\\%s\\%s",DataDirName,m,date,"cal_test_record_B.txt");
	
	present = GetFileInfo (record_file, &sizeoffile);
	if (present)
	{
		GetFileAttrs (record_file, &readonly, &s, &hidden, &ar);
		while (hidden)
			GetFileAttrs (record_file, &readonly, &s, &hidden, &ar);
		SetFileAttrs (record_file, -1, -1, 1, -1);
	}
	file = OpenFile (record_file, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
		sprintf(temp,"%12s %39s %8s %13s-%8s %8d\n",serial,testitemname[y],username,date,time,x);  
	WriteFile (file, temp, StringLength(temp));
	CloseFile (file);
	SetFileAttrs (record_file, -1, -1, 0, -1);
	return 1;
}



int board_record_time(int y,int x)
{
	long sizeoffile;
	int present;
	int ar;
	int hidden;
	int s;
	int readonly;
	int file;
	char record_file[300],temp[300];
	double curtime;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -