//--------------------------------------------------------------------------- #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<=7;x++) ((TLabel *)(ChannelBox->Controls[x]))->Caption = (" Channel "+IntToHex(x,1)+" 0 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, j; double volts; String RangeString; base = StrToInt("0x"+BaseEdit->Text); for (channel = 0;channel <= 7;channel++) { OutPortB(base+2, channel); // Set channel if ((channel % 2) == 0) { // Set gain: OutPortB(base+3, 0x00); // +/-5v range on even chans RangeString = "±5V"; } // end if else { OutPortB(base+3, 0x08); // +/-10v range on odd chans RangeString = "±10v"; } // end else 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[4] = {channel,counts,volts,RangeString}; ((TLabel *)(ChannelBox->Controls[channel]))->Caption = Format(" Channel %1x %4d %12.3f %4s",args,3); } // 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); } } //---------------------------------------------------------------------------