通过ESC / P命令将位图写入Epson TM88IV(写入NVRam)

Ans*_*son 2 .net c# printing command epson

参考链接:

  1. https://lh4.googleusercontent.com/-ceLtiOLVtME/UMBL1yf4RpI/AAAAAAAAAD0/itid5KibW_I/s1015/Doc1.png

  2. https://lh6.googleusercontent.com/-nrphBDA6sjk/UMA_Ukh7ZSI/AAAAAAAAADY/LwjkgobOaBg/s846/MappingTable.png

更新

我现在已经通过使用LockBits更改了图像转换,但是失败了。有人可以给我一些建议吗?

    /// <summary>
    /// Orginal command Format in Decimal:
    /// 29[GS], 40[(], 76[L], pL, PH, 48(m), 67[fn], 48[a], kc1, kc2, b, xL, xH, yL, yH, c, [d1 -- dk]
    /// pL = Lower bit of sum of parameters (m to dk) = 11(m to c) + last bit of image
    /// pH = Higher bit of sum of parameters (m to dk) = 11(m to c) + last bit of image
    /// kc = Key Code of NVRam, kc1 = first bit of key code, kc2 = second bit of key code. P.S.: The key code will be hardcode H1.
    /// b = number of colors = 1
    /// xL & xH = Lower bit of image width, e.g. Width = 128 = 0x0080 then xL = 0x80, xH = 0x00
    /// </summary>
    /// <param name="pLogo"></param>
    public void LoadImageToPrinter(Bitmap pLogo)
    {
        BitmapData oBmpData = pLogo.LockBits(new Rectangle(0, 0, pLogo.Width, pLogo.Height), ImageLockMode.ReadOnly, pLogo.PixelFormat);

        //The list contains all the commands in Decimal format
        List<int> oCommandList = new List<int>();

        //k = (int((xL + xH × 256) + 7)/8) × (yL + yH × 256)

        string HexValueOfX = pLogo.Width.ToString("X4");
        string HexValueOfY = pLogo.Height.ToString("X4");

        //k
        int oExpectedImageByteCount = Math.Abs(oBmpData.Stride) * pLogo.Height;

        //Total bit used for parameters
        int oTotalParameterBitCount = 11 + oExpectedImageByteCount;

        //The hex value for the oTotalParameterBitCount
        string oTotalParameterBitCountInHex = oTotalParameterBitCount.ToString("X4").PadLeft(4, '0');

        //GS, (, L
        oCommandList.AddRange(new int[] { 29, 40, 76 });

        //pL
        oCommandList.Add(GetLowerHexValue(oTotalParameterBitCountInHex));

        //pH
        oCommandList.Add(GetHigherHexValue(oTotalParameterBitCountInHex));

        //m,  fn, a,  kc1, kc2, b
        oCommandList.AddRange(new int[] { 48, 67, 48, (int)'H', (int)'1', 1 });

        //xL, xH
        oCommandList.AddRange(new int[] { GetLowerHexValue(HexValueOfX), GetHigherHexValue(HexValueOfX) });

        //yL, yH, c
        oCommandList.AddRange(new int[] { GetLowerHexValue(HexValueOfY), GetHigherHexValue(HexValueOfY), 49 });

        //Append the image bit to the List
        byte[] oImageByte = new byte[oExpectedImageByteCount];
        IntPtr oPtr = oBmpData.Scan0;
        Marshal.Copy(oPtr, oImageByte, 0, oExpectedImageByteCount);
        pLogo.UnlockBits(oBmpData);

        //Clear NVRam
        mThermalPrinterLibrary.Write(new int[] { 29, 40, 76, 5, 0, 48, 65, 67, 76, 82 }.IntArrayToCharString());

        //Store graphics data
        mThermalPrinterLibrary.Write(oCommandList.ToArray().IntArrayToCharString());
        mThermalPrinterLibrary.Write(oImageByte);

        //Print the graphics data
        mThermalPrinterLibrary.Write(new int[] { 29, 40, 76, 6, 0, 48, 69, (int)'H', (int)'1', 1, 1 }.IntArrayToCharString());        
}
Run Code Online (Sandbox Code Playgroud)

Joe*_*Joe 5

我是在多年前用C语言完成的。我没有手头的代码,但这不只是一个片段。为此,您需要执行以下操作。

  • 了解BMP文件格式 -假设您正在从文件中读取位图。

  • 查看WINGDI.H(Microsoft Windows SDK),它具有文件头等的C样式定义:BITMAPFILEHEADER,BITMAPCOREHEADER,BITMAPINFOHEADER。

  • 处理标题以确定位图是否满足您的要求(例如,为了简化处理,您可能需要坚持认为位图正好是128 x 98(BITMAPINFOHEADER.biWidth,BITMAPINFOHEADER.biHeight),具有一个平面(BITMAPINFOHEADER.biPlanes) = 1),是单色(BITMAPINFOHEADER.biBitCount = 1),未压缩(BITMAPINFOHEADER.biCompression = 0),这些限制不是绝对必要的,但可以简化您的处理。

  • 处理像素阵列,并将其转换为ESCPOS转义序列所需的格式。

或者,您可能要放弃使用ESCPOS,而使用OPOS / UPOS / POS for .NET,它提供了用于访问POS外围设备的更高级别的API:POSPrinter设备公开了一种打印位图的方法,并且无需进行任何操作。自己进行格式转换。为此,您需要下载Epson OPOS ADK。祝好运!

更新

而且,EPSON的文档就像地狱一样,无法理解它的需求。

对Epson的文档有何困难?也许您可以尝试询问有关您不了解的位的特定问题。

更新2

这里有一些指针:

  • GS(L pL pH m fn [params]:pL和pH是16位整数值的低位和高位字节,该整数值指定以下数据的字节长度(即m fn [params])。

  • 对于fn = 67(定义NV数据栅格格式),格式为GS(L pL pH m fn a kc1 kc2 b xL xH yL yH [c d1 ... dk] 1 ... [c d1 ... dk] b其中m = 48,fn = 67,a = 48

  • kc1和kc2是用于在打印时识别已下载数据的关键代码

  • b指定下载数据的颜色数量,1代表单色,2代表两种颜色。

  • xL和xH是16位整数值的低位和高位字节,以图像的点(像素)为单位定义宽度。

  • yL和yH是16位整数值的低位和高位字节,以图像的点(像素)为单位定义高度。

  • 对于单色位图,将有一个块c d1 ... dk指定颜色c和像素数据。对于彩色位图,每种颜色有一个块c d1 ... dk

  • 像素数据d1 ... dk具有k个字节,其中k =(宽度x(高度+7))/ 8。设置为1表示打印该点(像素)。

我不知道上述内容是否比Epson文档中的注释更清楚;如果不说,您不了解哪些位。

更新3

这是一个基于您问题中所示的128宽x 98高度位图的示例,为简单起见,此图为单色。

  • 您将需要k =(int(width + 7)/ 8)×(height)=(int(128 + 7)/ 8)x 98 = 16 x 98 = 1568字节像素数据(位= 1表示点打印):d 1至d 1568

  • 假设颜色c =颜色1 = 49小数= 0x31十六进制(也可以是0x32或0x33)

  • 宽度= 128 = 0x0080,因此xH = 0x00,xL = 0x80

  • 高度= 98 = 0x0062,所以yH = 0x00,yL = 0x62

  • b =颜色数量= 1

  • 假设您的密钥是“ H1”,即kc1 ='H'= 0x48和kc2 ='1'= 0x31

  • PARAM长度=长度米FN一个KC1 KC2 b xL的XH基yH的CD 1 ... d 1568 = 11 + 1568 = 1579 = 0x062B进制,所以PL = 0x2B访问,pH值= 0×06。

因此,您发送的数据将是:

GS(L pL pH m fn a kc1 kc2 b xL xH yL yH cd 1 ... d 1568

在十六进制中:

1D 28 4C 2B 06 30 43 30 48 31 01 80 00 62 00 31 d 1 ... d 1568