本文介绍了如何将ESC / POS传递给writefile fileapi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre lang =text我对ESC / POS命令有些麻烦。下面的代码打印出很好的常规文本,但当它关闭时,ESC / POS命令打印机什么也不做。>



<pre lang="text"I have some trouble with ESC/POS commands. The code below prints well regular text, but when it comes down the ESC/POS commands the printer does nothing.>

HANDLE	CreateFileResult;
BOOL    bResult;
PSP_INTERFACE_DEVICE_DETAIL_DATA dummy = GetDevices();

if (dummy != 0)
	{
	CreateFileResult = CreateFile(dummy->DevicePath, 
                                      GENERIC_WRITE | GENERIC_READ, 
                                      FILE_SHARE_WRITE | FILE_SHARE_READ, 
                                      NULL, 
                                      OPEN_ALWAYS, 
                                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 
                                      NULL);

		if (INVALID_HANDLE_VALUE == CreateFileResult) 
        {
		  std::cout << "Handle Failed " << std::endl;
		}
		else
		{
			
		  char cData1[] = { (CHAR)27, (CHAR)112 , CHAR(0), CHAR(255), CHAR(0) };
		  char cData2[] = { 0x1b, 0x70 ,0x00 ,0xFF ,0x00 };
			
			DWORD dwBytesToWrite = (DWORD)strlen(cData2);
			DWORD bytesWritten;
			OVERLAPPED osWrite = { 0,0,0 };
				
			
			WriteFile(CreateFileResult, cData2, dwBytesToWrite, &bytesWritten, &osWrite);
         }





我的尝试:



我尝试了很多不同的方法来传递数据(参见cData1& cData2)。任何人都可以帮助指出如何传递命令的正确方法吗?谢谢,Oliver。



What I have tried:

I have tried many different ways how to pass on the data (see cData1 & cData2). Can anyone help with pointing out the correct way how to pass the command? Thanks, Oliver.

推荐答案


DWORD dwBytesToWrite = sizeof(cData2);

这将写入所有五个字节。

That will write all five bytes.


这篇关于如何将ESC / POS传递给writefile fileapi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 12:34