//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "PACSDK.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; const int ORIGIN_X = 16; const int ORIGIN_Y = 88; const int LABEL_WIDTH = 50; const int LABEL_HEIGHT = 20; const int GAP_LABEL_CIRCLE = 5; const int DIAMETER = LABEL_WIDTH; const int GAP_HORIZONTAL = 5; const int GAP_VERTICAL = 10; TLabel * lbChName[32]; unsigned long diValue; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { for (int i = 0; i < 32; i++) { lbChName[i] = new TLabel(this); lbChName[i]->Width = LABEL_WIDTH; lbChName[i]->Height = LABEL_HEIGHT; lbChName[i]->Left = ORIGIN_X + (DIAMETER + GAP_HORIZONTAL) * (i % 8); lbChName[i]->Top = ORIGIN_Y + (LABEL_HEIGHT + GAP_LABEL_CIRCLE + DIAMETER + GAP_VERTICAL) * (i / 8); lbChName[i]->Caption = "CH_" + IntToStr(i); lbChName[i]->Parent = Form1; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { cbbSlot->ItemIndex = 0; cbbChannel->ItemIndex = 0; PaintBox1->Refresh(); cbbChannelChange(Sender); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) //Read DI { char temp[32]; int slot = cbbSlot->ItemIndex + 1; int total_ch = StrToInt(cbbChannel->Items->Strings[cbbChannel->ItemIndex]); HANDLE h = uart_Open(""); diValue = 0; pac_ReadDI(h, slot, total_ch, &diValue); uart_Close(h); Edit1->Text = IntToHex((int)diValue, total_ch/4); PaintBox1->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TForm1::cbbChannelChange(TObject *Sender) { int total_ch = StrToInt(cbbChannel->Items->Strings[cbbChannel->ItemIndex]); for (int i = 0; i < 32; i++) { if (i < total_ch) lbChName[i]->Visible = true; else lbChName[i]->Visible = false; } PaintBox1->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TForm1::PaintBox1Paint(TObject *Sender) { int total_ch = StrToInt(cbbChannel->Items->Strings[cbbChannel->ItemIndex]); int x1, y1, x2, y2; for (int i = 0; i < total_ch; i++) { if (pac_GetBit(diValue, i)) PaintBox1->Canvas->Brush->Color = clRed; else PaintBox1->Canvas->Brush->Color = clBlack; x1 = ORIGIN_X + (DIAMETER + GAP_HORIZONTAL) * (i % 8); y1 = LABEL_HEIGHT + GAP_LABEL_CIRCLE + (LABEL_HEIGHT + GAP_LABEL_CIRCLE + DIAMETER + GAP_VERTICAL) * (i / 8); x2 = x1 + DIAMETER; y2 = y1 + DIAMETER; PaintBox1->Canvas->Ellipse(x1, y1, x2, y2); } } //---------------------------------------------------------------------------