ESC/POS 如何发送彩色图片?

How to send color images with ESC/POS?

我有一台 Epson CW-C6000,我想用 ESC 命令控制它。我有要打印的文本,所以我知道我的 IP 地址、端口等都是正确的,但我终究无法打印图像。

这是我的代码(运行 来自 Rails 服务器上的 Ruby,大部分图像被截断):

streamSock = TCPSocket.new( "X.X.X.X", 9100 )
str = "~DYR:PRODIMG,B,P,183208,0,89504E470D...4AE426082" + "^XA" + "^FO150,150^IMR:PRODIMG.PNG^FS" + "^XZ"
streamSock.send( str , 0)
streamSock.close

图像是我用这个网站转换成十六进制的.png: http://tomeko.net/online_tools/file_to_hex.php?lang=en

我主要使用此 PDF 的第 10 页作为参考: https://files.support.epson.com/pdf/pos/bulk/esclabel_apg_en_forcw-c6000series_reve.pdf

有人有提示吗?爱普生支持人员非常无助。

另外,如果我的格式有误,我深表歉意;我是新来的,如果有什么问题,我会很乐意编辑我的 post。

也许这个material可以作为额外的参考。
它们的 command/data 格式似乎与 ESC/POS.

完全不同

ESC/Label Command Reference Guide
第 12 页

1.3.4 About Saving the Graphics and Label Formats in the Printer

With ESC/Label command, you can save graphics and label formats in the printer. The printer has a file system. Data saved in the printer is handled as files and is managed in the following way.

  • The file system does not have a hierarchy.
  • The printer has a non-volatile saving device, such as Flash ROM, and a volatile saving device, such as RAM, and different drive letters are allocated for each device.
  • Files are designated as
    "<drive letter> colon <:> <file name> dot <.> <extension>".

第 40-41 页

2.8 Printing Graphics
...Details have been omitted. Please refer to the actual document...

2.8.1 Registering a Graphic in a Printer and Printing It
...Pick up some from the content. Please refer to the actual document...

  1. Delete the files that remain in the printer (^ID command).
  2. Register the graphic in the printer (~DY command).

When registering a color graphic, you can use the PNG format. When registering a monochrome graphic, you can register the PNG format or the GRF format.

  • PNG format Monochrome and color graphics
  • GRF format Monochrome graphics

The reason to execute the step 1.
To ensure capacity of the storage memory necessary for print which application will perform.

2.8.2 Embedding a Graphic in the Field and Printing It
...Details have been omitted. Please refer to the actual document...


另外:

第 104-106 页

~DY
[Name]
Save File
[Format]
~DY d: o ,f ,x ,t ,w ,data
...A table detailing the parameters is due, but omitted...

[Function]
...Further detailed explanations and figures of functions and parameters are due, but omitted...

  • Graphic data is handled as follows.
    • If the data format is binary, you can use any binary data as Parameter data. At this time, the size of Parameter data must be matched to the size specified in Parameter t.
    • If the data format is a hexadecimal character string, one character from 1. to 3. below is used as Parameter data. At this time, the size of Parameter data written in binary must be matched to the size specified in Parameter t.
      1. 0 to 9, A to F, and a to f in ASCII can be used as hexadecimal graphic data.
      2. ASCII comma <,>, the parameter separator character, is used to separate lines. If a comma is input, processing is carried out as if ASCII 0 was input for the remainder of the line.
      3. G to Y and g to z in ASCII can be used as repetition characters. For example, if I9 is input, processing is carried out as if 999 were input. The following table indicates the number of repetitions.
        ...Characters and repeat specified number of times table omitted...

看这个技术参考指南的内容,好像可以用工具而不是命令来注册图片。
CW-C6000/C6500 Series Technical Reference Guide
第 173-174 页

第 288 页概述了爱普生喷墨标签打印机 SDK,还描述了示例程序的存在。

好吧,我终于让它工作了。打印彩色 .PNG 的命令是这样的:

~DYE:[Image Name].PNG,p,p,[Image Size],0,:B64:[Base64 String]:[CRC]

让我绊倒的事情:

-您似乎需要文件名的 .PNG 扩展名,即使 Epson 手册没有显示。

-[Image Size] 是 Base64 字符串中的字符数,尽管 Epson 手册说它应该是原始 .PNG 图像文件的大小。如果这是错误的,打印机将挂起并且在重新启动之前不再接受任何类型的输入。

-可能还有其他选择,但我只能使用十六进制 CRC-16/XMODEM 类型的 CRC。

感谢K Jhis/her的建议和陪伴!

@Farmbot26。我一直在尝试使用 vb.Net 进行同样的操作,正如您所指出的,Epson 支持没有帮助。我不确定是错误的实际图像数据、CRC 还是 ZPL 代码,因为没有任何帮助。这里有 2 个没有用的例子。

`Dim binaryData As Byte() = System.IO.File.ReadAllBytes(txtPNGFile.Text)
        zplImageData = Convert.ToBase64String(binaryData)
        crc = calcrc(binaryData, binaryData.Length).ToString("X4")
        Dim zplToSend As String = "~DYE:" & Path.GetFileName(txtPNGFile.Text).ToUpper & ",P,P," & zplImageData.Length & ",0,:B64:" & zplImageData & ":" & crc & "^XZ"`


`Dim binaryData As Byte() = System.IO.File.ReadAllBytes(txtPNGFile.Text)
        crc = calcrc(binaryData, binaryData.Length).ToString("X4") 'Calculate CRC
        zplImageData = BitConverter.ToString(binaryData).Replace("-", "")
        Dim zplToSend As String = "~DYE:" & Path.GetFileName(txtPNGFile.Text).ToUpper & ",A,P," & zplImageData.Length & ",0,:B64:" & zplImageData & ":" & crc & "^XZ"`

这是我的 CRC 示例。

`Function calcrc(ByVal data() As Byte, ByVal count As Integer) As Integer
    Dim crc As Integer = 0
    For Each b As Byte In data
        Dim d As Integer = CInt(b)
        crc = crc Xor (d << 8)
        For j = 0 To 7
            If ((crc And &H8000) <> 0) Then
                crc = (crc << 1) Xor &H1021
            Else
                crc = (crc << 1)
            End If
        Next
    Next
    Return crc And &HFFFF
End Function`

我想出了另一个解决方案。使用二进制数据保存 PNG 图像。我在使用爱普生设置实用程序读取图像数据的保存备份文件时发现了这一点。

~染料:FILENAME.PNG,B,P,BINARYFILESIZE,0, BINARYIMGDATA

` Try
            Dim binaryData As Byte() = System.IO.File.ReadAllBytes(txtPNGFile.Text)
            Dim client As System.Net.Sockets.TcpClient = New System.Net.Sockets.TcpClient()
            client.Connect(IP_TextBox1.Text.Replace(" ", ""), txtPort.Text)
            Dim writer As System.IO.StreamWriter = New System.IO.StreamWriter(client.GetStream(), Encoding.UTF8)
            Using mStream As New MemoryStream(binaryData)
                Dim zplToSend As String = "~DYE:" & Path.GetFileName(txtPNGFile.Text).ToUpper & ",B,P," & mStream.Length & ",0,"
                writer.Write(zplToSend)
                writer.Flush()
                mStream.WriteTo(client.GetStream())
                writer.Flush()
            End Using
            writer.Close()
            client.Close()
            MsgBox("Send Complete", MsgBoxStyle.OkOnly, "Complete")
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.OkOnly, "ERROR")

        End Try`

您还可以在 IMAGE 对象中打开图像文件并根据需要调整其大小。我必须为打印机的标签尺寸执行此操作。