//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Sample0u.h" #include "acces32.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TSample0Form *Sample0Form; TLabel *CountsLabels[8]; TLabel *VoltsLabels[8]; unsigned int Address; //--------------------------------------------------------------------------- __fastcall TSample0Form::TSample0Form(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TSample0Form::ExitButtonClick(TObject *Sender) { exit(0); } //--------------------------------------------------------------------------- void __fastcall TSample0Form::TestButtonClick(TObject *Sender) { if (TestTimer->Enabled == True) { TestTimer->Enabled = False; ErrorStatus->SimpleText = ""; TestButton->Caption = "Start Test"; BaseEdit->Enabled = True; } // end if else { Address = StrToInt("0x" + BaseEdit->Text); TestButton->Caption = "Abort Test"; BaseEdit->Enabled = False; TestTimer->Enabled = True; } // end else } //--------------------------------------------------------------------------- bool TSample0Form::CheckForEOC(int Address) { byte EOCCheck; EOCCheck = InPortB(Address); return ((EOCCheck & 0x80) == 0x80); } void __fastcall TSample0Form::TestTimerTimer(TObject *Sender) { int chan, counts; unsigned int timeout; double volts; for (chan = 0; chan <= 7; chan++) { timeout = 65535; OutPortB(Address + 2, chan | 0x08); // write channel while (!CheckForEOC(Address) && (timeout > 0)) timeout--; if (timeout == 0) { ErrorStatus->SimpleText = "A/D timeout on Channel " + IntToStr(chan); CountsLabels[chan]->Caption = "A/D Timeout"; VoltsLabels[chan]->Caption = "A/D Timeout"; } // end if timeout else { counts = InPort(Address + 2) & 0x0FFF; volts = ((counts ^ 0x800) - 0x800) * 0.00244; CountsLabels[chan]->Caption = IntToStr(counts); VoltsLabels[chan]->Caption = FloatToStr(volts); } // end else } // end for chan } //--------------------------------------------------------------------------- void __fastcall TSample0Form::FormCreate(TObject *Sender) { CountsLabels[0] = CountsLabel0; CountsLabels[1] = CountsLabel1; CountsLabels[2] = CountsLabel2; CountsLabels[3] = CountsLabel3; CountsLabels[4] = CountsLabel4; CountsLabels[5] = CountsLabel5; CountsLabels[6] = CountsLabel6; CountsLabels[7] = CountsLabel7; VoltsLabels[0] = VoltsLabel0; VoltsLabels[1] = VoltsLabel1; VoltsLabels[2] = VoltsLabel2; VoltsLabels[3] = VoltsLabel3; VoltsLabels[4] = VoltsLabel4; VoltsLabels[5] = VoltsLabel5; VoltsLabels[6] = VoltsLabel6; VoltsLabels[7] = VoltsLabel7; if (InPortB(0x61) == 0xAA55) { Application->MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", IDOK); } } //---------------------------------------------------------------------------