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

📄 s1l5.cpp

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

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


#define MAX_ELEMENTS 10;

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
        VARIANT sa;                     // holds a pointer to a SAFEARRAY
        SAFEARRAYBOUND rgsabound[1];    // set the dimension of the SAFEARRAY
        long bufferstate;               // holds the state of the host's write buffer
        long data;                      // holds the element data of SAFEARRAY during

        // initialize COM
        ::CoInitialize( NULL );

        // initialize VARIANT
        ::VariantInit( &sa );

        // 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;
        }

        // set the VARIANT to be a SAFEARRAY of 32-bit integers
        sa.vt = VT_ARRAY | VT_I4;

        // set the lower bound of the SAFEARRAY
        rgsabound[0].lLbound = 0;

        // set the number of elements in the SAFEARRAY
        rgsabound[0].cElements = MAX_ELEMENTS;

        // create the SAFEARRAY
        sa.parray = SafeArrayCreate( VT_I4, 1, rgsabound );

        // fill up the SAFEARRAY with values
        data = 1;
        for (long i = 0; i < (signed)sa.parray->rgsabound[0].cElements; i++) {
                hr = ::SafeArrayPutElement( sa.parray, &i, (long*)&data);
                data++;
        }

        // send data to the target
        status = rtdx->Write(sa, &bufferstate);

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

        // print out data
        for (long j=0; j<(signed)sa.parray->rgsabound[0].cElements; j++) {
                hr = ::SafeArrayGetElement( sa.parray, &j, (long*)&data);
                cout << "Value " << data << " was sent to the target!\n";
        }

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

        // release the RTDX COM Object
        rtdx.Release();

        // clear VARIANT
        ::VariantClear(&sa);

        // unitialize COM
        ::CoUninitialize();

        return 0;
}

⌨️ 快捷键说明

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