?? unit1.cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "TDLPortIO"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// Default port
PortEdit->Text="0x378"; // LPT1:
DataEdit->Text="0x00";
// Driver is in the same directory as the demo.exe file!
DLPortIO1->DriverPath=ExtractFileDir(ParamStr(0));
// Open the DriverLINX driver
DLPortIO1->OpenDriver();
if (!DLPortIO1->ActiveHW)
MessageDlg("Could not open the DriverLINX driver.",
mtError, TMsgDlgButtons() << mbOK, 0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReadButtonClick(TObject *Sender)
{
WORD DataPort; // Port to read data from
DWORD DataRead; // Data read from port
// Get the data port address
try {
DataPort=(WORD)StrToInt(PortEdit->Text);
} catch (...) {
MessageDlg("You have specified an invalid port.\nNo action performed.",
mtError, TMsgDlgButtons() << mbOK, 0);
return;
}
// Read the data
DataRead=DLPortIO1->Port[DataPort];
DataEdit->Text="0x"+IntToHex(DataRead, 0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WriteButtonClick(TObject *Sender)
{
WORD DataPort; // Port to read data from
DWORD DataWrite; // Data to write to port
// Get the data port address
try {
DataPort=(WORD)StrToInt(PortEdit->Text);
} catch (...) {
MessageDlg("You have specified an invalid port.\nNo action performed.",
mtError, TMsgDlgButtons() << mbOK, 0);
return;
}
// Get the data to write
try {
DataWrite=(DWORD)StrToInt(DataEdit->Text);
} catch (...) {
MessageDlg("You have specified an invalid port.\nNo action performed.",
mtError, TMsgDlgButtons() << mbOK, 0);
return;
}
// Write the data
DLPortIO1->Port[DataPort]=(BYTE)(DataWrite&0xFF);
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -