|
The following is a step-by-step lesson on how to use ActiveX in
Borland C++ Builder
In this lession, we will use Ultimaserial ActiveX to develop a
data acquisition application with DATAQ's Starter kit.
Upgrade to
UltimaSerial (version 3) now if you are starting a
new project!
Specification of the sample program:
a) Acquire voltage signal between -10 to 10V via
Channel 1 of DI-194 at a rate of 240
Samples/second
b) The data is streamed back to the PC via COM 1
c) The input signal is displayed on a scrolling waveform window
To use UltimaSerial in Borland C++ Builder, please download
and install UltimaSerial first. The following steps show you how to program the DI-194
under Borland C++ Builder.
1) Start Borland C++ Builder, and follow Component -> Import ActiveX
control ..., and you will see:

2) In the Import ActiveX dialogue box, select DATAQ Instrument
DQChart Control.
3) Click the Install button, then OKs to install the DqChart
control to ActiveX tab to be used in Step 7)
4) Repeat 1) to 3) to install UltimaSerial control to ActiveX tab to
be used in Step 7). If you can't find UltimaSerial and DQChart in the list, you need
to install UltimaSerial control.
5) Enable Component Palette if it is not on the toolbar of Borland C++
Builder

6) If you like, you can restart Borland C++ Builder to have clean form.
(You don't need to save anything at this point)
7) On the new form, add DqChart and UltimaSerial from the ActiveX tab.
Make sure DqChart's object name is DqChart1, and UltimaSerial's object name is
UltimaSerial1.
8) Add two buttons from the Standard tab and name them Start and Stop.
Make sure Start button is object Button1 and Stop button is object Button2 so that we can
use our sample codes directly.

9) On the form, double click on Start and Stop buttons to create the codes
for them
10) In the Object Inspector, select UltimaSerial1, and add the name
"NewData" for the event NewData

11) In the code editor, change the default codes
From:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DQCHARTLib_OCX"
#pragma link "ULTIMASERIALLib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NewData(TObject *Sender, short ErrorCode)
{
}
//---------------------------------------------------------------------------
To: (Watch for
the blue text)
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DQCHARTLib_OCX"
#pragma link "ULTIMASERIALLib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
UltimaSerial1->Device=194;
UltimaSerial1->CommPort =1;
UltimaSerial1->ChannelCount=1;
UltimaSerial1->EventLevel=2;
UltimaSerial1->SampleRate=240;
UltimaSerial1->Start();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
UltimaSerial1->Stop();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NewData(TObject *Sender, short ErrorCode)
{
DQChart1->Chart (UltimaSerial1->GetData());
}
//---------------------------------------------------------------------------
12) Now you can run the program by following Run->Run, or simply
hitting F9 key!
Last update: 10/05/07
Copyright: 2000-2005 www.UltimaSerial.com
|