Windaq Add-ons
UltimaSerial
UltimaWaterfall
XChart
FFT1024
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.
-
Run Microsoft Visual C++ 2008 Express Edition
-
Start a New Project from File menu. Select Windows
Forms Application.under CLR type. Give a name MyTest2 to the project, hit OK
-
A form is created
-
Follow MyTest2->View->Toolbox to show Toolbox pane
-
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.
-
In the dialogue box "Choose Toolbox Items", select COM
components tab
-
Check both Ultimaserial and XChart Controls, hit OK. Now you
will see these two controls in the Toolbox pane:
-
Add Ultimaserial and XChart components to the form, along
with two buttons, change their text and name to Start and Stop, and a label
-
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)
-
Back in form1.cs[Design]* tab, select Ultiamserial icon, in
its property pane, select Event tab, which looks like a lightning.
-
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) {
}
-
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();
}
-
Build the solution and it should work now!
-
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
|