//--------------------------------------------------------------------------- #include #include "Acces32.h" #pragma hdrstop #include "sample0u.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TSample0Form *Sample0Form; //--------------------------------------------------------------------------- __fastcall TSample0Form::TSample0Form(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TSample0Form::ExitButtonClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TSample0Form::TestButtonClick(TObject *Sender) { int x; if (TestTimer->Enabled == True) { TestTimer->Enabled = False; for (x=0; x<=15; x++) ((TLabel *)(ChannelBox->Controls[x]))->Caption = " Channel "+IntToHex(x,1)+" 0 0"; ErrorStatus->SimpleText = ""; TestButton->Caption = "Start Test"; } // end if else { TestTimer->Enabled = True; TestButton->Caption = "Abort Test"; } // end else } // end TestButtonClick //--------------------------------------------------------------------------- void __fastcall TSample0Form::TestTimerTimer(TObject *Sender) { Word base; int channel, counts, i; double volts; base = StrToInt("0x"+BaseEdit->Text); // Get User inputted base address for (channel=0; channel<=15; channel++) { // Set Channel OutPortB(base+2, (InPortB(base+2) & 0xF0) + channel); // Reset EOC interrupt OutPortB(base+1, 0); // Start A/D conversion OutPortB(base, 0); // Wait for EOC or timeout i = 0; while ( ((InPortB(base+2) & 0x80) < 0x80) & (i <= 1000) ) i++; // if timeout display error and exit program if (i > 1000) { ErrorStatus->SimpleText = "Error: Timeout on channel "+ IntToHex(channel,1); break; } // end if // Get count data counts = InPortB(base); // Scaling 5v range on 8 bit device = 0.039 volts/count volts = (counts - 128) * 0.039; // Show data TVarRec args[3] = {channel,counts,volts}; ((TLabel *)(ChannelBox->Controls[channel]))->Caption = Format(" Channel %1x %3d %12.3f",args,2);//+IntToHex(channel,1)+" "+IntToStr(counts)+" "+FloatToStr(volts); } // end of for channel } // end TestTimerTimer //--------------------------------------------------------------------------- void __fastcall TSample0Form::FormCreate(TObject *Sender) { 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); } } //---------------------------------------------------------------------------