Search code examples
objective-cccocoa-touchgraphicsprinting

Printing directly to Ethernet printer using 'raster mode': need basic guidance


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.

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"

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.

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.

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.


Solution

  • I have a hunch this might be the same as the old Seiko printers, only yours is network enabled. If so, have a look at the C code here. It tries to output to a serial port /dev/cua, where it thinks the printer is.

    But if the commands are the same, the code should help you. It takes as input the Portable Bitmap Format, which is plain ASCII text.

    But I don't know. Microsoft indicates Star Micronics works the same as Epson LQ, in which case there is ample documentation.

    Related links:


    Update! ;-) Try this, totally untested code:

    /* Call with grayscale images of height 256, width 256. */
    
    - (void) outputraster(char* pixels, int rows)
    {
        const char initializeRaster[] =    "\x1B\x2A\x72\x52";
        const char enterRaster[] =         "\x1B\x2A\x72\x41";
        const char formFeed[] =            "\x1B\x0C\x00";
        const char clearRaster[] =         "\x1B\x2A\x72\x43";
        const char exitRaster[] =          "\x1B\x2A\x72\x42";
    
    /* The FF means 255 lines: */
        char setRasterPageLength[]         "\x1B\x2A\x72\x50\xFF\x0";
    
    
    /* The FF FF means 256 lines and 256 rows: */
        char sendRasterData[] =            "\x62\xFF\xFF";
    
        [self sendBytes:initializeRaster ofLength:sizeof(initializeRaster)];
        [self sendBytes:enterRaster ofLength:sizeof(enterRaster)];
        [self sendBytes:clearRaster ofLength:sizeof(clearRaster)];
        [self sendBytes:setRasterPageLength ofLength:sizeof(setRasterPageLength)];
        [self sendBytes:sendRasterData ofLength:sizeof(sendRasterData)];
    
        while (rows)
        {
            for (int x = 0; x < 255; x++)
            {
                [self sendBytes:pixels[x] ofLength:256];
            }
    
            rows --;
        }
    }
    

    Update!


    I was looking at the docs at night, and stumbled upon how you can print out a prestored logo. Then I looked at how to define that logo, and that part of the documentation looked a lot more thorough: alt text alt text alt text

    Explanations of bitmap format for a similar printer: alt text

    Also, look at pages 34 and on for an explanation of the bitmap format of a Star printer.