Python 3.x Epson ESCPOS使用ESC R n命令打印丹麦字符

Python 3.x Epson ESCPOS使用ESC R n命令打印丹麦字符,python-3.x,epson,pos,escpos,Python 3.x,Epson,Pos,Escpos,我使用的是爱普生TM-T20II热敏收据打印机,我需要用丹麦字符(æ,ø,å)打印收据。描述了用于字符语言选择的ESCPOS代码。我的Python代码如下 import win32print import six #create some raw data rawdata = b'\x1b\x40' #Instantiate the printer ESC @ rawdata = rawdata + b'\x1b\x52\x10' #Select the Danish II character

我使用的是爱普生TM-T20II热敏收据打印机,我需要用丹麦字符(æ,ø,å)打印收据。描述了用于字符语言选择的ESCPOS代码。我的Python代码如下

import win32print
import six
#create some raw data
rawdata = b'\x1b\x40' #Instantiate the printer ESC @
rawdata = rawdata + b'\x1b\x52\x10' #Select the Danish II character set as in documentation ESC R 
where n = 10
rawdata = bytes('Print æ,ø,å', 'utf-8') + b'\n' + b'\x1d\x56' + six.int2byte(66) + b'\x00' #print 
some text and cut

#Creating the printing job in Windows 10 and send the raw text to the printer driver
printer = win32print.OpenPrinter('EPSON TM-T20II Receipt')
hJob = win32print.StartDocPrinter(printer, 1, ("Test print", None, "RAW"))
win32print.WritePrinter(printer, rawdata)
win32print.EndPagePrinter(printer)
win32print.ClosePrinter(printer)

我的问题是我打印出了一些奇怪的字符。我还通过按住进纸按钮并打开打印机电源,将打印机设置为Danish II。我错过了什么?

目前,您可能想要尝试的是将下面的编码规范从utf-8更改为cp865

rawdata = bytes('Print æ,ø,å', 'utf-8') + b'\n' + b'\x1d\x56' + six.int2byte(66) + b'\x00' #print  
如果不起作用,您应该停止使用win32print并切换到pyserial。
还需要切换打印机模式,卸载高级打印机驱动程序,并安装打印机串行端口驱动程序。
然后,应用程序需要使用原始ESC/POS命令创建所有打印数据

原因如下


您可以在此处获得TM-T20II的高级打印机驱动程序以及手动和示例程序。

根据示例程序“步骤1打印设备字体”,为了向打印机发送原始ESC/POS命令,需要选择特定的设备字体

使用设备字体打印“Hello APD”,并自动打印收据

C++中示例源代码的核心如下所示

下面是它在VB中的外观

将它们移植到Python的win32print不是很困难或不可能吗?
Wi32打印API似乎没有能力在打印中间自定义字体。

StartDocPrint和WritePrinter有以下解释。

请注意,打印机驱动程序可能会忽略请求的数据类型

适用于将原始PostscriptHPGL文件复制到打印机


ESC/POS命令不是原始PostScript或HPGL,EPSON的高级打印机驱动程序不一定通过win32print调用发送此类数据

您想让TM-T20II作为Windows标准桌面页面打印机使用吗?如果没有,请将打印机更改为串行端口模式,重新安装设备驱动程序,并使用或发送ESC/POS命令。我知道python escpos,但它没有我所有的需求。例如,据我所知,python escpos不支持丹麦字符。如果python escpos缺少功能,您应该修改它以添加功能,或者切换到pyserial并自己创建和发送所有escpos命令。在原始模式下使用pyserial和在问题中编写的win32print不一样吗?
CDC dc;
/*
 * Create the device context for the printer
 */
if(! dc.CreateDC(EPS_DRIVER_NAME, EPS_PRINTER_NAME, NULL, NULL) )
{
    AfxMessageBox(_T("Printer is not available."));
    return;
}

dc.StartDoc(&di);

/*
 * Perform the printing of the text
 */
CFont font, *old;
font.CreatePointFont(95, "FontA11", &dc);
old = dc.SelectObject(&font);
dc.TextOut(20, 10, "Hello APD!");
dc.SelectObject(old);
font.DeleteObject();

dc.EndPage();
dc.EndDoc();
dc.DeleteDC();
Dim printFont As New Font("Lucida Console", 8, FontStyle.Regular, GraphicsUnit.Point) ' Substituted to FontA Font

e.Graphics.PageUnit = GraphicsUnit.Point

' Print the string at 6,4 location using FontA font.
e.Graphics.DrawString("Hello APD!", printFont, Brushes.Black, 6, 4)

' Indicate that no more data to print, and the Print Document can now send the print data to the spooler.
e.HasMorePages = False