//--------------------------------------------------------------------------- #include #pragma hdrstop #include "acces32.h" #include "DACu.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TMainForm *MainForm; #define maxch 6 double span = 5.0, offset = 2.5; unsigned curval = 0; unsigned address; bool RunFlag; unsigned ConvertForOutput(unsigned v) { if (MainForm->GroupChannel->ItemIndex < maxch) OutPort(address + (MainForm->GroupChannel->ItemIndex * 2), v); else for (int i = 0; i < maxch; i++) OutPort(address + (i * 2), v); return v; } AnsiString IntToBin(unsigned input) { AnsiString temp; unsigned i; double f; temp = ""; for (i = 12; i >= 1; i--) temp += (input & (1 << (i - 1)))?'1':'0'; temp += "xxxx "; f = input*span/4096-offset; temp += IntToHex(int(input), 3) + ' ' + FloatToStrF(f, ffFixed, 6, 3); temp += (MainForm->GroupRange->ItemIndex > 4)?" mA":" Volts"; return temp; } void UpdateDAC() { switch(MainForm->GroupRange->ItemIndex){ case 0:offset=2.5;span=5.0;break; case 1:offset=5.0;span=10.0;break; case 2:offset=10.0;span=20.0;break; case 3:offset=0.0;span=5.0;break; case 4:offset=0.0;span=10.0;break; case 5:offset=-1.0;span=4.0;break; case 6:offset=-4.0;span=16.0;break; } MainForm->LOutput->Caption=IntToBin(ConvertForOutput(curval)); } //--------------------------------------------------------------------------- __fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TMainForm::ValueChange(TObject *Sender) { curval=Value->Position; UpdateDAC(); } //--------------------------------------------------------------------------- void __fastcall TMainForm::FormCreate(TObject *Sender) { int i; GroupChannel->Items->Clear(); for (i = 0; i < maxch; i++) GroupChannel->Items->Append("Channel" + IntToStr(i)); GroupChannel->Items->Append("All Channels"); GroupChannel->ItemIndex = 0; Memo1->Lines->Append(""); Memo1->Lines->Append("Please configure the dialog options shown to reflect the" " settings on the card that is installed. The card''s output voltage shown" " onscreen will only be correct if these settings are correct." " Refer to the card''s manual for specifics about jumper settings and switches."); Memo1->ScrollBars=ssVertical; 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); } } //--------------------------------------------------------------------------- void __fastcall TMainForm::ExitButtonClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TMainForm::InitializeClick(TObject *Sender) { unsigned data = 0; data = StrToInt("0x" + ISAEdit->Text); if (data >= 0x100) { address=data; RunFlag=1; } else Beep(); if (RunFlag) GroupOutput->Visible = 1; } //--------------------------------------------------------------------------- void __fastcall TMainForm::GroupRangeClick(TObject *Sender) { UpdateDAC(); } //--------------------------------------------------------------------------- void __fastcall TMainForm::FormActivate(TObject *Sender) { ISAEdit->SetFocus(); } //---------------------------------------------------------------------------