//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "PACSDK.h" #include "stdio.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //For AI modules: //The general SDK, XPacSDK.dll, supports only 87K and 7K series. //8K series AI modules have their own libraries. TLabel * lbArr[10]; TEdit * edArr[10]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { for (int i = 0; i < 10; i++) { lbArr[i] = new TLabel(this); edArr[i] = new TEdit(this); lbArr[i]->Parent = Form1; edArr[i]->Parent = Form1; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { cbbSlot->ItemIndex = 0; cbbChannel->ItemIndex = 0; RadioButton1->Checked = true;//float, engineering format int total_ch = StrToInt(cbbChannel->Items->Strings[cbbChannel->ItemIndex]); addItems2cbbSingleCh(Sender, total_ch); cbbSingleCh->ItemIndex = 0; printTextBoxs(Sender, total_ch); } //--------------------------------------------------------------------------- void __fastcall TForm1::addItems2cbbSingleCh(TObject *Sender, int total_ch) { cbbSingleCh->Items->Clear(); for (int i = 0; i < total_ch; i++) { cbbSingleCh->Items->Add(IntToStr(i)); } } //--------------------------------------------------------------------------- void __fastcall TForm1::printTextBoxs(TObject *Sender, int channel) { int x = 20; int y = 225; for (int i = 0; i < channel; i++) { //label locations: lbArr[i]->Left = x + 120 * (i % 5); lbArr[i]->Top = y + 40 * (i / 5); lbArr[i]->Width = 50; lbArr[i]->Height = 20; lbArr[i]->Caption = "CH_" + IntToStr(i); lbArr[i]->Visible = true; } for (int i = 0; i < channel; i++) { //textbox locations: x = 75; y = 225; edArr[i]->Left = x + 120 * (i % 5); edArr[i]->Top = y + 40 * (i / 5); edArr[i]->Width = 60; edArr[i]->Height = 25; edArr[i]->Text = ""; edArr[i]->Visible = true; } for (int j = channel; j < 10; j++) { lbArr[j]->Visible = false; edArr[j]->Visible = false; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) //read single channel AI { int slot = cbbSlot->ItemIndex + 1; int total_ch = StrToInt(cbbChannel->Items->Strings[cbbChannel->ItemIndex]); int ch = StrToInt(cbbSingleCh->Items->Strings[cbbSingleCh->ItemIndex]); float AI_fValue = 0; int AI_hValue = 0; char temp[32]; HANDLE h = uart_Open(""); if (RadioButton1->Checked) { pac_ReadAI(h, slot, ch, total_ch, &AI_fValue); Sleep(10); Edit1->Text = FloatToStr(AI_fValue); } else { pac_ReadAIHex(h, slot, ch, total_ch, &AI_hValue); Sleep(10); sprintf(temp, "%X", AI_hValue); Edit1->Text = AnsiString(temp); } uart_Close(h); } //--------------------------------------------------------------------------- void __fastcall TForm1::cbbChannelChange(TObject *Sender) { int total_ch = StrToInt(cbbChannel->Items->Strings[cbbChannel->ItemIndex]); printTextBoxs(Sender, total_ch); addItems2cbbSingleCh(Sender, total_ch); cbbSingleCh->ItemIndex = 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) //read All AI channels { int slot = cbbSlot->ItemIndex + 1; int total_ch = StrToInt(cbbChannel->Items->Strings[cbbChannel->ItemIndex]); float AI_fArr[10]; int AI_hArr[10]; char temp[32]; HANDLE h = uart_Open(""); if (RadioButton1->Checked) { pac_ReadAIAll(h, slot, AI_fArr); for(int i=0;iText = FloatToStr(AI_fArr[i]); } else { pac_ReadAIAllHex(h, slot, AI_hArr); for (int i = 0; i < total_ch; i++) { sprintf(temp, "%X", AI_hArr[i]); edArr[i]->Text = AnsiString(temp); } } uart_Close(h); } //---------------------------------------------------------------------------