使用“光栅模式”直接打印到打印机的以太网:需要基本的指导 [英] Printing directly to Ethernet printer using 'raster mode': need basic guidance

查看:281
本文介绍了使用“光栅模式”直接打印到打印机的以太网:需要基本的指导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对面的一个问题迷迷糊糊的办法的超出了我的专业领域,我没有一个导师可以寻求这方面的帮助。

I've stumbled across a problem way beyond my area of expertise, and I don't have a mentor to turn to for help with this.

我有一个收据打印机,我需要通过一个iOS应用与接口。该打印机所在的同一个网络设备(S),所以我可以通过支持行模式命令解决这个问题。

I have a receipt printer I need to interface with through an iOS app. The printer is located on the same network as the device(s), so I can address it through supported "Line Mode commands"

我想要做的就是保持code我已经是跨平台工作 - 也就是说,它的一个UIView /的NSView,如果你不熟悉的OS X / iOS的,它只是一个标准香草认为我可以渲染成PDF / PNG格式。值得庆幸的是,打印机有这似乎是什么,我需要一个光栅图形模式。

What I'd like to do is keep the code I have already that works cross-platform – i.e. it's a UIView/NSView, and if you're not familiar with OS X/iOS, it's just a standard vanilla view that I can render into PDF/PNG formats. Thankfully, the printer has a "raster graphics" mode that seems to be what I need.

不幸的是,无论是命令规范的蹩脚的英语,还是我完全没有超越了基本的C,还是我对图形的完整知识的缺乏什么知识,我不知道如何甚至可以从命令规格开始我有。我知道,打印机和网络我的的,因为我可以解决这个问题通过网络,并将其发送基础饲料的命令。但是,我不知道如何从一个PNG去 - >无论打印机需要使它的光栅模式的工作

Unfortunately, be it the broken English of the command spec, or my complete lack of knowledge of anything beyond basic C, or my complete lack of knowledge regarding graphics, I have no idea how to even get started from the command specifications I have. I know the printer and my networking works because I can address it over the network and send it basic feed commands. But, I have no idea how to go from a PNG -> whatever the printer needs to make it's 'raster mode' work.

该规范可以在<一个href=\"http://www.star-m.jp/eng/service/usermanual/linemode_cm_en.pdf\">http://www.star-m.jp/eng/service/usermanual/linemode_cm_en.pdf ,你会想,如果你想帮助开始阅读的页面是3-68,而烦恼甚至开始使用我有具体的命令是在3-78 / 3-79。

The specification is available at http://www.star-m.jp/eng/service/usermanual/linemode_cm_en.pdf , and the page you'd want to start reading it if you want to help is 3-68, and the specific commands I'm having trouble even getting started with are on 3-78/3-79.

我可以给你不过是一个对号,但我向你保证,你有我永远感谢你甚至可以给我提供了正确的方向,甚至一个点。

I can give you nothing but a checkmark but I assure you, you'll have my undying gratitude if you can even provide me even a point in the right direction.

推荐答案

已经写了几个打印机驱动程序我可以证实,一般的文档是因为打印机的方式工作混乱。您参考该文件实际上并不似乎对我不好。

Having written a few printer drivers I can confirm that generally the documentation is confusing because of the way printers work. The document that you refer to doesn't actually seem to bad to me.

我认为你是对的光栅模式下打印,并且整体这是要提供最好的结果。

I think you're right to be printing in raster mode and that overall this is going to give the best results.

从明星文档,我想你会需要发送:

From the Star documentation I reckon you'll need to send :

1. \x1b*rR  Initialize raster mode
2. \x1b*rA  Enter raster mode
3. \x1b*rC  Clear raster data
4. \x1b*rml
4. b\x##\x##\xAA\xAA\xAA....<DATA>..........
5. \x1b\x0C\x00 Raster Form feed(??) - should spit out the data.
6. \x1b*rB  Clear raster data

OBV 的。在上面的\\ X1B是ESC的C-编码(即字符27 0x1b)。

Obv. in the above \x1b is the C encoding of ESC (i.e. character 27 0x1b).

这一切,我一直在阅读下面的文件是如何图像应该光栅模式进行格式化。当行模式是作为垂直和放大器完全不同;水平进行了交换。从热敏打印机程序员手册(TSP552,TSP552II,TSP2000)

From all of the documentation that I've been reading the following is how the images should be formatted in raster mode. When in line mode it is completely different as the vertical & horizontal are swapped. From THERMAL PRINTER PROGRAMMER'S MANUAL (TSP552,TSP552II,TSP2000)

这相当于下面的字节流。

This equates to the following bytes stream.

在四号命令行是有效的'B'后跟两个字节definining大小。这个大小被计算为包含在该流%256和/ 256。因此,对于该倒是320x1像素的数目0x40,0x01

On the 4th command line it is effectively 'b' followed by two bytes definining the size. This size is computed as the number of pixels contained in the stream % 256 and / 256. So for 320x1 that'd 0x40,0x01

因此​​,采取上述并将其插入到一个简单的测试程序,你应该使用这个测试:

So, taking the above and plugging it into a simple test program you should test with this:

char rasterImage [] = {
0x1b, '*', 'r', 'R',       //  Initialize raster mode
0x1b, '*', 'r', 'A',       // Enter raster mode
0x1b, '*', 'r', 'C',       // Clear raster data
//          n1  n2 d1    d2..
0x1b, 'b', 0x2, 0, 0x00, 0x00, // data
0x1b, 'b', 0x2, 0, 0x1F, 0xF8,
0x1b, 'b', 0x2, 0, 0x3F, 0xFC,
0x1b, 'b', 0x2, 0, 0x77, 0xEE,
0x1b, 'b', 0x2, 0, 0xF8, 0x1F,
0x1b, 'b', 0x2, 0, 0xF8, 0x1F,
0x1b, 'b', 0x2, 0, 0xF8, 0x1F,
0x1b, 'b', 0x2, 0, 0x0F, 0xF0,
0x1b, 'b', 0x2, 0, 0x1F, 0xF8,
0x1b, 'b', 0x2, 0, 0x1F, 0xF8,
0x1b, 'b', 0x2, 0, 0x3E, 0x7C,
0x1b, 'b', 0x2, 0, 0x38, 0x1C,
0x1b, 'b', 0x2, 0, 0x79, 0x9E,
0x1b, 'b', 0x2, 0, 0x73, 0xCE,
0x1b, 'b', 0x2, 0, 0x73, 0xCE,
0x1b, 'b', 0x2, 0, 0xF9, 0x9F,
0x1b, 'b', 0x2, 0, 0xF8, 0x1F,
0x1b, 'b', 0x2, 0, 0xFE, 0x7F,
0x1b, 'b', 0x2, 0, 0xFF, 0xFF,
0x1b, 'b', 0x2, 0, 0xFF, 0xFF,
0x1b, 'b', 0x2, 0, 0x00, 0x00,
0x1b, 'b', 0x2, 0, 0x00, 0x00,
0x1b, 'b', 0x2, 0, 0x00, 0x00,
0x1b, 'b', 0x2, 0, 0x00, 0x00};

[self.currentDataBeingSent appendBytes:rasterImage length:sizeof(rasterImage)];

简单地喷出了到打印机,你应该得到的图片如上。在这里,您可以轻松地调整并播放有关与确切的命令得到的东西的工作。通常这是我曾经设法弄清楚什么应该做的唯一途径。

Simply squirt that out to the printer and you should get a picture as above. This is where you can easily tweak and play about with the exact commands to get something that's working. Often this is the only way I've ever managed to figure out what should be done.

参考。注释。

如果你有每像素一个字节,那么你需要将这些合并成一系列的比特;以下应根据您的引擎收录code做的工作。我也改变了的char * ,因为它是签署时位操纵可能会导致问题是无符号的。

If you have a byte per pixel then you will need to merge these into a series of bits; the following should do the job based on your pastebin code. I've also changed the char* to be unsigned as it is signed can cause problems when bit manipulating.

NSUInteger bitmapBytePerRow = width/8;
NSUInteger bytesPerRow = 3 + bitmapBytePerRow;

[self.currentDataBeingSent = [NSMutableData dataWithLength:bytesPerRow * height];
[self.currentDataBeingSent appendBytes:initializeRaster length:sizeof(initializeRaster)];
[self.currentDataBeingSent appendBytes:enterRaster length:sizeof(enterRaster)];

NSUInteger byteOffset = 0;
for (NSUInteger y = 0; y < height; y++)
{
    unsigned char *rasterCommandForRow = (unsigned char *)calloc(bytesPerRow, sizeof(char));
    unsigned char *current_raster = rasterCommandForRow; 
    *current_raster++ = '\x6B';     
    *current_raster++ = (width*height) % 256;
    *current_raster++ = (width*height) / 256;

    unsigned char mask = '\x80' ;
    unsigned char out = 0 ;
    for (NSUInteger x = 0; x < width; x++)
    {
        if (*(data + (byteOffset * sizeof(char))))
            out |= mask ;
        byteOffset++;
        mask >>= 1 ;
        if( 0 == mask )
        {
            mask = '\x80' ;
            *current_raster++ = out ;
            if( out )
        lastDot = nextOut ;
            out = 0 ;
        }

    }

    // handle partially finished byte .
    if( ( '\x80' != mask ) && ( 0 != out ) )
        *current_raster++ = out ;

    [self.currentDataBeingSent appendBytes:rasterCommandForRow length:bytesPerRow];
}

rev.3a

纵观的Mac CUPS支持从星是拿到源$ C ​​$ c,对于它包含了很多线索如何应该是这样的驱动程序。有时候,code是那么容易得多文档阅读。

rev.3a

Looking at the Mac CUPS support from Star it's got the source code for the driver which contains a lot of clues about how this should be done. Sometimes code is so much easier to read than documentation.

starcupsdrv-3.1.1_mac_20100423.zip \\ starcupsdrv-3.1.1_mac \\来源$ C ​​$ C \\

包含 starcupsdrv-SRC-3.1.1.tar.gz \\ 子文件夹 starcupsdrv的\\ src \\

查看rastertostar.c,重要的位是N1 / N2的值的计算。这些都不是在所有的X和放大器; ý但基于所述像素数,lastBlackPixel是像素从源计数

View rastertostar.c, the important bit is the calculation of the n1 / n2 values. These aren't at all X & Y but based on the pixel count, lastBlackPixel is the count of pixels from the source.

putchar('b');
putchar((char) ((lastBlackPixel > 0)?(lastBlackPixel % 256):1));
putchar((char) (lastBlackPixel / 256));

我修改上面的code为包括修复,希望那将是更接近。如果没有张贴出来的东西打印机的扫描,这将是非常有用的诊断发生了什么。

I've modified the code above to include the fixes, hopefully that'll be closer. If not post a scan of what comes out of the printer, it will be useful to diagnose what's happening.

有关参考580之间的code:650从 jsStarUSB.cpp 在我看来,是沿着你需要制作一个缓冲一下线(存储在 nextOut ),包含格式的栅格数据直接发送到打印机。

For reference The code between 580:650 from jsStarUSB.cpp seems to me to be along the lines of what you need to produce a buffer (stored in nextOut) that contains the raster data in the format to be sent directly to the printer.

这篇关于使用“光栅模式”直接打印到打印机的以太网:需要基本的指导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆