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

📄 scope.c

📁 HP GPIB的VB和C语言库文件,参考范例.
💻 C
📖 第 1 页 / 共 2 页
字号:
//   id - identifies the I/O session for the SRQ.
//
// Description:
//   This routine is called when an SRQ is generated by a device.
//
/////////////////////////////////////////////////////////////////////
void SICLCALLBACK my_srq_handler(INST id)
{
    unsigned char status;

    // make sure it was the scope requesting service
    ireadstb(id,&status);

    if (status &= 64) {
        // clear the status byte so the scope can assert SRQ again if needed.
        iprintf(id,"*CLS\n");

        sprintf(text_buf[num_lines++],
                 "SRQ received!, stat=0x%x",status);
    } else {
        sprintf(text_buf[num_lines++],
                 "SRQ received, but not from the scope");
    }
    InvalidateRect(hWnd, NULL, TRUE);
}

/////////////////////////////////////////////////////////////////////
//
// init_scope_io:
//
// Parameters:
//   none
//
// Description:
//   This routine installs a SICL error handler, opens a device
//   session for the scope and puts the scope in a known state.
//
/////////////////////////////////////////////////////////////////////
void init_scope_io(void)
{
    // install custom error handler
    ionerror(my_err_handler);

    // open a device session to the scope
    scope = iopen("scope");

    if (scope == 0) {
        sprintf(text_buf[num_lines++],"Oscilloscope iopen failed!");
    } else {
        sprintf(text_buf[num_lines++],"Oscilloscope session initialized!");
        // set a timeout value for the session
        itimeout(scope, TIMEOUT);

        // put the scope in a known state
        iclear(scope);
        iremote(scope);
    }
    InvalidateRect(hWnd, NULL, TRUE);  // print output
}

/////////////////////////////////////////////////////////////////////
//
// close_scope:
//
// Parameters:
//   none
//
// Description:
//   This routine cleans up, closes the scope session and calls
//   _siclcleanup.
//
/////////////////////////////////////////////////////////////////////
void close_scope(void)
{
    // give local control back to the scope
    ilocal(scope);

    // close the session
    iclose(scope);

    // Call _siclcleanup before exiting to release resources allocated
    // by SICL for this application (required for Windows 3.1).
    _siclcleanup();
}


/////////////////////////////////////////////////////////////////////
//
// get_voltage:
//
// Parameters:
//   none
//
// Description:
//   The following routine gets voltage readings from the Digital
//   MultiMeter specified by the symbolic name "dmm" in SICL.INI
//
/////////////////////////////////////////////////////////////////////
void get_voltage(void)
{
    INST dmm;
    double voltage;
    unsigned char cmd[50];

    enable_io_menu_items(FALSE);  // do this before making sicl calls

    dmm = iopen("dmm");
    itimeout(dmm, 500);

    // put the meter in a known state and get its IDN string.
    iprintf(dmm,"*RST;*CLS\n");
    ipromptf(dmm,"*IDN?\n","%s",cmd);

    sprintf(text_buf[num_lines++],"DMM is %s",cmd);

    // make a DC voltage reading and get the result.
    iprintf(dmm,"measure:volt:dc?\n");
    iscanf(dmm,"%lf",&voltage);

    sprintf(text_buf[num_lines++],"  Current voltage: %lf V",voltage);

    // close the session
    iclose(dmm);

    InvalidateRect(hWnd, NULL, TRUE);  // print output

    enable_io_menu_items(TRUE);  // do this after making all sicl calls
}

/////////////////////////////////////////////////////////////////////
//
// get_data:
//
// Parameters:
//   INST id for the scope device session.
//
// Description:
//   The following routine gets settings and waveform data from the
//   scope.  The device is locked during the measurement to prevent
//   outside access.
//
/////////////////////////////////////////////////////////////////////
void get_data (INST id)
{
    long   elements;

    enable_io_menu_items(FALSE);  // do this before making sicl calls

    // lock the device to prevent access from other applications
    ilock(scope);

    // initialize scope
    iprintf(id,"*RST\n");

    // retrieve the scope's ID string
    ipromptf(id,"*IDN?\n","%s",scopeidn);

    // setup up the waveform source

    iprintf(id,":autoscale\n");
    iprintf(id,":waveform:format word\n");

    // input waveform preamble to controller

    iprintf(id,":digitize channel1\n");
    iprintf(id,":waveform:preamble?\n");

    // read the scope preamble - 20 comma-separated values.
    iscanf(id,"%,20f\n",pre);

    // command scope to send the data
    iprintf(id,":waveform:data?\n");

    // enter the data
    elements = R_ELEMENTS;
    iscanf(id,"%#wb\n",&elements,readings);

    if ( elements == R_ELEMENTS ) {
        sprintf (text_buf[num_lines++],"Readings buffer full: May not have received all points");
        InvalidateRect(hWnd, NULL, TRUE);
    }

    // Get probe attenuation
    ipromptf(id,":chan1:probe?\n","%s",probe);

    // release the scope for use by others
    iunlock(scope);

    sprintf(text_buf[num_lines++]," Oscilloscope waveform upload complete!");
    InvalidateRect(hWnd, NULL, TRUE);  // print output

    enable_io_menu_items(TRUE);  // do this after making all sicl calls
}

/////////////////////////////////////////////////////////////////////
//
// show_scope_settings:
//
// Parameters:
//   none
//
// Description:
//   This routine formats and prints the settings of the scope read
//   in the get_data routine.  It does no I/O.
//
/////////////////////////////////////////////////////////////////////
void show_scope_settings (void)
{
    float vdiv;
    float off;
    float sdiv;
    float delay;

    num_lines = 0;  // set message output to top of window

    vdiv  = 32 * pre [7];
    off   = (128 - pre [9]) * pre [7] + pre [8];
    sdiv  = pre [2] * pre [4] / 10;
    delay = (pre [2] / 2 - pre [6]) * pre [4] + pre [5];

    //    print the statistics about the data
    //
    sprintf (text_buf[num_lines++],"Oscilloscope ID:  %s", scopeidn);
    sprintf (text_buf[num_lines++]," ------  Current Channel 1 Settings  ------");
    sprintf (text_buf[num_lines++],"      Volts/Div = %f V", vdiv);
    sprintf (text_buf[num_lines++],"         Offset = %f V", off);
    sprintf (text_buf[num_lines++],"          Probe = %s"    , probe);
    sprintf (text_buf[num_lines++],"          S/Div = %f S", sdiv);
    sprintf (text_buf[num_lines++],"          Delay = %f S", delay);
    sprintf (text_buf[num_lines++]," ");
    InvalidateRect(hWnd, NULL, TRUE);
}

/////////////////////////////////////////////////////////////////////
//
// print_disp:
//
// Parameters:
//   INST id for the scope device session.
//
// Description:
//   Commands the scope to print it's display and send SRQ when
//   complete.  The iwaithdlr function is used to suspend operation
//   until the SRQ is received.
//
/////////////////////////////////////////////////////////////////////
void print_disp (INST id)
{
    INST hpibintf;
    unsigned char cmd[16];
    int length;

    enable_io_menu_items(FALSE);  // do this before making all sicl calls
    num_lines = 0;  // set message output to top of window

    // get the interface session for this device
    hpibintf = igetintfsess(id);

    // disable interrupt events
    iintroff();

    // install the SRQ handler
    ionsrq(id,my_srq_handler);   // Not supported on HP 82335

    // tell the scope to SRQ on 'operation complete'
    iprintf(id,"*CLS\n");
    iprintf(id,"*SRE 32; *ESE 1\n");

    // tell the scope to print
    iprintf(id,":print?; *OPC\n");

    // tell the scope to talk and printer to listen
    //    the listen command is formed by adding 32 to the device address
    //        of the device to be a listener
    //    the talk command is formed by adding 64 to the device address of
    //        the device to be a talker

    cmd[0] = (unsigned char)63;      // 63 is unlisten
    cmd[1] = (unsigned char)(32+1);  // printer at addr 1, make it a listener
    cmd[2] = (unsigned char)(64+7);  // scope at addr 7, make it a talker
    cmd[3] = '\0';                    // terminate the string

    length = strlen (cmd);

    // Use HP-IB specific commands to control the bus and interface
    igpibsendcmd(hpibintf,cmd,length);
    igpibatnctl(hpibintf,0);

    sprintf (text_buf[num_lines++],"Waiting for print to complete...");
    InvalidateRect(hWnd, NULL, TRUE);

    // wait for SRQ  or 30 seconds before continuing.
    iwaithdlr(30000L);

    // Re-enable interrupt events.
    iintron();

    sprintf (text_buf[num_lines++],"Printing complete!");
    InvalidateRect(hWnd, NULL, TRUE);

    enable_io_menu_items(TRUE);  // do this after making all sicl calls
}

⌨️ 快捷键说明

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