打印机编程
打印机编程

Visual C++6.0是开发Windows应用程序的强大工具,但是要通过它实现程序的打印功能,一直是初学者的一个难点,经常有朋友询问如何在VC中实现打印功能,他们往往感到在MFC提供的框架内实现这个问题很复杂,不知道如何下手。
本例针对这个问题,介绍一种简单的方法实现文字串的打印功能,读者朋友可以在此基础上稍微改动一下,就可以实现文件、图像的打印功能。
一、实现方法 在Windows操作系统下,显示器、打印机和绘图仪都被视为输出设备,正常情况下,系统默认的输出设备是显示器。
要使用打印机,首先需要创建一个指向打印机的设备环境句柄,然后通过该句柄调用相关的绘图函数把所需的文字和图形输出至打印机上。
当打印结束后,删除这个设备环境句柄即可。
当Windows系统中安装好打印机后,系统总是自动设置一个打印机为系统的默认打印机,在Windows的启动配置文件Win.ini中的[window]段中列出了带有关键字device的默认打印机。
下面是某一机器中Win.ini中的[Windows]字段的内容:[windows]load=run=NullPort=Nonedevice=HP LaserJet 4050(computer000),HPBFDB1,LPT1 在上述关键字device后的字符串中,包含了系统中默认打印机的三个重要属性,它们依次是打印机的设备名HP LaserJet 4050(computer000),驱动程序名是HPBFDB1,输出端口为LPT1。
为了操纵系统默认的打印机,实现程序的打印功能,在程序中可调用API函数GetProfileString()从Win.ini文件中获得device这个设备字符串,该函数的原型为:DWORD GetProfileString( LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize)。
escpos c编程示例

escpos c编程示例ESC/POS是一种用于打印机控制的指令集,它使用C语言编程实现打印机的控制和打印任务的管理。
本文将介绍一些ESC/POS的C编程示例,帮助读者了解如何使用ESC/POS指令集来控制打印机。
ESC/POS是一种打印机控制指令集,它定义了打印机的各种功能和操作指令。
使用ESC/POS指令集,我们可以控制打印机的打印样式、页面布局、字体设置等。
下面是一些常用的ESC/POS指令示例。
1. 打印文本要打印文本,我们可以使用指令`printf`来发送文本内容到打印机。
例如,要打印一行文本"Hello, World!",可以使用以下代码:```printf("Hello, World!\n");```2. 设置字体要设置打印机的字体,可以使用指令`fprintf`来发送字体设置指令。
例如,要设置打印机的字体为宋体,可以使用以下代码:```fprintf(printer, "\x1B\x4D\x00"); // 设置字体为宋体```3. 打印图片要打印图片,可以使用指令`fprintf`将图片数据发送到打印机。
例如,要打印一个位图图片,可以使用以下代码:```fprintf(printer, "\x1B\x2A\x21\x00\x00\x00\x01"); // 设置位图模式fprintf(printer, "\x1B\x2A\x21\x01\x00\x00\x01"); // 打印位图数据```4. 设置对齐方式要设置打印机的对齐方式,可以使用指令`fprintf`发送对齐设置指令。
例如,要设置打印机的对齐方式为居中对齐,可以使用以下代码:```fprintf(printer, "\x1B\x61\x01"); // 设置对齐方式为居中对齐```5. 设置打印纸张大小要设置打印机的纸张大小,可以使用指令`fprintf`发送纸张大小设置指令。
三洋打印机浏览器编程手册说明书

SANEI Printer BrowserProgramming manualJAN 28, 2021 Rev1.0.0This manual provides information on the design guidelines concerning Sanei Printer Browser that customers need to build Web applications.Caution・Sanei Printer Browser is a copyrighted work of Sanei Electric Co., Ltd. (hereinafter referred to as Sanei Electric). Copyright and other rights concerning this product belong to Sanei Electric.・Sanei Electric does not guarantee the absence of defects in the Sanei Printer Browser and is not liable for any damages resulting from the use of the information contained in this manual.・Sanei Electric shall never be liable under any circumstances for any direct or indirect loss or damage in connection with the use of Sanei Printer Browser.Sanei Electric Co., Ltd.Unauthorized reproduction prohibited.The contents of this document are subject to change without notice.Android is a trademark of Google Inc.Table of Contents1. INTRODUCTION (3)2. OPERATING ENVIRONMENT (3)3. SUPPORTED PRINTERS (3)4. ABOUT API (4)5. API LIST (5)5-1. discoverUsbPrinter (7)5-2. discoverBlePrinter (7)5-3. discoverBthPrinter (8)5-4. connectUsbPrinter (8)5-5. connectBlePrinter (9)5-6. connectBthPrinter (9)5-7. connectNetworkPrinter (10)5-8. disconnectPrinter (10)5-9. isPrinterConnected (10)5-10. printString (10)5-11. printString (Encoding specified) (11)5-12. setFontStyle (11)5-13. setFontStyle (Underline thickness specified) (11)5-14. setFontType (11)5-15. setFontMagnification (12)5-16. setFontColor (12)5-17. setFontSmoothing (12)5-16. setAlignment (12)5-17. setCodePage (13)5-18. setInternationalChar (14)5-19. printBarcode (14)5-20. printQR (15)5-21. printPDF417 (15)5-22. setBarcodeModification (16)5-23. printBitmap (16)5-24. printBitmap (Print Position and dithering designation) (16)5-25. linefeed (16)5-26. paperFeed (17)5-27. printStringAndroidFont (17)5-28. initPrinter (17)5-29. startPageMode (17)5-30. endPageMode (18)5-31. setPageAttribute (18)5-32. getStatus (19)5-33. outputRawDataByte (20)5-34. outputRawDataBase64 (20)5-35. inputRawData (20)5-36. inputRawData (20)1. IntroductionThe SANEI Printer Browser is a browser app supportable to print directly from a web program (Javascript) to our printer.To prepare for using this browser app, you can download the sample program in the following URL.https://www.sanei-elec.co.jp/wp/wp-content/uploads/2021/02/sample.zipThis is a simple print sample using Javascript.This manual describes the command syntax for Javascript required for printing, referring to this sample program.2. Operating EnvironmentRuntime version: 1.8.0 or laterAndroid OS: Ver 7.1.1 or later3. Supported Printers★ Memory switch settingsSet the memory switch settings for all printer models as follows.OFFLINE BUSY = OFFAct. For Driver = INVALID4. About API(1) type of dataThe data handled by the Javascript API is number, strings, Boolean, and object.Character strings that are difficult to handle depending on the type of API are converted to JSON format or Base64 and used.(2) Calling APIThe API can be called easily by adding “Printer.” at the top of the call.No external library is needed to build this extension, and no preparation is required to call theAPI.(3) Get Return ValuesThe return value can be obtained directly from the API.The return value is mainly used after conversion because it is returned in JSON format or Base64.The Boolean can be used without conversion.5. API ListThe list of printer device functions is as follows.5-1. discoverUsbPrinterGet the name of the USB printer port that can be connected.function:Printer.discoverUsbPrinter(timeoutMillis)Argument:timeoutMillis Timeout period (milliseconds)Return value:USB printer port name in JSON format (array)Remarks:Return the obtained USB printer port name to its original form with "JSON.parse".Example:// Get USB Printer Port Namevar result = Printer.discoverUsbPrinter(0);//Converts the USB printer port name in JSON format to its original format.var printers = JSON.parse(result);// Get the first USB printer port name.var first_printer = printers[0];5-2. discoverBlePrinterGet the name of the Bluetooth (BLE) printer port that can be connected.function:Printer.discoverBlePrinter(timeoutMillis)Argument:timeoutMillis Timeout period (milliseconds)Return value:Bluetooth (BLE) printer port name in JSON format (array)Remarks:Return the obtained Bluetooth (BLE) printer port name to its original form with"JSON.parse".Example:// Get Bluetooth (BLE) Printer Port Namevar result = Printer.discoverBlePrinter(0);//Converts the Bluetooth (BLE) printer port name in JSON format to its original format.var printers = JSON.parse(result);// Get the first Bluetooth (BLE) printer port name.var first_printer = printers[0];Get the name of the Bluetooth (SPP) printer port that can be connected.function:Printer.discoverBthPrinter(timeoutMillis)Argument:timeoutMillis Timeout period (milliseconds)Return value:Bluetooth(SPP) printer port name in JSON format (array)Remarks:Return the obtained Bluetooth (SPP) printer port name to its original form with "JSON.parse".Example:// Get Bluetooth (SPP) Printer Port Namevar result = Printer.discoverBthPrinter(0);//Converts the Bluetooth (SPP) printer port name in JSON format to its original format.var printers = JSON.parse(result);// Get the first Bluetooth (SPP) printer port name.var first_printer = printers[0];5-4. connectUsbPrinterConnect to the specified USB printer port.function:Printer.connectUsbPrinter(printer)Argument:printer USB printer port name in JSON format.Return value:Returns the success or failure of the connection as a Boolean.true Successful connectionfalse Connection failedRemarks:Use "JSON. Stringify" to convert the USB printer port name to JSON format.Example://Converts USB printer port names to JSON format.var jprinter = JSON.stringify(printer);// Connect to USB printer portvar status = Printer.connectUsbPrinter(jprinter)Connect to the specified Bluetooth (BLE) printer port.function:Printer.connectBlePrinter(printer)Argument:printer Bluetooth (BLE) printer port name in JSON format.Return value:Returns the success or failure of the connection as a Boolean.true Successful connectionfalse Connection failedRemarks:Use "JSON. Stringify" to convert the Bluetooth (BLE) printer port name to JSON format.Example:// Converts Bluetooth (BLE) printer port names to JSON format.var jprinter = JSON.stringify(printer);// Connect to Bluetooth (BLE) USB printer portvar status = Printer.connectBlePrinter(jprinter)5-6. connectBthPrinterConnect to the specified Bluetooth (SPP) printer port.function:Printer.connectBthPrinter(printer)Argument:printer Bluetooth (SPP) printer port name in JSON format.Return value:Returns the success or failure of the connection as a Boolean.true Successful connectionfalse Connection failedRemarks:Use "JSON. Stringify" to convert the Bluetooth (SPP) printer port name to JSON format.Example:// Converts Bluetooth (SPP) printer port names to JSON format.var jprinter = JSON.stringify(printer);// Connect to Bluetooth (SPP) printer portvar status = Printer.connectBthPrinter(jprinter)5-7. connectNetworkPrinterConnect to the specified network printer port.function:Printer.connectNetworkPrinter (address,port)Argument:address IP address (string)port Port number (number)Return value:Returns the success or failure of the connection as a Boolean.true Successful connectionfalse Connection failed5-8. disconnectPrinterDisconnect the connected printer port.function:Printer.disconnectPrinter()Argument:NoneReturn value:None5-9. isPrinterConnectedCheck the printer port connection.function:Printer.isPrinterConnected()Argument:NoneReturn value:Returns the current connection state as a Booleantrue Connectedfalse Not connected5-10. printStringSpecifies the character string and prints out the printer font.function:Printer.printString(text)Argument:text Specify the character string to be printed in Unicode.Return value:None5-11. printString (Encoding specified)Prints a character string with encoding specified in the printer font.function:Printer.printString(text,charname)Argument:text Character stringcharname String encoding nameReturn value:NoneRemarks:Charname specifies the encoding name to use in Java.Example. Specify an encoding name such as "UTF-8", "SJIS", etc. as a string.5-12. setFontStyleSets character modifiers for the printer fonts.function:Printer.setFontStyle(bold,italic,underline)Argument:bold Specification (true) or cancellation (false) of bold typefaceitalic Specification (true) or cancellation (false) of italic typefaceunderline Specification (true) or cancellation (false) of underlining Return value:None5-13. setFontStyle (Underline thickness specified)Sets character modifiers for the printer fonts. (Underline thickness specified)function:Printer.setFontStyle(bold,italic,underline,dotpitch)Argument:bold Specification (true) or cancellation (false) of bold typefaceitalic Specification (true) or cancellation (false) of italic typefaceunderline Specification (true) or cancellation (false) of underliningdotpitch Underline thickness specifies 0 to 7 dots.Return value:None5-14. setFontTypeSets the printer font type.function:Printer.setFontType(compact)Argument:compact Specification (true) or cancellation (false) of small font (Font B).Return value:None5-15. setFontMagnificationSets the printer font size (vertical multiple and horizontal multiple).function:Printer.setFontMagnification (horizontalRation, verticalRatio)Argument:horizontalRatio Specification of the horizontal multiple between 1 to 8 verticalRatio Specification of the vertical multiple between 1 to 8.Return value:None5-16. setFontColorSpecifies or cancels white/black inversion for printer fonts.function:Printer.setFontColor(reverse)Argument:reverse Specification (true) or cancellation (false) of white/black inversion Return value:None5-17. setFontSmoothingSpecifies or cancels smoothing of printer fonts.function:Printer.setFontSmoothing(smoothing)Argument:smoothing Specification (true) or cancellation (false) of smoothingReturn value:None5-16. setAlignmentSpecifies the print position for print data (left alignment, centering, and right alignment).function:Printer.setAlignment(alignment)Argument:alignmentReturn value:None5-17. setCodePageSpecifies the code page for the printer font.function:Printer.setCodePage(codePage) Argument:codepageReturn value:None5-18. setInternationalCharSpecifies the international character for the printer font.function:Printer.setInternationalChar(internationalCharset)Argument:internationalCharsetReturn value:None5-19. printBarcodePrints the 1D barcode.function:Printer.printBarcode(barcodeSystem,barcodeData) Argument:barcodeSystembarcodeData Barcode data Return value:None5-20. printQRPrints the QR code.function:Printer.printQR(size,eccLevel,barcodeData)Argument:size Specify the symbol size (1 to 40).eccLevel Specify the error control level (1 to 4).1: L (7%)2: M (15%)3: Q (25%)4: H (30%)barcodeData Barcode dataReturn value:None5-21. printPDF417Prints the PDF417.function:Printer.printPDF417(truncate,binaryEncode,eccLevel,size,barcodeData)Argument:truncate Specify (true) of not specify (false) as (compact) PDF417binaryEncode Byte encoding mode (true) or automatic encoding mode (false)eccLevel The error correction level (0 to 7) is specified.size The barcode size is specified as shown in the combination table.barcodeData Barcode dataReturn value:None5-22. setBarcodeModificationSets the 1D barcode modification information (height, HRI characters).function:Printer.setBarcodeModification (hri,width,height)Argument:hri HRI character modification.Width The barcode module width (1 to 4) is specified.Height The barcode height (1 to 255 dot pitch) is specified.Return value:None5-23. printBitmapConverts the bitmap data specified by Base64 character string to bit image command and prints it.function:Printer.printBitmap(data)Argument:data Specify the bitmap data (Base64 string).Return value:None5-24. printBitmap (Print Position and dithering designation)Converts the bitmap data specified by Base64 character string to bit image command and prints it.function:Printer.printBitmap(data,align,dither)Argument:data Specify the bitmap data (Base64 string).align Specify the print position (Left, Center, Right).dither Specify dithering (true) or not (false)Return value:None5-25. linefeedSpecified number of carriage return (line feeds) is executed.function:Printer.lineFeed(lines)Argument:lines Number of carriage returns (line feeds) is specified (1 to 255).Return value:None5-26. paperFeedExecutes paper feeding the specified number of dot lines.function:Printer.paperFeed(lines)Argument:lines Paper feed is specified by a dot pitch value of -255 to 255.If the parameter is negative, the command executes printing and reversepaper feeding.If the parameter is an integer, printing and forward paper feeding areexecuted.Return value:NoneRemarks:In the standard mode, the data in the line buffer is printed, and the paper is fed forward by the specified dot pitch.In page mode, the data is shifted in the y-axis direction by the specified dot pitch.5-27. printStringAndroidFontConverts the specified character string into Android font and prints in bit image format.function:Printer.printStringAndroidFont(text, x, y, textSize)Argument:text Character string is specified.x Horizontal print positiony Vertical print positiontextSize Specify Character Size (Unit: SP).Return value:NoneRemarks:SP = Scale-independent pixel5-28. initPrinterModification information set in the printer is initialized.function:Printer.initPrinter()Argument:NoneReturn value:None5-29. startPageModeShift from standard mode to page mode.function:Printer.startPageMode()Argument:NoneReturn value:None5-30. endPageModeThe specified area of page memory is printed and the page mode is shifted to standard mode.function:Printer.endPageMode()Argument:NoneReturn value:None5-31. setPageAttributeSets the page mode attribution information (printing direction and printing area).function:Printer.setPageAttribute(x,y,width,height,direction)Argument:x Starting point of the print area (x axis)y Starting point of the print area (y axis)width Horizontal width of the starting point of the print area (x axis)height Height of the starting point of the print area (y axis)direction Direction of expansion within the print areaReturn value:NoneRemarks:The print area can be specified any number of times until the page mode is printed.When printing in page mode, the printer automatically prints within the maximumprint area at that time.The specified range of the print area depends on the printer model and memoryswitch settings.5-32. getStatusGets the printer status.function:Printer.getStatus()Argument:NoneReturn value:JSON format Status.Remarks:The acquired status is restored to its original format by "JSON.parse" and used.Refer to the command reference GS R1 command for the specification of thestatus value.Example://Get the statusvar result = Printer.getStatus();//Converting a Retrieved JSON Status to Original Formatvar status = JSON.parse(result);switch (status.status1) {case 82: //Ascii code ’R’buffer+= "Status1: WAITING<br>";break;case 66: // Ascii code ’B’buffer+= "Status1: MOVING<br>";break;case 69: // Ascii code ’E’buffer+= "Status1: ERROR<br>";break;default:buffer+= "Status1: " + status.status1 + "<br>";}5-33. outputRawDataByteSends binary data (1-Byte) to the printer port.function:Printer.outputRawDataByte(byte)Argument:byte 1-byte binary dataReturn value:None5-34. outputRawDataBase64Sends binary data (Base64 strings) to the printer port.function:Printer.outputRawDataBase64(base64)Argument:base64 Base64 strings binary dataReturn value:None5-35. inputRawDataGets binary data (1-Byte) from the printer port.function:Printer.inputRawData(timeoutMillis)Argument:timeoutMillis Specify the timeout period (in milliseconds) Return value:1-byte binary data5-36. inputRawDataGets binary data (Base64 strings) from the printer port.function:Printer.inputRawData(timeoutMillis,size)Argument:timeoutMillis Specify the timeout period (in milliseconds)Size Specify the size to receiveReturn value:Base64 strings binary data。
ESC打印机编程手册

1
PPTII-A 编程手册
更改记录
版本
1.0 1.1
日期
2013.09.27 2014.03.11 原始版本
更改内容
更改
ห้องสมุดไป่ตู้陈卫华 陈卫华
审核
林扬 林扬
承认
任小薇 任小薇
1.变更 ESC t n 指令(P21)
2
PPTII-A 编程手册
目 录
1.概述.................................................................................................................................................................. 7 1.1 关键字说明.............................................................................................................................................. 7 1.2 指令格式说明.......................................................................................................................................... 7 2.指令集.............................................................................................................................................................. 8 HT 横向跳格.................................................................................................................................................. 8 LF 打印并走纸一行....................................................................................................................................... 8 FF 打印并走纸............................................................................................................................................... 9 CR 打印并回车.............................................................................................................................................. 9 ESC SP n 设置字符右间距.......................................................................................................................... 9 ESC ! n 选择打印模式................................................................................................................................10 ESC $ nL nH 设置横向绝对打印位置..................................................................................................... 10 ESC % n 选择/取消自定义字符................................................................................................................. 11 ESC & y c1 c2 [x1 d1...d(y × x1)]...[xk d1...d(y × xk)]定义用户自定义字符.................................11 ESC *m nL nH d1... dk 选择位图模式................................................................................................... 12 ESC - n 选择/取消下划线模式................................................................................................................... 14 ESC 2 设置默认行高...................................................................................................................................15 ESC 3 n 设置行高.......................................................................................................................................15 ESC = n 选择打印机.................................................................................................................................. 15 ESC ? n 取消用户自定义字符.................................................................................................................... 16 ESC @初始化打印机................................................................................................................................. 16 ESC D n1...nk NUL 设置横向跳格位置.................................................................................................. 16 ESC E n 选择 /取消加粗模式...................................................................................................................... 17 ESC G n 选择 /取消双重打印模式............................................................................................................. 17
条码打印机编程手册(BPLA)V1.3

条码打印机编程手册(BPLA)山东新北洋信息技术股份有限公司目录声明 (6)概述 (7)实时指令<SOH> (9)SOH#软复位 (9)SOH A返回打印机状态(以字符串形式) (9)SOH B暂停 (10)SOH C停止/取消 (10)SOH D关闭实时指令 (10)SOH E返回批处理数量 (10)SOH F返回打印机状态(以字节形式) (10)SOH G返回打印机状态(以字符串形式) (11)SOH H返回打印机状态(以字节形式) (11)系统指令<STX> (13)STX%打印位置微调 (14)STX&进/退标签 (14)STX:字符平滑放大开关设定 (14)STX A液晶显示设定 (14)STX A 允许自动返回打印机状态 (15)STX B 下载点阵式位图字体 (15)STX C模块拷贝 (16)STX C 设置连续纸长度 (16)STX D内存映像功能 (16)STX D 进入双缓冲工作模式 (16)STX E设置存储标签的打印数量 (16)STX E 选择透射传感器 (17)STX F进标签 (17)STX F 设置打印停止位置 (17)STX G打印当前存储的的标签 (17)STX G 内部批处理模式 (17)STX H实时指令允许 (17)STX H 横向复制打印 (18)STX I输入图象数据 (18)STX I 下载矢量字体 (19)STX J 软DIP开关设置 (19)STX K系统扩展指令 (20)STX K 检测RS-232串口 (20)STX L进入标签格式指令 (21)STX L 设置镜像打印 (21)STX M设置寻找标签的最大长度 (21)STX M 设置打印机计量单位为米制 (21)STX N设置打印机计量单位为点制 (21)STX N 设置打印机计量单位为英制 (22)STX O设置打印开始位置 (22)STX O 切刀测试 (22)STX P 打印暂停 (22)STX Q清除所有模块的内容 (22)STX Q 清除指定模块的内容 (22)STX R 选择反射传感器 (22)STX S设置进纸速度 (23)STX S 进入单缓冲工作模式 (23)STX T打印打印头测试样张 (23)STX T 检测RAM模块 (23)STX U标签域替换 (23)STX U 设置旋转打印 (24)STX V保留 (24)STX V 返回当前版本信息 (24)STX W返回内存配置信息 (25)STX W 检测FLASH模块 (25)STX X设置缺省模块 (25)STX X 从模块中删除指定文件 (25)STX Y输出传感器的值 (26)STX Y 设置字体符号集 (26)STX Z打印内部信息和打印头测试样张 (26)STX Z 压缩模块 (26)*注释行 (26)系统扩展指令<STX>K (27)STX K打印偏移量调整 (27)STX KD软DIP开关配置 (27)STX K F 出纸偏移量调整 (28)STX K M 设置校准标签的最大长度 (29)STX KM内存配置 (29)STX KQ内存配置查询 (29)STX KR复位内存配置 (30)STX KS配置系统缓冲区大小 (30)STX KW配置打印缓冲宽度 (30)STX K W 打印缓冲区宽度设定 (30)标签格式指令 (32)+(>)连续域递增数字(字母) (33)-(<)连续域递减数字(字母) (33)^设置相同标签的打印数量 (33)&设置连续域的位置 (33):设置出纸单位(4位) (34)A设置域的位处理模式 (34)C设置列偏移数量 (35)C 设置出纸单位(2位) (35)D设置点的宽度和高度 (35)E结束标签格式模式并打印 (35)E 结束标签格式模式并打印(不进行出纸处理) (35)G存储数据到全局寄存器 (36)G 设置字符间距 (36)H设置打印浓度 (36)M镜像 (36)M 设置米制模式 (36)N设置点模式 (37)N 设置英制模式 (37)P设置打印速度 (37)P 设置回退速度 (37)Q设置总的标签打印数量 (37)R设置行偏移数量 (37)R 调用格式 (37)S设置前进速度 (38)S 存储标签格式 (38)T设置域结束符 (38)T 排版设置 (38)X结束标签 (38)Y S字体符号集的设置 (38)Z 斜杠零/普通零切换 (39)STX S调用全局寄存器 (39)*注释行 (39)制作标签 (40)生成记录 (41)记录结构 (41)记录结构类型 (43)条码类型及其属性 (48)附录一 ASCII表 (54)附录二打印机支持的字体 (55)附录三条码类型及其属性 (56)附录四十六进制(.HEX)文件格式 (57)附录五出错代码 (57)附录六 BPLA 支持存储模块 (58)附录七速度对照表 (58)附录八 BPLA 保留指令 (58)本手册内容未经同意不得随意更改,山东新北洋信息技术股份有限公司(以下简称新北洋)保留变更的权利。
斑马打印机编程 ZPL II语言编程基础

符号字体
^XA ^FO100,500 ^GSN,60,60^FDB^FS ^XZ
打印样张
打印条形码
^XA
开始标签格式
^LH0,0
原始位置
^FO203,203
条形码位置
^BY3,2.4,50
条形码系统设定[预置]
^B3N,Y,,Y
Code 39 条形码
^FDABC123^FS
条形码数据
^XZ
结束标签格式
使用ZTool工具转换图片文件为ZPL格式
原图片必须是单色图片 原图片格式必须是PCX,或是TIF
使用Zebra Designer制作图像
在Zebra Designer中选择正确的打印机 型号
制作带有需打印的图像标签 将该标签打印至文件 在标签文件中删除标签格式信息 指定图像文件下载的目标驱动器 保存文件后缀名为.GRF
»ZPL II支持小写、大写或大小写混合输入的 指令
»增加了一些新的命令
ห้องสมุดไป่ตู้
ZPL II 语言功能
打印各种标签格式
»文本 »图形 »条形码
设置打印机参数 获取打印机配置及状态信息
ZPL II 语言相关概念
域(field)
ZPL对象
»图片 »标签格式文件
打印机设备名称
打印机存储设备 » 指定 ZPL II 的目标对象 (图像,标签格式,字体) 到不 同的存储区域
图像打印指令
下载图形
~DGR:SMILE.GRF,12012,39
调用图形 ^XG
^XA ^FO50,50^XGR:SMILE.GRF,1,1^FS ^XZ
删除图形文件
^XA^IDB:SCREW.GRF^XZ
58MM热敏打印机编程手册

58MM热敏打印机 编程手册格式说明本编程手册的命令说明包括以下部分:1)命令名称及功能概述。
这是命令描述的第一部分。
给出了ASCII码形式的命令及该命令的功能概述。
2)格式。
这部分使用了ASCII码编码形式,十六进制码形式,十进制码形式3种形式描述该命令。
其中的取值范围部分无特殊说明则为十进制数,例如下例中1≤n≤4,其中1为十进制数的1,而不是ASCII码编码表中的“1”。
3)范围。
给出了变量的范围。
4)描述。
给出了命令的详细的解释。
5)注释。
给出了命令的注意事项。
由于命令在不同模式下,和不同命令配合时,将可能导致相互影响,而此部分给出了这些细节。
6)参考。
给出了与此命令相关、相似的其他命令。
1、HT水平定位[格式]ASCII码HT十六进制码09十进制码9[描述]移动打印位置到下一个水平定位点的位置。
[注释]•如果没有设置下一个水平定位点的位置,则该命令被忽略。
•如果下一个水平定位点的位置在打印区域外,则打印位置移动到为[打印区域宽度+1]。
•通过ESC D命令设置水平定位点的位置。
•打印位置位于[打印区域宽度+1]处时接收到该命令,打印机执行打印缓冲区满打印当前行,并且在下一行的开始处理水平定位。
•默认值水平定位位置是每8个标准ASCII码字符(12×24)字符跳一格(即第9,17,25,…列)。
•当前行缓冲区满时,打印机执行下列动作:标准模式下,打印机打印当前行内容并将打印位置置于下一行的起始位置。
页模式下,打印机进行换行并将打印位置置于下一行的起始位置。
[参考]ESC D2、LF打印并换行[格式]ASCII码LF十六进制码0A十进制码10[描述]将打印缓冲区中的数据打印出来,并且按照当前行间距,把打印纸向前推进一行。
[注释]该命令把打印位置设置为行的开始位置。
[参考]ESC2,ESC33、ESC SP n设置字符右间距[格式]ASCII码ESC SP n十六进制码1B20n十进制码2732n[范围]0≤n≤255[描述]设置字符的右间距为[n×横向移动单位或纵向移动单位]英寸。
打印机计数芯片编程实例

打印机计数芯片编程实例随着科技的进步,打印机已经成为我们日常生活和工作中不可或缺的设备之一。
而在打印机的工作过程中,计数芯片起着至关重要的作用。
本文将以打印机计数芯片编程实例为主题,介绍打印机计数芯片的功能和实现方法。
一、打印机计数芯片的功能打印机计数芯片主要用于记录打印机的使用情况,包括打印页数、墨盒使用量等。
通过计数芯片,用户可以清楚地了解到打印机的工作情况,及时更换耗材,提高打印效率。
二、打印机计数芯片的编程实例在打印机计数芯片的编程实例中,我们将以C语言作为编程语言,通过编写相应的代码来实现打印机计数功能。
下面是一个简单的示例:```c#include<stdio.h>int main(){int printCount = 0; // 打印计数// 模拟打印printf("开始打印...\n");for(int i=0; i<10; i++){printf("正在打印第%d页...\n", i+1);printCount++;}printf("打印结束!\n");// 打印计数输出printf("打印计数:%d\n", printCount);return 0;}```上述示例中,我们通过一个简单的循环来模拟打印过程,每打印一页,计数器就自增1。
最后,我们将打印计数输出,以便用户了解打印机的使用情况。
三、打印机计数芯片编程实例的应用打印机计数芯片的编程实例可以应用于各种打印机设备中,不仅可以实现打印计数的功能,还可以根据实际需求进行扩展,如记录不同类型文档的打印次数、墨盒剩余量等。
打印机计数芯片还可以与其他系统进行连接,实现更多的功能。
例如,可以将打印计数数据发送给服务器,用于统计打印机的使用情况和维护管理;也可以与用户的电脑或手机相连,实现远程监控和管理打印机等。
四、结语通过打印机计数芯片的编程实例,我们可以清楚地了解到打印机计数的原理和实现方法。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
打印机编程1、检测当前打印机状态用内嵌汇编调用中断INT 17H,读取打印机的状态字节加以分析,即可得到其当前状态.例:输入参数:如果有3个打印端口LPT1、LPT2、LPT3,那么输入参数LPTPort就是1、2、3。
function TestPrinterStatus(LPTPort : word):byte;var status : byte;CheckLPT : word;beginstatus := 0;if (LPTPort >=1) and (LPTPort <=3) thenbeginCheckLPT := LPTPort -1;asmmov dx,CheckLPT;mov al,0;mov ah,2;int 17H;mov &status,ah;end;end;result := status;end;返回值有以下几种:01H:超时08H:I/O错误10H:打印机未联机20H:打印机缺纸80H:打印机空闲。
2、如何获取当前打印机的名称、驱动程序、打印端口信息:以下是来自Borland公司的完整例子。
请注意其中两条判断语句,这说明有时候仅仅凭getprinters并不能保证信息的正确,还需要WIN.INI的帮助。
uses printers;{$IFNDEF WIN32}const MAX_PATH = 144;{ENDIF}procedure TForm1.Button1Click(Sender : TObject);varpDevice : pChar;pDriver : pChar;pPort : pChar;hDMode : THandle;beginif PrintDialog1.Execute then beginGetMem(pDevice,cchDeviceName);GetMem(pDriver,MAX_PATH);GetMem(pPort,MAX_PATH);Printer.GetPrinter(pDevice,pDriver,pPort,hDMode);if lStrLen(pDriver) = 0 then beginGetProfileString('Devices',pDevice,'',pDriver,MAX_PATH);pDriver[pos(',',pDriver) - 1] := #0;end;if lStrLen(pPort) = 0 then beginGetProfileString('Devices',pDevice,'',pPort,MAX_PATH);lStrCpy(pPort,@pPort[lStrLen(pPort) + 2]);end;FreeMem(pDevice,cchDeviceName);FreeMem(pDriver,MAX_PATH);FreeMem(pPort,MAX_PATH);end;end;3、获取打印机队列的状态信息:在有些情况下,需要获取打印机队列的状态信息,可以通过WindowsAPI函数ENumJobs来获取打印机队列的状态信息。
下面的程序片断对获取打印机队列的状态信息进行了说明。
(1)创建一个新工程;(2)在窗体Form1中添加一个Button组件和一个Memo组件,进行相关属性的设置;(3)添加Button1的OnClick事件。
procedure TForm1.Button1Click(Sender :TObject);varLPHandle : THandle;//打印机句柄LPStrBuf : Array [0..256] of Char;//打印机名称NoJobs : Word; //希望获取的作业数s : LongWord; //Job_Info的字节数Job_Info : Array [0..10] of JOB_INFO_1; //打印队列信息cbNeeded : Cardinal;cReturned : Cardinal; //返回的作业数ret : LongBool;I : integer;beginLPStrBuf := 'HPLaserJet';//指定打印机名//打开打印机if OpenPrinter() thenbeginMessageBox(Form1.Handle,'打开打印机失败。
','信息',MB_OK);Exit;end;s := SizeOf(Job_Info);cbNeeded := 0;cReturned := 0;NoJobs := 10;ret := ENumJobs(LPHandle,0,NoJobs,1,@Job_Info,s,cbNeeded,cReturn);//显示打印队列信息Memo1.Lines.Add('共有打印任务:' + InttoStr(cReturned) + '个。
');for I := 0 to cReturned -1 doMemo1.Lines.Add('第' + IntToStr(I+1) + '个打印任务有' + IntToStr(Job_Info[I].TotalPages) + '页。
'); end;在进行测试的时候,应根据系统中安装的打印机设置LPStrBuf的数值,可以通过Windows 系统的“控制面板”打开打印机管理器验证运行结果。
4、获取默认打印机的信息:在Windows的Win.ini文件中有下面的一些配置信息:[Windows]load =run =NullPort = Nonedevice = HPLaserJetIII,HPPCL5MS,LPT1.............其中Windows节的device键中指明了当前系统中默认打印机的信息。
可以通过WindowsAPI 函数GetProfileString获取该信息。
函数GetProfileString的原形如下:DWORDGetProfileString(LPCTSTRlpAppName, //指定节名的字符串LPCTSTRlpKeyName, //指定键名的字符串LPCTSTRlpDefault, //没有找到键名时返回的字符串LPTSTRlpReturnedString, //在键名找到时返回的字符串DWORDnSize //lpReturnedString的字节数);例子如下:(1)创建一个新的工程;(2)在窗体Form1上添加一个Button组件和一个Edit组件,进行相关属性设置;(3)添加Button1的OnClick事件。
procedure TForm1.Button1Click(Sender : TObject);varAppName : Array [0..256] of Char; //节名称字符串KeyName : Array [0..256] of Char; //键名称字符串DefaultString : Array [0..256] of Char; //在键名没找到时默认返回的字串ReturnedString : Array [0..256] of Char; //在键名找到时返回的字串beginAppName := 'Windows';//节名称KeyName := 'device'; //键名称GetProfileString(AppName,KeyName,DefaultString,ReturnedString,Sizeof(ReturnedString));Edit1.Text := ReturnedString;//显示结果end;以上测试可打开win.ini进行对照。
2004-3-3 12:24:52 打印机的设置5、Windows系统默认的打印机信息存放于Win.INI文件中,只有修改了相应的文件内容,再通知Windows系统进行刷新,才算改变了默认的打印机。
下面是程序片断:varstrINI : Array [0..MAX_PATH] of Char;arrWindows : Array [0..46] of Char;beginGetWindowsDirectory(strINI,SizeOf(strINI));StrCat(strINI,'Win.INI');with TINIFile.Create(strINI) dotry //更改WIN.INI文件中的默认打印机设置WriteString('Windows','device','HPLaserJet 4 Plus,HPPCL5MS,LPT1');finallyFree;end;StrCopy(arrWindows,'Windows');SendMessage(HWND_BROADCAST,WM_WININICHANGE,0,LongInt(@arrWindows)); //发消息end;6、调用系统的“页面设置”对话框:首先要在Uses子句中加入CommDlg单元,参见下例:procedure TForm1.Button1Click(Sender : TObject);var s : tagPSD;beginFillChar(s,Sizeof(s),0);s.lStructSize := Sizeof(s);if PageSetupDlg(s) thenShowmessage('OK')elseShowmessage('Error');end;7、调用系统的“添加打印机”对话框:ShellExecute(0,'Open','rundll','shell32.dll,SHHelpShortcuts_RunDLL AddPrinter', '' , SW_SHOWNORMAL);打印测试页:WinExec('rundll32 msprint2.dll,RUNDLL_PrintTestPage',1);8、用代码添加打印机:需要调用API函数的AddPrinter,它有三个参数:打印机名、打印质量、打印机说明。
以下代码把函数封装起来。
只需要提供出现在Windows中的打印机名,打印机的接口名(例如:LPT1:),驱动器名和打印程序名(通常是winprint)。