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

📄 s1l3.cpp

📁 德州仪器公司的6000系列的程序示例,可以看看实现什么功能,如果需要可以继续上传,配套有电子版说明
💻 CPP
字号:
//####################################################################
// S1L3.cpp - (Section 1, Lesson 3) RECEIVING AN INTEGER FROM THE HOST
//            This is the RTDX Host Client for Section 1, Lesson 3
//####################################################################

#import "..\..\..\..\cc\bin\rtdxint.dll"
#include <iostream.h>


#define VALUE_TO_SEND 5

using namespace RTDXINTLib;

int main()
{
        IRtdxExpPtr rtdx;               // Holds pointer to IRtdxExp interface
        long status;                    // Holds status of RTDX COM API calls
        HRESULT hr;                     // Holds status of generic COM API calls
        long data=VALUE_TO_SEND;        // Holds data to be sent to target
        long bufferstate;               // Holds the state of the host's write buffer

        // initialize COM
        ::CoInitialize( NULL );

        // Instantiate the RTDX COM object
        hr = rtdx.CreateInstance( __uuidof(RTDXINTLib::RtdxExp) );

        cout.setf( ios::showbase );

        if ( FAILED(hr) ) {
                cerr << hex << hr << " - Error: Instantiation failed! \n";
                return -1;
        }

        // open a channel (ichan) for writing
        status = rtdx->Open( "ichan", "W" );

        if ( status != Success ) {
                cerr << hex << status \
                     << " -  Error: Opening of channel \"ichan\" failed! \n";
                return -1;
        }

        // loop until the status of the write buffer is greater or equal to 0.
        // This means that the target is satisfied and the Host client does not
        // need to write any more data.
        do {
                rtdx->WriteI4( data, &bufferstate );

                if ( status != Success ) {
                        cerr << hex << status << " - Error: WriteI4 failed!\n";
                        return -1;
                }

                cout << "Value " << data << " was sent to the target!\n";

                // give the target enough time to catch up
                Sleep( 2000 );

                // write an integer
                status = rtdx->StatusOfWrite( &bufferstate );

                if ( status != Success ) {
                        cerr << hex << status \
                             << " - Error: Getting status of host's write buffer! \n";
                        return -1;
                }
        } while ( bufferstate < 0 );


        // close the channel
        status = rtdx->Close();

        // release the IRtdxExp interface
        rtdx.Release();

        // uninitialize COM
        ::CoUninitialize();

        return 0;
}

⌨️ 快捷键说明

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