📄 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 + -