UltimaSerial How to use ActiveX in Visual C++ (VC++) 2008 Express Edition (.NET)
 

Windaq add-ons
Windaq Add-ons


Data logger
UltimaSerial

Spectrogram
UltimaWaterfall

 

Ultimaserial XChart
XChart

 

FFT1024
FFT1024

 

Ultimaserial Classroom
Lessons

The following is a step-by-step lesson on how to use ActiveX in Microsoft Visual C++ 2008 Express Edition (.NET)

32 or 64-bit?

Most ActiveXs are 32-bit components, you must select 32-bit code option when using 64-bit compilers. Both 32-bit and 64-bit Windows runs 32-bit applications properly. 

In this lesson, we will use Ultimaserial ActiveX to develop a data acquisition application to use  DATAQ's Starter kit DI-158 via USB port. 

  1. Run Microsoft Visual C++ 2008 Express Edition

  2. Start a New Project from File menu. Select Windows Forms Application.under CLR type. Give a name MyTest2 to the project, hit OK

     

  3. A form is created


  4. Follow MyTest2->View->Toolbox to show Toolbox pane


  5. Inside the Toolbox pane, right click to bring out the menu, click Choose Items... It will take a while before the dialog box "Choose Toolbox Items" appears.

  6. In the dialogue box "Choose Toolbox Items", select COM components tab


  7. Check both Ultimaserial and XChart Controls, hit OK. Now you will see these two controls in the Toolbox pane:


  8. Add Ultimaserial and XChart components to the form, along with two buttons, change their text and name to Start and Stop, and a label


  9. Double click on the two buttons to create codes (you will need to switch between the tabs of form1.h* and form1.h[Design]* to do so)

  10. Back in form1.cs[Design]* tab, select Ultiamserial icon, in its property pane, select Event tab, which looks like a lightning.


  11. Double click on NewData event, now Visual C++ 2008 should generate codes should be like this:

    private: System::Void Start_Click(System::Object^ sender, System::EventArgs^ e) {

    }

    private: System::Void Stop_Click(System::Object^ sender, System::EventArgs^ e) {

    }

    private: System::Void axUltimaSerial1_NewData(System::Object^ sender, AxULTIMASERIALLib::_DUltimaSerialEvents_NewDataEvent^ e) {

    }

     

  12. Add our codes:

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    axUltimaSerial1->Device=158;

    axUltimaSerial1->CommPort =0;

    axUltimaSerial1->SampleRate=20;

    axUltimaSerial1->ChannelCount =1;

    axUltimaSerial1->AcquisitionMode=ULTIMASERIALLib::enumMode::NoCondition;

    axUltimaSerial1->Start();

    }

    private: System::Void Stop_Click(System::Object^ sender, System::EventArgs^ e) {

    axUltimaSerial1->Stop();

    }

    private: System::Void axUltimaSerial1_NewData(System::Object^ sender, AxULTIMASERIALLib::_DUltimaSerialEvents_NewDataEvent^ e) {


    //
    GetData returns a variant that contains a 16-bit integer array. The casting below converts it to a safearray for easy handling.

    array
    <Int16, 2>^ Data = (array<Int16, 2>^)axUltimaSerial1->GetData();

    axXChart1->Chart(Data);

    label1->Text = Data[0, 0].ToString();

    }


  13. Build the solution and it should work now!

  14. To create a new waveform from the data collected and chart it, use a managed array. Please take a look at this and you should be able to construct your own codes:

    #define ARRAY_SIZE 200

    array< short, 2 >^ local = gcnew array< short, 2 >(2, ARRAY_SIZE);
    int i;

    for (i = 0 ; i < ARRAY_SIZE ; i++) {
    local[0,i] = 20000;
    }
    axXChart1->Chart (local);

 



 

 

Last update: 03/14/22

Copyright: 2000-2005  www.UltimaSerial.com