大家好,第一次发帖,请多关照。
现象描述:
PC端并口连接设备打印机(设备自带打印机),生产过程中实时发送Windows字体的汉字(例如 张三),随机出现漏打印,即设备返回执行成功,但色带打印机并没有真正打印出来。
软件结构: VB主动程序,DLL动态库(整合Windows字体,写并口操作),设备底层驱动打印
代码如下(摘抄 CreateFile,WriteFile)
int OpenLPT()
{
if ((hdlPrinter = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL )) == (HANDLE) -1 )
{
return -1 ;
}
return 0;
}
int CloseLPT ()
{
if (hdlPrinter != (HANDLE) -1) {
CloseHandle(hdlPrinter);
hdlPrinter = (HANDLE)-1;
return 0;
}
else
return -1;
}
int WriteLPT(char * chCmd, int nLenCmd)
{
BOOL rWriteFile;
DWORD dwByteWritten;
DWORD DelayTime, BeginTime;
OVERLAPPED Write_OS;
//memset(&Write_OS, 0, sizeof(OVERLAPPED));
DelayTime = 30000;
BeginTime = GetTickCount();
do{
OpenLPT();
rWriteFile = WriteFile(hdlPrinter, chCmd, nLenCmd, &dwByteWritten, NULL);
//20080429 by jacky*************************/
if(FlushFileBuffers(hdlPrinter) == FALSE)
{
Pt3080_LogFun(chCmd,0);//记录日志
}
/*******************************************/
CloseLPT();
LogFileWrite(chCmd,nLenCmd);
if (rWriteFile != 0)
return 0;
else
return -1;
}while((GetTickCount()-BeginTime)
return -1;
}
另:为何FlushFileBuffers()每次执行都不会成功?
问题困扰多时,请诸位仁兄多多帮忙。