//--------------------------------------------------------------------------- #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); OutPortB(base+2, 0xF0); // Set scan from Ch0 to Ch15 do { OutPortB(base, 0); // Start A/D conversion i = 0; // Wait for EOC or timeout while (((InPortB(base+8) & 0x80) == 0x80) & (i < 32000)) i++; if (i >= 32000) { // if timeout, display error & quit channel = InPortB(base) & 0x0F; ErrorStatus->SimpleText = "Error: Timeout on channel "+IntToHex(channel,1); break; } // end if channel = InPortB(base) & 0x0F; // Get channel number counts = InPort(base) >> 4; // Get channel counts // Scaling 5v range on 12 bit device = 0.00244v/count volts = (counts-2048)*0.00244; // Display results ((TLabel *)(ChannelBox->Controls[channel]))->Caption = " Channel "+IntToHex(channel,1)+" "+IntToStr(counts)+" "+FloatToStr(volts); } while ((InPort(base) & 0x0F) != 0x0F); // end while } // 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); } } //---------------------------------------------------------------------------