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

📄 llmain.cpp

📁 vc,optical passive component auto test software.
💻 CPP
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#include <hp816x.h>/****************************************************************** This example demonstrates, how to interfaces the hp816x instrument drive into a C programming environment. The program acts as a windows console  program and should be run in DOS box. The program performs a lambda scan. Only the result of one channel is  fetched. To return the data of more then one channel, adopt the program to your needs. The result is placed in file named "llscan.csv" if no command line argument is used. The output can be imported MS-Excel double-clicking on to the filename. To compile and link this example, make sure that the library path covers  visa32.lib and hp816x_32.lib. The include path should be set to <vxipnp>\win(XX)\include ******************************************************************//*the instrument handle*/ViSession IHandle;#define cmdLineMsg "Please enter the following command line options:\n \             [<filename> [<start wavelength>] [<stop wavelength>] [<step size>] [<number of scans>]]\n"/* Global defined functions*/static void CheckError (ViSession vi, ViStatus errStatus);int main (int argc,char **argv){  ViStatus errStatus;   /*local variables to set up  a lambda scan */  ViReal64 power,startWavelength,stopWavelength,stepSize;           ViInt32  opticalOutput,numberofScans,PWMChannels,unit;              ViUInt32 numberofDatapoints,numberofValueArrays;  ViUInt32 i;  ViInt32 j;  int converted;    char filename[256],commandline[256];  FILE *fp;  /*results will be stored in:*/  ViReal64 *wavelengthArray, *powerArray;      commandline[0]=0;  for(j=1; j < argc; j++)  {    strcat(commandline,argv[j]);    strcat(commandline, " ");  }    /*initialize local variables to default values*/  power = -7.0;  unit = hp816x_PU_DBM;  startWavelength = 1550.0e-9;  stopWavelength = 1555.0e-9;  stepSize = 5.0e-12;  opticalOutput = hp816x_HIGHPOW;  numberofScans = hp816x_NO_OF_SCANS_2;  PWMChannels = 1;  ViRsrc defBusadress = "GPIB0::20::INSTR";   converted = 0;  /*process command line*/    switch (argc - 1)  {    case 1:       converted = sscanf((const char *)commandline,"%s",filename);      break;    case 2:       converted = sscanf(commandline,"%s%lf",filename,&startWavelength);      break;    case 3:       converted = sscanf((const char *)commandline,"%s%lf%lf",filename,&startWavelength,&stopWavelength);      break;    case 4:      converted = sscanf((const char *)commandline,"%s%lf%lf%lf",filename,&startWavelength,                                            &stopWavelength,&stepSize);      break;    case 5:       converted = sscanf((const char *)commandline,"%s%lf%lf%lf%d",filename,&startWavelength,                                            &stopWavelength,&stepSize,&numberofScans);      break;    default:        strcpy(filename,"llscan.csv");        }  /*check if all arguments could be converted*/  if(converted != argc-1)  {      printf("Command line error!\n %s",cmdLineMsg);      exit(-1);  }    /*initialize the driver*/  errStatus = hp816x_init(defBusadress, VI_FALSE, VI_TRUE, &IHandle);  CheckError (IHandle, errStatus);     /*register at least the mainframe containing the tunable laser source*/  errStatus =  hp816x_registerMainframe (IHandle);    CheckError (IHandle, errStatus);     /*get original logged wavelength points (no interpolation)*/  errStatus = hp816x_returnEquidistantData (IHandle,VI_FALSE);  CheckError (IHandle, errStatus);       /*prepare the lambda scan operation*/  errStatus = hp816x_prepareMfLambdaScan (IHandle, unit, power,                                       opticalOutput, numberofScans, PWMChannels,                                                   startWavelength,                                               stopWavelength,                                                stepSize,                                                      &numberofDatapoints,                                           &numberofValueArrays);     CheckError (IHandle, errStatus);   /*use the returned number of datapoints  allocate memory for the results*/  wavelengthArray = (ViReal64 *)malloc(numberofDatapoints *sizeof(ViReal64));  powerArray      = (ViReal64 *)malloc(numberofDatapoints *sizeof(ViReal64));  /*perform the lambda scan operation*/   errStatus = hp816x_executeMfLambdaScan (IHandle, wavelengthArray);  CheckError (IHandle, errStatus);                                           /*fetch the results for channel 0  to  fetch result from different channels just call hp816x_getLambdaScanResult  with the appropriate channel number */  errStatus = hp816x_getLambdaScanResult (IHandle,                                             0,         /*channel number starts from 0!!*/                                             VI_TRUE,                                             -50,                                                powerArray,                                             wavelengthArray);  CheckError (IHandle, errStatus);     /*write data to file*/  fp = fopen(filename,"wt");  if( fp == NULL)    printf("unable to open file %s",filename);  else  {      for (i = 0 ; i <  numberofDatapoints; i++)      {        fprintf(fp,"%1.13lf;%1.12lf\n",wavelengthArray[i],powerArray[i]);      }  }  /*release the allocated memory*/  free (wavelengthArray);  free (powerArray);      /*unregister all mainframes*/  hp816x_unregisterMainframe (0);  /*close the driver*/  errStatus = hp816x_close(IHandle);  return 0;}/***************************************************************************/void CheckError (ViSession vi, ViStatus errStatus)/***************************************************************************/{    ViInt32     inst_err;    ViChar      err_message[256];    if(errStatus < VI_SUCCESS )    {            /* If the driver is set to detect instrument errors,    */            /*   and an instrument error is detected, the error     */            /*   code is hp816x_INSTR_ERROR_DETECTED (see           */            /*   hp816x.h).  In this case, query the instrument     */            /*   for the error and display it.                      */            /* Otherwise, the error is a driver error.  Query the   */            /*   driver for the error and display it.               */        if(hp816x_INSTR_ERROR_DETECTED == errStatus)	        {            hp816x_error_query(vi, &inst_err, err_message);             printf("        Inst. Error : %lx, %s\n", inst_err, err_message);         }        else        {            hp816x_error_message(vi, errStatus, err_message);             printf("        Driver Error : %lx, %s\n", errStatus, err_message);        }            /* Optionally reset the instrument, close the           */            /*   instrument handle, and exit the program.           */     hp816x_close(vi);      exit(errStatus);  	    }return;}

⌨️ 快捷键说明

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