//--------------------------------------------------------------------------- #include #pragma hdrstop #include "pad128.h" #include "ACCES32.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" unsigned int base; unsigned int ch = 0; //number of channels selected unsigned int scans = 0; //number of times to scan each channel unsigned int buffer[255]; //place to store data read from the fifo //chbox and chedit dynamically created at runtime TEdit *chedit[8]; TCheckBox *chbox[8]; TMainForm *MainForm; void STARTCONVERSION(void){ OutPort(base + 16, 0x0001); //send START to chip } void RESET(void){ OutPort(base + 16, 0x0002); //send RESET to chip } void CALIBRATE(void){ OutPort(base + 16, 0x0008); //calibrate } void SETCHANNEL(void) { unsigned int offset = 0; unsigned int val = 0; unsigned int loopval = 0; for (int i = 0; i < 8; i++){ if(chbox[i]->Checked){ OutPort(base+offset,val); offset+=2; //inc ram pointer address only if channel is selected ch++; //number of channels selected loopval = val; } val+=4; //inc value to write whether channel is selected or not } offset-=2;//set offset to last outport value to write loop bit OutPort(base+offset, loopval + 1); //set loop bit on last box checked } //--------------------------------------------------------------------------- __fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TMainForm::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); } unsigned int i; for(i = 0; i < 8; i++){ chedit[i] = new TEdit(this); //data display edit boxes chedit[i]->Parent = DataPanel; chedit[i]->Left = 8 + (i * 48); chedit[i]->Top = 32; chedit[i]->Width = 46; chedit[i]->Height = 21; chedit[i]->TabStop = false; chedit[i]->Text = " "; } for(i = 0; i < 4; i++){ chbox[i] = new TCheckBox(this); //channel select boxes chbox[i]->Parent = SetupPanel; chbox[i]->Left = 192; chbox[i]->Top = 32 + (i * 17); chbox[i]->Width = 97; chbox[i]->Height = 17; chbox[i]->Checked = false; chbox[i]->TabOrder = i + 2; //tab stops 0 and 1 are base and scan edit boxes chbox[i]->Caption = "Channel " + (IntToStr(i)); } for(i = 4; i < 8; i++){ chbox[i] = new TCheckBox(this); chbox[i]->Parent = SetupPanel; chbox[i]->Left = 296; chbox[i]->Top = 32 + ((i-4) * 17); chbox[i]->Width = 97; chbox[i]->Height = 17; chbox[i]->Checked = false; chbox[i]->TabOrder = i + 2; //tab stops 0 and 1 are base and scan edit boxes chbox[i]->Caption = "Channel " + (IntToStr(i)); } } void __fastcall TMainForm::DataButtonClick(TObject *Sender) { base = StrToInt("0x" + BaseEdit->Text); scans = StrToInt(ScansEdit->Text); RESET(); CALIBRATE(); if (RunTimer->Enabled){ RunTimer->Enabled = false; DataButton->Caption = "Get Data"; }else{ RunTimer->Enabled = true; DataButton->Caption = "Stop Data"; } } //--------------------------------------------------------------------------- void __fastcall TMainForm::RunTimerTimer(TObject *Sender) { unsigned int x; RESET(); SETCHANNEL(); RESET(); STARTCONVERSION(); for(x = 0; x < scans; x++){ for(int i = 0; i < 8; i++){ if(chbox[i]->Checked){ //this delay is appropriate for a 200MHz Pentium //for faster computers, call ProcessMessages() more than once Application->ProcessMessages(); //delay //Application->ProcessMessages(); //delay //Application->ProcessMessages(); //delay buffer[x * (ch+1) + i] = InPort(base+24)&0x0FFF;//read data into buffer } //mask off upper nybble which could be set to contain ram instruction number else buffer[x * (ch+1) + i] = 0;//put 0 in buffer if the channel is not setup } } for(x = 0; x < scans; x++){ for(int i = 0; i < 8; i++){ if(chbox[i]->Checked){ chedit[i]->Text = " " + IntToHex(int(buffer[x * (ch+1) + i]),3); }else chedit[i]->Text = " ";//print nothing if channel not setup } } ch = 0; //reset for next time through loop, incremented in SETCHANNEL } //--------------------------------------------------------------------------- void __fastcall TMainForm::ExitButtonClick(TObject *Sender) { Application->Terminate(); } //---------------------------------------------------------------------------