请问一点关于并口的问题
上次发了个帖子问了一下并口的问题,一位老大提醒用creatfile,我自己写了一段代码出了点问题,还请各位老大花点时间给解答一下
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE m_hCardInterFace;
COMMTIMEOUTS m_CommTimeouts;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
m_hCardInterFace = CreateFile("LPT1",
GENERIC_WRITE,
NULL,NULL,
OPEN_EXISTING,
NULL,
NULL);
if(m_hCardInterFace!=INVALID_HANDLE_VALUE)
{
m_CommTimeouts.ReadIntervalTimeout = 1000;//读操作两个字节之间的时间(单位:毫秒)
m_CommTimeouts.ReadTotalTimeoutMultiplier = 1000;//读操作的时间(单位:毫秒)
m_CommTimeouts.ReadTotalTimeoutConstant = 1000;
m_CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
m_CommTimeouts.WriteTotalTimeoutConstant = 1000;
SetCommTimeouts(m_hCardInterFace, &m_CommTimeouts);
}
else
{
Label1->Caption = "fail" ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char lpOutBuffer[100] = {0} ;
DWORD dwBytesWrite=1;
COMSTAT ComStat ;
DWORD dwErrorFlags;
bool bWriteStat;
ClearCommError(m_hCardInterFace,&dwErrorFlags,&ComStat);
bWriteStat = WriteFile(m_hCardInterFace,lpOutBuffer,dwBytesWrite,&dwBytesWrite,NULL);
if(!bWriteStat)
{
Label1->Caption= "write fail" ;
}
else
{
Label1->Caption = "OK" ;
}
CloseHandle(m_hCardInterFace);
}
//---------------------------------------------------------------------------
程序跟踪到WriteFile()那里就没反应了,请问是什么问题呢?