6.1. 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.1.1. Required Work Contents
The works required to migrate to ICommandBuilder and add a printer model are as follows.
Important
Depending on the combination of printer models, it may be necessary to change the portSettings specification .
6.1.2. Implement StarIOExtension
Make sure that your project includes StarIOExtension. Use libraries of the same SDK version.
Nuget package
winmd files
StarIOPort.winmd
StarIO_Extension.winmd
SMCloudServices.winmd
Details of the library installation procedure are described in How to add the library .
6.1.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 .
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)
string command = "\x1b\x40"; // Initialization
command += "\x1b\x1d\x61\x01"; // Alignment
command += "Hello world";
command += "\x1b\x64\x02"; // Cut paper
ICommandBuilder builder = StarIO_Extension.StarIoExt.CreateCommandBuilder(emulation);
builder.BeginDocument();
builder.AppendAlignment(AlignmentPosition.Right);
builder.AppendData(Encoding.GetEncoding(encoding).GetBytes("Hello world").AsBuffer());
builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);
builder.EndDocument();
builder.GetCommands()
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.
BitmapDecoder starLogoBitmapDecoder = await CreateCouponImageAsync("star_logo_image.png");
ICommandBuilder builder = StarIO_Extension.StarIoExt.CreateCommandBuilder(emulation);
builder.BeginDocument();
await builder.AppendBitmapAsync(starLogoBitmapDecoder, true);
builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);
builder.EndDocument();
builder.GetCommands();
6.1.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 |
// TSP650II (StarLine)
// Emulation emulation = Emulation.StarLine;
// TSP100 (StarGraphic)
// Emulation emulation = Emulation.StarGraphic;
// mC-Print3 (StarPRNT)
Emulation emulation = Emulation.StarPRNT;
ICommandBuilder builder = StarIO_Extension.StarIoExt.CreateCommandBuilder(emulation);
How to search for printers ( FindAllAsync )
The printer search method by FindAllAsync 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 are as follows.
LAN interfaces
Printer
Model Name (ProductInformation)
mC-Print2
“MCP21”, “MCP20”
mC-Print3
“MCP31”, “MCP30”
mC-Label3
“MCL32”
TSP100IV
“TSP143IV”
TSP100IV SK
“TSP143IV”
TSP100IIILAN
“TSP143IIILAN”, “TSP143IIIW”
TSP650II
“TSP654”
TSP700II
“TSP743II”
TSP800II
“TSP847II”
SP700
“SP712”, “SP742”, “SP717”, “SP747”
Bluetooth interface
Printer
Model Name (ProductInformation)
mC-Print2
“mC-Print2-XXXXX”
mC-Print3
“mC-Print3-XXXXX”
mC-Label3
“mC-Label3-XXXXX”
mPOP
“STAR mPOP-XXXXX”
TSP100III
“TSP100-XXXXX”
TSP650II
“Star Micronics”
TSP700II
“Star Micronics”
TSP800II
“Star Micronics”
SP700
“Star Micronics”
SM-S210i
"Star Micronics"[1], "SM-S210I-XXXXX"[2] SM-S230i
"Star Micronics"[1], "SM-S230I-XXXXX"[2] SM-T300
"Star Micronics"[1], "SM-T300-XXXXX"[2] SM-T300i
"Star Micronics"[1], "SM-T300I-XXXXX"[2] SM-T400i
"Star Micronics"[1], "SM-T400I-XXXXX"[2] SM-L200
“Star Micronics”
SM-L300
“Star Micronics”
XXXXX : 5-digit identification number that differs for each product
[1] | Firmware version less than 5.0 |
[2] | Firmware version 5.0 or later |
How to specify ConnectAsync - portName parameter
If the return value of FindAllAsync ( ProductInformation ) 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.
Printer |
Bluetooth DeviceName |
---|---|
TSP100 |
“TSP100-XXXXX” |
TSP650II |
“Star Micronics” |
mC-Print3 |
“mC-Print3-XXXXX” |
XXXXX : 5-digit identification number that differs for each product
StarIOPort.Port port = new StarIOPort.Port();
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";
// No changes required if used "BT:"
string portName = "BT:";
await port.ConnectAsync(portName, portSettings);
Other interfaces
No specific device names are specified for each printer. Refer to the ConnectAsync page and set the appropriate portName for each interface.
How to specify ConnectAsync - portSettings parameter
The identifier that should be used with each model may be different. Please change it referring to 2. portSettings Parameter of ConnectAsync .
For example, the identifiers of portSettings
of TSP100/TSP650II and mC-Print3 are the same.
Printer |
portSettings |
---|---|
TSP100 |
“” |
TSP650II |
“” |
mC-Print3 |
“” |
StarIOPort.Port port = new StarIOPort.Port();
string portName = "BT:";
// string portSettings = "l10000"
string portSettings = "";
await port.ConnectAsync(portName, portSettings);
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 AppendBitmapAsync etc., please change the layout according to the printable area of the printer model you want to migrate to.
6.1.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 async Task<Result> printSample()
{
Result result = Result.ErrorUnknown;
try
{
Emulation emulation = Emulation.StarPRNT;
ICommandBuilder builder = StarIO_Extension.StarIoExt.CreateCommandBuilder(emulation);
builder.BeginDocument();
builder.AppendAlignment(AlignmentPosition.Right);
builder.AppendData(Encoding.GetEncoding(encoding).GetBytes("Hello world").AsBuffer());
builder.AppendCutPaper(CutPaperAction.PartialCutWithFeed);
builder.EndDocument();
IBuffer buffer = builder.GetCommands()
using (StarIOPort.Port port = new StarIOPort.Port())
{
result = Result.ErrorOpenPort;
String portName = "BT:";
String portSettings = "";
await port.ConnectAsync(portName, portSettings);
StarIOPort.Status status;
result = Result.ErrorBeginCheckedBlock;
status = await port.BeginCheckedBlockAsync();
if (status.Offline == true)
{
string message = "Printer is Offline.";
if (status.ReceiptPaperEmpty == true)
{
message += "\nPaper is Empty.";
}
if (status.CoverOpen == true)
{
message += "\nCover is Open.";
}
throw new Exception(message);
}
result = Result.ErrorWritePort;
if (await port.WriteAsync(buffer) != buffer.Length)
{
throw new Exception("WriteAsync failed.");
}
result = Result.ErrorEndCheckedBlock;
status = await port.EndCheckedBlockAsync();
if (status.Offline == true)
{
string message = "Printer is Offline.";
if (status.ReceiptPaperEmpty == true)
{
message += "\nPaper is Empty.";
}
if (status.CoverOpen == true)
{
message += "\nCover is Open.";
}
throw new Exception(message);
}
result = Result.Success;
}
}
catch (Exception)
{
}
return result;
}