6.3. ICommandBuilder Migration Guide (A Function Incorporated in the StarPRNT V5)

This is an ICommandBuilder migration guide to minimize printer-model dependency.

ICommandBuilder is a function that enables human-readable command creation instead of conventional binary command creation and incorporated in the extension library of StarPRNT V5.0 or later (hereinafter, StarIOExtension )

Until now, developers had to create commands after understanding the specifications of printer emulation, however this function can reduce learning costs and man-hours for adding printer models

Please use ICommandBuilder referring to this guide.

6.3.1. Required Work Contents

The works required to migrate to ICommandBuilder and add a printer model are as follows.

  1. Implement StarIOExtension
  2. Change API and command creation method
  3. Change emulation
  4. Specify portName

Important

Depending on the combination of printer models, it may be necessary to change the portSettings specification .

6.3.2. Implement StarIOExtension

Make sure that your project includes StarIOExtension. Use libraries of the same SDK version.

Nuget package

dll files

  • StarIO.dll
  • StarIOExtension.dll
  • SMCloudServicesSolution.dll

Details of the library installation procedure are described in How to configuration StarPRNT Application .

6.3.3. How to change API and command creation method (Introduction of ICommandBuilder)

Differences in overall flow

As shown in the following flow, no changes other than the command creation method are required to use ICommandBuilder .

migrationFlowEN

Changes in print data creation program (printer built-in font)

The code for printing the printer built-in font used for characters on receipts will change as shown in the sample below. Please make the necessary change according to the function you are using.

See ICommandBuilder for a list of supported features.

Note

The TSP100 series does not support printer fonts. Please see Changes in Changes in print data creation program (image data)

Before: Using only StarIOPort
string command = "\x1b\x40";       // Initialization
command += "\x1b\x1d\x61\x01";     // Alignment
command += "Hello world";
command += "\x1b\x64\x02";         // Cut paper
After: Using StarIOPort + ICommandBuilder/StarIOExtension
ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

builder.BeginDocument();
builder.AppendAlignment(AlignmentPosition.Right);
builder.Append(Encoding.GetEncoding(encoding).GetBytes("Hello world").AsBuffer());
builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);
builder.EndDocument();

builder.commands

Changes in print data creation program (image data)

The code for printing image data used for store logos etc.

See ICommandBuilder for a list of supported features.

After: Using StarIOPort + ICommandBuilder/StarIOExtension
using (var stream = Properties.Resources.star_logo_image)
{
    starLogoImage = new Bitmap(stream);
}

ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

builder.BeginDocument();
await builder.AppendBitmap(starLogoImage, true);
builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);
builder.EndDocument();

builder.commands

6.3.4. How to add a printer model

When adding or migrating a printer model, if you are using ICommandBuilder to create printer commands, you will only need to change the emulation in most cases.

However, in some situations, additional changes are required. Please make the necessary changes referring to the information below.

How to change the emulation ( ICommandBuilder )

The mC-Print3 and other printers may support different emulations.

Check the supported emulation on the Emulation page and change the emulation when creating an ICommandBuilder instance.

For example, in case of TSP100/TSP650II and mC-Print3, it is necessary to change the emulation according to the table below.

Printer Emulation
TSP650II StarLine
TSP100 StarGraphic
mC-Print3 StarPRNT
Sample code for emulation change
// TSP650II (StarLine)
// Emulation emulation = Emulation.StarLine;

// TSP100 (StarGraphic)
// Emulation emulation = Emulation.StarGraphic;

// mC-Print3 (StarPRNT)
Emulation emulation = Emulation.StarPRNT;
ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

How to search for printers ( SearchPrinter )

The printer search method by SearchPrinter is the same.

If the model name obtained from the search is used for some determination in the application, it is necessary to change it

For example, the printer model names included in the search results for TSP100/TSP650II and mC-Print3 are as follows.

LAN interfaces

Printer Model Name (PortInfo)
TSP100III “TSP143IIILAN (STR_T-001)”, “TSP143IIIW (STR_T-001)”
TSP650II “TSP654 (STR_T-001)”
mC-Print3 “MCP31 (STR-001)”, “MCP30 (STR-001)”

USB interfaces

Printer Model Name(PortInfo)
TSP100III “Star TSP100 Cutter (TSP143)”
TSP650II “TSP650II Cutter (TSP654II)”
mC-Print3 “Star MCP31/30”

Bluetooth interface

Printer Model Name (PortInfo)
TSP100 “TSP100-XXXXX”
TSP650II “Star Micronics”
mC-Print3 “mC-Print3-XXXXX”

XXXXX : 5-digit identification number that differs for each product

How to specify GetPort - portName parameter

If the return value of SearchPrinter ( PortInfo ) is used to specify portName , there is no need to change the parameter.

However, if the parameter is specified directly (fixed value, etc.), the default value of the device name differs between mC-Print3 and other models, so the parameter may need to be changed.

For example, the default values of TSP100/TSP650II and mC-Print3 are as follows.

Bluetooth interface

Printer Bluetooth DeviceName
TSP100 “TSP100-XXXXX”
TSP650II “Star Micronics”
mC-Print3 “mC-Print3-XXXXX”

XXXXX : 5-digit identification number that differs for each product

USB PrinterClass interface

Printer USB Printer queue name
TSP100III “Star TSP100 Cutter (TSP143)”
TSP650II “TSP650II Cutter (TSP654II)”
mC-Print3 “Star MCP31/30”
Sample
IPort port = null;
string portSettings = "";

// TSP650II (Bluetooth)
// string portName = "BT:Star Micronics";

// TSP100 (Bluetooth)
// string portName = "BT:TSP100-XXXXX";

// mC-Print3 (Bluetooth)
// string portName = "BT:mC-Print3-XXXXX";

// mC-Print3 (USB Printer Class)
// string portName = "Star MCP31/30";

// No changes required if used "BT:"
string portName = "BT:";

port = Factory.I.GetPort(portName, portSettings, timeout)

Other interfaces

No specific device names are specified for each printer. Refer to the StarIOPort_getPort page and set the appropriate portName for each interface.

How to specify GetPort - portSettings parameter

The identifier that should be used with each model may be different. Please change it referring to 2. portSettings Parameter of GetPort .

For example, the identifiers of portSettings of TSP100/TSP650II and mC-Print3 are the same.

Printer portSettings
TSP100 “”
TSP650II “”
mC-Print3 “”
Sample
IPort port = null;
string portName = "BT:";

// string portSettings = "l10000"
string portSettings = "";

port = Factory.I.GetPort(portName, portSettings, timeout)

How to specify the printable area

The initial value of the printable area setting differs depending on the printer models. Specify the printable area with AppendPrintableArea as necessary.

If graphic data is printed by using AppendBitmap etc., please change the layout according to the printable area of the printer model you want to migrate to.

6.3.5. Code flow from command creation to data transmission

The following is the flow from command creation to writing. In actual operation, execute the following function in a non-UI thread.

public static void PrintSample(byte[] commands, string portName, string portSettings, int timeout)
{
    CommunicationResult result = CommunicationResult.ErrorUnknown;

    IPort port = null;
    try
    {
        Emulation emulation = Emulation.StarPRNT;
        ICommandBuilder builder = StarIoExt.CreateCommandBuilder(emulation);

        builder.BeginDocument();
        builder.AppendAlignment(AlignmentPosition.Right);
        builder.Append(Encoding.GetEncoding(encoding).GetBytes("Hello world").AsBuffer());
        builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);
        builder.EndDocument();

        String portName = "BT:";
        String portSettings = "";

        result = CommunicationResult.ErrorOpenPort;
        port = Factory.I.GetPort(portName, portSettings, timeout);

        StarPrinterStatus status;
        result = CommunicationResult.ErrorBeginCheckedBlock;

        status = port.BeginCheckedBlock();
        if (status.Offline)
        {
            throw new PortException("Printer is Offline.");
        }

        result = CommunicationResult.ErrorWritePort;

        uint commandsLength = (uint)commands.Length;
        uint writtenLength = port.WritePort(commands, 0, commandsLength);
        if (writtenLength != commandsLength)
        {
            throw new PortException("WritePort failed.");
        }

        result = CommunicationResult.ErrorEndCheckedBlock;
        status = port.EndCheckedBlock();
        if (status.Offline == true)
        {
            throw new PortException("Printer is Offline.");
        }

        result = CommunicationResult.Success;
    }
    catch (PortException) {} finally
    {
        if (port != null)
        {
            Factory.I.ReleasePort(port);
        }
    }

    return result;
}