//--------------------------------------------------------------------------- #include #include "Acces32.h" #pragma hdrstop #include "sample0u.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TSample0Form *Sample0Form; Word base; //--------------------------------------------------------------------------- __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<=7;x++) ((TLabel *)(ChannelBox->Controls[x]))->Caption = (" Channel "+IntToHex(x,1)+" 0 0"); ErrorStatus->SimpleText = ""; TestButton->Caption = "Start Test"; } // end if else { base = StrToInt("0x"+BaseEdit->Text); TestTimer->Enabled = True; TestButton->Caption = "Abort Test"; } // end else } // end TestButtonClick //--------------------------------------------------------------------------- void __fastcall TSample0Form::TestTimerTimer(TObject *Sender) { int channel, counts, i, j; double volts; for (channel = 0;channel <= 7;channel++) { OutPortB(base+2, channel); // Set channel for (i = 0;i < 32000;i++); // Wait for settle count, this is an empty loop OutPortB(base+1, 0); // Start A/D conversion j = 0; // Wait for EOC or timeout while (((InPortB(base+2) & 0x80) >= 0x80) & (j < 32000)) j++; if (j >= 32000) { ErrorStatus->SimpleText = "Timeout on Channel "+IntToHex(channel,1); break; } // end if counts = InPort(base) >> 4; // Read count data // Scaling 5v range on 12 bit device = 0.00244v/count volts = (counts-2048.0)*0.00244; // Display results TVarRec args[3] = {channel,counts,volts}; ((TLabel *)(ChannelBox->Controls[channel]))->Caption = Format(" Channel %1X %4d %g",args,2); } // end for } // 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); } } //---------------------------------------------------------------------------