SLP440

This is an SLP 440:

http://cdn.overstock.com/images/products/etilize/images/250/1010053866.jpg

It's a label printer that can be operated both by serial and USB. Since the serial interface is simpler than the USB, I chose to use the serial.

Hardware

http://mbed.co.uk/projects/cookbook/attachment/wiki/SLP440/schematic.bmp

In order to allow the mbed to communicate via serial, an RS232 level shifter must be made. The mbed can then be connected through the level shifter to a male D-connector, which in turn connects to the printer. The default baud rate of the SLP440 is 115,200. Make sure you wire up the serial port correctly: the red PCB you can see in the picture is printed wrongly, as it is in fact for the other gender of plug. As a result, I initially wired it up incorrectly and could not work out what was wrong.

Notice the sticker on the chip produced with the printer.

The printer sends XON/XOFF signals to tell the mbed whether it'll recieve any more input.

Software

A detailed documentation of the printer can be found on the manufacturers website (or at the bottom of this page). Each command was laboriously turned into a member function of the class SLP440, to allow easy calling. By combining this library with the BitmapFile library, bitmaps stored on the chip can be printed to the printer. Color images are first converted (poorly) to black and white, since the printer is not color.

Sample program

This program loads a bitmap named "mbed.bmp" stored in the flash memory, then prints it out onto a label. This is how the label on my chip was printed.

#include "mbed.h"
#include "SLP440.h"
#include "BitmapFile.h"

Serial pc(USBTX, USBRX);
SLP440 printer(28,27);

LocalFileSystem local("local");

int main()
{
    BitmapFile MyBitmap("/local/mbed.bmp");
    for(int row = MyBitmap.getHeight()-1; row >=0 ; row--)
    {
        char *bitstream = MyBitmap.getRowBitstream(row,false);

        /* these lines used to invert picture */
        int bytes = (MyBitmap.getWidth()+7)/8;
        for(int col=0; col<bytes; col++)
        {
            bitstream[col] = ~bitstream[col];
            if(col+1 == bytes)
            {
                bitstream[col] ^= 0xFF>>(8-(bytes*8-MyBitmap.getWidth()));
            }
        }
        /* end of picture inversion */

        printer.Print(bytes,bitstream);
        delete [] bitstream;
    }
    MyBitmap.close();
    printer.FeedLabel();
}

Here is the image I used on my chip:

http://mbed.co.uk/projects/cookbook/svn/SLP440/examples/SLP440/mbed.bmp

API

The library is avaliable from:

SLP440A class to use an SLP440 label printer.
Functions
WaitForEmptyBufferWaits for the printer to accept data.
SLP440Creates an instance of the SLP440 class.
PrintPrint literal (binary) data
PrintRLEPrint compressed (RLE) data
SetMarginSet offset (in mm) from left side
RepeatPrintRepeat last print command
TabTab a number of dots to the right
LineFeedFeed label one dot
VTabFeed label a number of dots
FeedLabelfeed to top of next label
SetSpeedSet printer speed mode
SetDensitySet printer density
ResetReset printer
ReverseFeedFeed paper backwards a number of dots
Checkpointsend checkpoint response
GetModelNumRequest printer model number
SetIndentSet image offset in dots from left side
SetFineModeSet anti-banding mode on/off
SetXOFFThresholdSet XOFF threshold
SetXONThresholdSet XON threshold
EnableDiagnosticsEnable diagnostic mode
SetSerialNoSet serial number
SetOptionsChange option settings
GetOptionsRequest option settings
SetModeSet printer mode
GetModeGet printer mode
SetLabelLengthSet the label length in millimeters
CheckBaudRateCheck for correct baud rate
class SLP440
A class to use an SLP440 label printer.
void WaitForEmptyBuffer()
Waits for the printer to accept data.
SLP440(int tx,
int rx)
Creates an instance of the SLP440 class.

Attachments