|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2005-10-23 20:16:44
|
显示全部楼层
对于对串口感兴趣的朋友,可以参考我写的驱动,自己完成串口下载功能,请完成后放出来。串口最基本的驱动如下,在深程的东西不便放出来。
//---------------------------------------------------------------------------
bool __fastcall TSerPgm::Open (AnsiString Port)
{
static bool runonce = true;
hComm = CreateFile( Port.c_str(),
GENERIC_READ | GENERIC_WRITE,
0, //not shared
NULL, //no security
OPEN_EXISTING,
0,//No Overlapped
NULL //template
);
if (hComm == INVALID_HANDLE_VALUE)
{
// ShowMessage("Error opening serial port");
return false;
}
SetLogic (false ,resetbit);
if (runonce)
GetDelayCalib ();
runonce = false;
return true;
}
//---------------------------------------------------------------------------
void __fastcall TSerPgm::SetDTRStatus(bool b)
{
if (b)
EscapeCommFunction(hComm,SETDTR); //将DTR升至高电位
else
EscapeCommFunction(hComm,CLRDTR);//将DTR降至低电位
}
//---------------------------------------------------------------------------
void __fastcall TSerPgm::SetRTSStatus(bool b)
{
if (b)
EscapeCommFunction(hComm,SETRTS); //将RTS升至高电位
else
EscapeCommFunction(hComm,CLRRTS);//将RTS降至低电位
}
//---------------------------------------------------------------------------
void __fastcall TSerPgm::SetBreakState (bool b)
{
if (b) EscapeCommFunction (hComm, SETBREAK);
else EscapeCommFunction (hComm, CLRBREAK);
}
//---------------------------------------------------------------------------
void __fastcall TSerPgm::GetModemStatus (void)
{
bool r;
DWORD s;
r = GetCommModemStatus (hComm, &s);
if (r)
{
if (s & MS_CTS_ON)
FCD = true;
else
FCD = false;
if (s & MS_DSR_ON)
FCTS = true;
else
FCTS = false;
if (s & MS_RING_ON)
FDSR = true;
else
FDSR = false;
if (s & MS_RLSD_ON)
FRI = true;
else
FRI = false;
}
}
//--------------------------------------------------------------------------- |
|