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

📄 scope_control.cpp

📁 一个简单示波器的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            }
        }
    }

    return(bRetcode);
}

//****************************************************************************
//
// Disconnect from the oscilloscope device.
//
//****************************************************************************
bool ScopeControlDisconnect(void)
{
    bool bRetcode = true;

    //
    // If we are connected and communicating, tell the scope that we are going away.
    //
    if(devInfo.bCommunicating)
    {
        SendScopePacket(SCOPE_PKT_HOST_GOODBYE, 0, 0);
    }

    if(!devInfo.hwndNotify)
    {
        //
        // Free our Windows-side resources.
        //
        if(devInfo.bDeviceConnected)
        {
            bRetcode = TerminateDevice(&devInfo);
        }

        //
        // Clean up our state so that we are ready for another call to
        // ScopeControlConnect().
        //
        devInfo.bCommunicating = false;
    }

    return(bRetcode);
}

//****************************************************************************
//
// Connect to the device and exchange HOST_HELLO/HELLO_RESPONSE.
//
//****************************************************************************
bool ScopeControlConnect(tScopeSettings *psSettings)
{
    bool bRetcode;
    bool bDriverInstalled;
    unsigned char ucType;
    unsigned char ucParam;
    unsigned long ulParam;
    unsigned long ulLength;
    tScopeSettings *psLocalSettings;

    //
    // Are we operating in synchronous mode? If not, the device open handling
    // is performed in the read/connect thread.
    //
    if(!devInfo.hwndNotify)
    {
        //
        // Yes so try to open the device.
        //
        bRetcode = InitializeDevice(&bDriverInstalled);

        //
        // If the InitializeDevice call was successful, we are connected to
        // the oscilloscope device and have queried its endpoints successfully.
        // We are ready to start sending packets back and forward.
        //
        devInfo.bDeviceConnected = bRetcode;
    }
    else
    {
        //
        // We are in asynchronous mode. The read/connect thread handles
        // the basic initiation of communication so, if this has not yet
        // succeeded, return false to indicate that connection is not
        // possible just now.
        //
        if(!devInfo.bDeviceConnected)
        {
            return(false);
        }
    }

    //
    // Now we need to send the HELLO packet to the scope and wait for
    // its response.
    //
    bRetcode = SendScopePacket(SCOPE_PKT_HOST_HELLO, 0, 0, 0);

    //
    // If we sent the packet successfully and we are operating in synchronous
    // mode, wait for the device to respond with a HELLO_RESPONSE. In
    // asynchronous mode, this is passed to the client directly when it
    // appears using WM_SCOPE_DEVICE_CONNECTED.
    //
    if(!devInfo.hwndNotify && bRetcode)
    {
        //
        // If we sent the packet successfully, wait for the scope to respond.
        //
        bRetcode = ScopeWaitPacket(&ucType, &ucParam, &ulParam, &ulLength,
                                   (void **)&psLocalSettings);
        if(bRetcode)
        {
            //
            // Yay - we are in communication with the scope (or, at least, it's
            // talking to us). Check what it sent to make sure it was a HELLO
            // response packet.
            //
            if((ucType == SCOPE_PKT_HELLO_RESPONSE) &&
               (ulLength == sizeof(tScopeSettings)))
            {
                //
                // We got what we expected so all is well. We are now in
                // communication with the scope device.
                //
                devInfo.bCommunicating = TRUE;

                //
                // Copy the response into the user's buffer and free the pointer
                // we were passed by ScopeWaitPacket().
                //
                *psSettings = *psLocalSettings;
                LocalFree(psLocalSettings);
            }
        }
    }

    return(bRetcode);
}

//****************************************************************************
//
// Start or stop automatic data capture.
//
//****************************************************************************
bool ScopeControlStartStop(bool bStart)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope to stop or start automatic capture as requested.
        //
        bRetcode = SendScopePacket(bStart ? SCOPE_PKT_START : SCOPE_PKT_STOP, 0, 0);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Start or stop automatic data capture.
//
//****************************************************************************
bool ScopeControlEnableChannel2(bool bEnable)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope to enable or disable channel 2.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_SET_CHANNEL2, (bEnable ?
                                   SCOPE_CHANNEL2_ENABLE :
                                   SCOPE_CHANNEL2_DISABLE), 0);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Request capture of a single waveform from the oscilloscope.
//
//****************************************************************************
bool ScopeControlCapture(void)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope capture a single waveform.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_CAPTURE, 0, 0);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Set the capture timebase
//
//****************************************************************************
bool ScopeControlSetTimebase(unsigned long ulTimebaseuSdiv)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope capture a single waveform.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_SET_TIMEBASE, 0, ulTimebaseuSdiv);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Set the oscilloscope trigger level.
//
//****************************************************************************
bool ScopeControlSetTriggerLevel(unsigned long ulLevelmV)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope capture a single waveform.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_SET_TRIGGER_LEVEL, 0, ulLevelmV);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}


//****************************************************************************
//
// Set the oscilloscope trigger level.
//
//****************************************************************************
bool ScopeControlSetTriggerPos(long lPos)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope capture a single waveform.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_SET_TRIGGER_POS, 0, lPos);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Set the trigger type and channel.
//
//****************************************************************************
bool ScopeControlSetTrigger(unsigned char ucChannel, unsigned long ulType)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope capture a single waveform.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_SET_TRIGGER_TYPE, ucChannel, ulType);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Set the vertical position for a particular oscilloscope channel waveform.
//
//****************************************************************************
bool ScopeControlSetPosition(unsigned char ucChannel,
                             long lPosmV)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope to set the vertical position for the given
        // channel.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_SET_POSITION, ucChannel,
                                   (unsigned long)lPosmV);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Set the vertical scaling for a particular oscilloscope channel waveform.
//
//****************************************************************************
bool ScopeControlSetScale(unsigned char ucChannel,
                          unsigned long ulScalemVdiv)
{
        bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope to set the scaling for the given channel.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_SET_SCALE, ucChannel,
                                   ulScalemVdiv);

        return(bRetcode);
    }
    else
    {
        return(false);
    }
}

//****************************************************************************
//
// Enable or disable automatic data transmission from the device.
//
//****************************************************************************
bool ScopeControlAutomaticDataTransmission(bool bEnable)
{
    bool bRetcode;

    if(devInfo.bCommunicating)
    {
        //
        // Tell the oscilloscope to enable or disable channel 2.
        //
        bRetcode = SendScopePacket(SCOPE_PKT_DATA_CONTROL, bEnable, 0);

        return(bRetcode);
    }
    else
    {
        return(false);
    }

}

⌨️ 快捷键说明

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