Sato Printer Api Reference Document
Sato Printer Api Reference Document
Sato Printer Api Reference Document
Version 3.0
13-Aug-2018
Page | 1
CONTENTS
Copyrights........................................................................................................................................................... 6
Trademarks ........................................................................................................................................................ 6
Overview ............................................................................................................................................................. 7
Download ............................................................................................................................................................ 7
Setup ................................................................................................................................................................... 8
Connect ..................................................................................................................................................... 13
Page | 2
Send Single Data..................................................................................................................................... 13
Disconnection........................................................................................................................................... 15
Test Print................................................................................................................................................... 16
Utilities functions.......................................................................................................................................... 24
Page | 3
Command Data Replace ........................................................................................................................ 24
Socket Server........................................................................................................................................... 27
Classes ......................................................................................................................................................... 32
Page | 4
SOFTW ARE LICENSE AGREEMENT
PLEASE READ THE FOLLOWING TERMS AND or destroy, the printer and all copies of the Software
and documentation.
CONDITIONS BEFORE USING THIS PRODUCT. BY
INSTALLING THE PRODUCT YOU THEREBY INDICATE 9. SATO Corporation warrants that for ninety (90) days
YOUR ACCEPTANCE OF THESE TERMS AND after delivery, the Software will perform in
CONDITIONS. SHOULD YOU DISAGREE WITH ANY OF accordance with specifications published by SATO
THE TERMS OR CONDITIONS LISTED BELOW, Corporation, and that the distribution media will be
PROMPTLY REMOVE ALL FILES RELATED TO THIS free from defects in material and workmanship.
PRODUCT FROM YOUR HOST PLATFORM AND SATO Corporation does not warrant that the
RETURN THE PRODUCT TO SATO CORPORATION. Software is free from all bugs, errors and omissions.
1. You explicitly agree to accept a non-exclusive license 10. Your exclusive remedy and the sole liability of SATO
to use the Software identified on the distribution Corporation in connection with the Software is
media solely for your own customary business or replacement of defective distribution media upon
personal purposes. Your local and national laws their return to SATO Corporation. SATO
govern this Agreement. Corporation will not be liable for any loss or damage
caused by delays in furnishing a Software Product or
2. Henceforth, “Software” shall refer to the digitally
encoded, machine-readable data and program. The any other performance under this Agreement. SATO
term “Software Product” includes the Software Corporation does not warrant that the functions
identified on the distribution media, including any contained in the Software will meet your
accompanying documentation. The term “Distribution requirements or that the operation of the Software will
Media” refers to any method by which the Software be uninterrupted or error free.
Product is delivered to the end user, including but not 11. Use, duplication or disclosure by the Government is
limited to Floppy Disks, CD-ROM, Magnetic Tape subject to restrictions as set forth in the relevant
and On-Line distribution via the Internet. The guidelines of your country, such as the Rights in
Software Product is licensed (not sold) to you, and Technical Data and Computer Software clause at
SATO® either owns or licenses from other vendors FAR 242.227- 7013, subdivision (b) (3) (ii) or
who own all copyright, trade secret, patent and other subparagraph (c) (1) (ii), as appropriate. Further use,
proprietary rights in the Software Product. duplication or disclosure is subject to restrictions
3. To protect the proprietary rights of SATO Corporation, applicable to restricted rights software as set forth in
FAR 52.227-19 (c) (2) or equivalent rules.
you agree to maintain the Software Product and other
proprietary information concerning the Software THE PARTIES AGREE THAT ALL OTHER WARRANTIES,
Product in strict confidence and to establish EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF
reasonable procedures regulating access to and use FITNESS FOR A PARTICULAR PURPOSE AND
of the software. MERCHANTABILITY ARE EXCLUDED.
4. You agree not to duplicate or copy the Software SATO Corporation reserves the right to make changes
except that you may make one backup copy. You and/or improvements in the Software without notice at any
agree that any such copy shall contain the same time.
proprietary notices as those appearing on the IN NO EVENT WILL SATO CORPORATION BE LIABLE
original.
FOR LOST PROFITS, LOST DATA, BUSINESS
5. You shall not sub-license, sell, lease, or otherwise INTERRUPTIONS OR ANY OTHER DIRECT, INDIRECT,
transfer all or any portion of the Software Product INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
separate from the printer(s), without the prior written OUT OF THE USE OF OR INABILITY TO USE THIS
consent of SATO Corporation. PRODUCT, EVEN IF SATO CORPORATION HAS BEEN
6. You may not modify or prepare derivative works of ADVISED OF THE POSSIBILITY OF SUCH DAMAGES,
OR ANY DAMAGES CAUSED BY ABUSE OR
the Software Product. You may not transmit the
Software Product over a network, by telephone, or MANIPULATION OF THE SOFTWARE. SOME STATES
DO NOT ALLOW THE EXCLUSION OR LIMITATION OF
electronically using any means; or reverse engineer,
decompile or disassemble the Software. LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL
DAMAGES, SO THE ABOVE LIMITATION MAY NOT
7. You may transfer the Software Product with the APPLY TO YOU.
printer(s), but only if the recipient agrees to accept
the terms and conditions of this Agreement. Your YOU ACKNOWLEDGE THAT YOU HAVE READ THIS
license is automatically terminated if you transfer the AGREEMENT, UNDERSTAND IT, AND AGREE TO BE
Software Product and printer(s). BOUND BY ITS TERMS AND CONDITIONS. NEITHER
PARTY SHALL BE BOUND BY ANY STATEMENT NOR
8. This License remains in force until terminated, and REPRESENTATION NOT CONTAINED IN THIS
may be terminated by agreement between you and AGREEMENT. NO CHANGE IN THIS AGREEMENT IS
SATO Corporation, or by SATO Corporation, if you EFFECTIVE UNLESS WRITTEN AND SIGNED BY
fail to comply with the terms of this License if such PROPERLY AUTHORIZED REPRESENTATIVES OF
failure is not corrected within thirty (30) days after EACH PARTY. BY INSTALLING THIS SOFTWARE
notice. When this License is terminated, you shall PRODUCT, YOU AGREE TO ACCEPT THE TERMS
either return to the place you obtained them from, AND-CONDITIONS OF THIS AGREEMENT.
Page | 5
COPYRIGHTS
LIMITATION OF LIABILITY
SATO Corporation and its subsidiaries in Japan, the U.S and other countries make
no representations or warranties of any kind regarding this material, including, but
not limited to, implied warranties of merchantability and fitness for a particular
purpose. SATO Corporation shall not be held responsible for errors contained
herein or any omissions from this material or for any damages, whether direct,
indirect, incidental or consequential, in connection with the furnishing, distribution,
performance or use of this material.
Specifications and contents of this document are subject to change without notice.
TRADEMARKS
While all efforts have been taken to ensure accuracy and currency of the
information contained herein, there are instances where the contents of this
document may be outdated. In that case, proceed to SATO worldwide websites
(www.satoworldwide.com) to check whether an updated document has been made
available for your reference.
Page | 6
OVERVIEW
The SATO Printer API was developed to simplify the communication between .NET
applications and SATO printers.
Software developers can use this API to send printer commands to printer as well
as to receive response from printer if there is any.
Also, SATO Printer API can be used for getting SATO printer list from printer driver,
check number of job in printer spooler or printer information from printer driver.
SYSTEM REQUIREMENTS
CLIENT COMPUTER
Custom application developed with SATO Printer API must be distributed with the
DLL files of SATO Printer API. And following components must be installed on the
client computer.
• Microsoft .NET Framework 4.0 (or higher version)
• Visual C++ Redistributable Package for Visual Studio 2013
DOW NLOAD
Latest version of the SATO Printer API is available on following URL webpage.
http://www.satoworldwide.com/software/sato-printer-interface-api.aspx
Page | 7
SETUP
Execute the SATO Printer API setup package and follow the guidance of the setup
wizard. By default, the SATO Printer API files will be install in below folder.
x86 environment:
C:¥Program Files¥SATO¥SATO Printer API
x64 environment:
C:¥Program Files (x86)¥SATO¥SATO Printer API
Page | 8
USING THE SATO PRINTER API
DISCOVERY PORTS
Gets a list of the port available on the computer. For COM port and LPT port, this
returns all available ports based on Windows device management regardless of
printer connection. For USB, it will returns connected SATO printer ports.
As for TCP/IP, API will discover SATO printers on the same broadcast segment
through available TCP/IP interfaces of PC then return a list of discovered SATO
printer information. The information includes printer IP address and MAC address.
Method syntax
COM port:
GetCOMList()
LPT port:
GetLPTList()
USB port:
GetUSBList()
Page | 9
TCPIP:
GetTCPIPList()
Parameters
Not Applicable
Return Values
COM port: List of string
LPT port: List of string
USB port: List of USBInfo class
TCPIP : List of TCPIPInfo class
Supported socket server
Yes
Example (C#)
COM port:
List<string> COMPorts = SATOPrinter.GetCOMList();
LPT port:
List<string> LPTPorts = SATOPrinter.GetLPTList();
USB port:
List<Printer.USBInfo> USBPorts = SATOPrinter.GetUSBList();
TCPIP:
List<Printer.TCPIPInfo> TCPIPs = SATOPrinter.GetTCPIPList();
Before sending data to the printer, require to specify interface type of the printer
connection. Below properties allow setting interface type for COM, USB, LPT or
TCP/IP.
Properties syntax
.Interface
Supported socket server
Yes
Example (C#)
COM port:
Page | 10
SATOPrinter.Interface = Printer.InterfaceType.COM;
LPT port:
SATOPrinter.Interface = Printer.InterfaceType.LPT;
USB port:
SATOPrinter.Interface = Printer.InterfaceType.USB;
TCP/IP port:
SATOPrinter.Interface = Printer.InterfaceType.TCPIP;
Before sending data to the printer, require to specify the interface port of the printer
connection. Below properties allow you to set COM, LPT or USB port or IP address
and IP Port of printer you want to communicate.
Properties syntax
COM port:
.COMPort
LPT port:
.LPTPort
USB port:
.USBPortID
TCP/IP port:
.TCPIPAddress
.TCPIPPort
Supported socket server
Yes
Example (C#)
COM port:
SATOPrinter.COMPort = “COM1”;
LPT port:
SATOPrinter.LPTPort = “LPT1”;
USB port:
Page | 11
SATOPrinter.USBPortID =
“¥¥?¥usb#vid_0828&pid_0122#6&1161632e&0&1#{a5dcbf10-6530-11d2-901f-00c04
fb951ed}”;
TCP/IP port:
SATOPrinter.TCPIPAddress = "10.25.7.204";
SATOPrinter.TCPIPPort = "1024";
When using serial COM port for connection, it can change baud rate and
parameters. Default baud rate is 9600 and parameters 8-N-1.
Properties class syntax
COMSetting
Supported socket server
Yes
Example (C#)
SATOPrinter.COMSetting.Baudrate = 115200
SATOPrinter.COMSetting.Parameters = “8-N-1”
SET TIMEOUT
This timeout variable applies to connection timeout, send data timeout and receive
data timeout. The default timeout is 2500 (2.5 seconds), in milliseconds format.
Properties syntax
.Timeout
Supported socket server
Yes
Example (C#)
SATOPrinter.Timeout = 5000; //(5 seconds timeout)
The permanent connection flag allows printer connection open at all time. The
default value is false. (SATO Printer only allow for one active connection, please
use it wisely)
Page | 12
Properties syntax
.PermanentConnect
Supported socket server
No
Example (C#)
SATOPrinter.PermanentConnect = true;
CONNECT
Send method will send a single command data to the printer. This method wills
automatic raise connection to the printer and sends command. If
“PermanentConnect” flag not set or set to false, it will automatic disconnect the
connection. Ensure to set interface port and interface type before using this
method.
Method syntax
Send(byte[] data)
Parameters
Byte Array data
Page | 13
Return Values
Not Applicable
Supported socket server
Yes
Example (C#)
SATOPrinter.Send(<Byte Array SBPL command>);
Query method will send a single command to the printer and return received a
single reply from the printer. This method will connect to the printer and send
command data, disconnect connection from the printer when a reply data is
received. Ensure to set interface port and interface type before use this method.
(Note: permanent connection should not use this method)
Method syntax
Query(byte[] data)
Parameters
Byte Array data
Return Values
Byte Array data
Supported socket server
Yes
Example (C#)
Byte[] Printer_Reply = SATOPrinter.Query(<Byte Array SBPL Query command>);
To process reply data from printer while using the permanent connection, need to
use event handler. Below example in C# shows for initializing the event method:-
Example (C#)
Initialize event method handler:
SATOPrinter.ByteAvailable += new
EventHandler<Printer.ByteAvailableEventArgs>(ReadMsg);
Page | 14
Create an event method:
private void ReadMsg(object sender, Printer.ByteAvailableEventArgs e)
{
byte[] rawData = e.Data;
string printerReplied = Utils.ByteArrayToString(b);
}
DISCONNECTION
This method to get printer status and return a class values. Ensure to set interface
port and interface type before use this method.
Method syntax
GetPrinterStatus()
Parameters
Not Applicable
Return Values
Printer Status Class
Supported socket server
Yes
Page | 15
Example (C#)
Printer.Status pStatus = SATOPrinter.GetPrinterStatus();
TEST PRINT
This method to instruct the printer to print a test label. Ensure to set interface port
and interface type before use this method.
Method syntax
TestPrint()
Parameters
Not Applicable
Return Values
Not Applicable
Supported socket server
Yes
Example (C#)
SATOPrinter.TestPrint();
This method to empty/clear printer buffer (labels data in printer memory). Ensure to
set interface port and interface type before use this method.
Method syntax
ClearBuffer()
Parameters
Not Applicable
Return Values
Not Applicable
Supported socket server
Yes
Example (C#)
SATOPrinter.ClearBuffer();
Page | 16
REPRINT LABEL
This method to instruct the printer to reprint the last printed label. Ensure to set
interface port and interface type before use this method.
Method syntax
Reprint()
Parameters
Not Applicable
Return Values
Not Applicable
Supported socket server
Yes
Example (C#)
SATOPrinter.Reprint();
Page | 17
PRINTER DRIVER FUNCTIONS
Gets list of printer driver on the computer. This will reply SATO printer driver only.
Method syntax
GetDriverList()
Parameters
Not Applicable
Return Values
List of Driver Info
Supported socket server
Yes
Example (C#)
List<Driver.Info> Drivers = SATODriver.GetDriverList();
Page | 18
GET LIST OF DRIVER PORT NAME
Page | 19
SET DRIVER INFO
Page | 20
CLEAR SPOOLER PRINT JOBS
Page | 21
GET PORT INFO FROM PORT NAME
Get printer driver company and printer driver version by driver name.
Method syntax
GetVersion(string DriverName)
Parameters
String of Driver Name
Return Values
String of driver version
Supported socket server
Yes
Format
Driver Company|Driver Version
(example: SEAGULL SCIENTIFIC, INC.|7.4.2.0
SATO CORPORATION|7.1.02.10208)
Example (C#)
string driverVersion = SATODriver.GetVersion(“SATO CL412e”);
Page | 22
SEND BYTE ARRAY RAW DATA THROUGH DRIVER
Page | 23
UTILITIES FUNCTIONS
This static method to convert image file into SBPL graphic commands (ESC+G)
Method syntax
ConvertGraphicToSBPL(string GraphicFilePath)
Parameters
GraphicFilePath as string
Return Values
SBPL commands as string
Supported socket server
Yes
Example (C#)
string graphicCommands =
Utils.ConvertGraphicToSBPL(“C:/Pictures/my.png”);
Or
string graphicCommands = Utils.ConvertGraphicToSBPL(new
Uri(“https://abc.com/my.png”));
This static method to uses predesigned template file with variable data to replaced
desired value. Mainly use for PRN template file and it created by Nice Label
Software.
Method syntax
CommandDataReplace(string CommandFilePath, Dictionary<string,string>
VariablesValue)
Parameters
CommandFilePath as string
VariablesValue list as Dictionary
Return Values
Page | 24
Replaced variables command as string
Supported socket server
Yes
Example (C#)
Dictionary<string,string> variables = new Dictionary<string,string>();
variables.Add(“@Var1@”,”SATO Printer”);
variables.Add(“@Var2@”,”$100.00”);
variables.Add(“@Barcode1@”,”123456789”);SATO
string PRNCommands = Utils.CommandDataReplace (“C:/data/my.prn”,
variables);
Or
string PRNCommands = Utils.CommandDataReplace (new
Uri(“https://abc.com/my.prn”), variables);
Page | 25
Parameters
Byte array data
Return Values
String data
Supported socket server
No
Example (C#)
string strData = Utils.ByteArrayToString(<Byte array data>);
Page | 26
WEB SOCKET FUNCTIONS
Initialize the web socket server. (By enable web socket server, it allow web
application accessing SATO Printer API functions like SATO printer TCP/IP
discovery, driver settings change etc.) It defaults 8055 port for the socket server
and you may change it if the port is been occupied in the PC.
Class constructor syntax
SocketServer()
Parameters
Port as Integer (default 8055)
Web Socket URL for client to connect
Non-Secure: ws://localhost:8055/SATOPrinterAPI
Secure: wss://localhost:8055/SATOPrinterAPI (required to enable secure socket
server)
Example (C#)
using SATOPrinterAPI;
SocketServer SATOServer = new SocketServer(); //Use default 8055 port
Or
SocketServer SATOServer = new SocketServer(8081); //Change default port to
8081
If the Web application using SSL secure channel like HTTPS, it better to enable
secure socket server for the data communication. Follow the instruction link below
to export the localhost certificate for secure socket server.
(https://www.sslsupportdesk.com/export-ssl-certificate-private-key-pfx-using-mmc-
windows/)
Properties syntax
.Certificate
Parameters
Not Applicable
Page | 27
Return Values
Not Applicable
Example (C#)
SATOServer.Certificate = new
System.Security.Cryptography.X509Certificates.X509Certificate2
(@"C:/cert/localhost_cert.pfx", "0310"); //(certificate file path and
password)
Starting socket server it may allow client to connect and consume API functions.
For secure socket server, please ensure to define a certificate details before start
the socket server.
Method syntax
Start()
Parameters
Not Applicable
Return Values
Not Applicable
Example (C#)
SATOServer.Start();
Page | 28
EXAMPLE OF CALLING API FUNCTION IN W EB SOCKET CLIENT
It work similar from the API called, JSON input data consist of properties, method
and parameters. It supported string input or byte array input. By using string input,
those byte array data required to encode as base64 string. If API return value is
Class form or List form, it will be JSON, other than that it will return as string (Byte
array return will be encoded as base64 string). Please refer below example to
understand further.
Example 1:
Printer API function: Get Printer TCP/IP List
JSON input:
{
"Method":"Printer.GetTCPIPList"
}
Output:
[{"Name":"CL4NX
203dpi","MacAddress":"00:19:98:12:30:DD","IPAddress":"10.65.2.178","Details":"S
ATO LAN Interface"},
{"Name":"CL4NX
203dpi","MacAddress":"78:A5:04:93:D6:57","IPAddress":"10.65.2.75","Details":"SA
TO LAN Interface"}]
Example 2:
Printer API function: Query commands to printer
JSON input: ([ENQ] control char in base64 encoded string is [BQ==])
{
"Interface":"TCPIP",
"TCPIPAddress":"10.65.2.75",
"TCPIPPort":"9100",
"Method":"Printer.Query",
Page | 29
"Parameters":{
"Data":"BQ=="}
}
Output:
AAAAHAUCICBBMDAwMDAwICAgICAgICAgICAgICAgIAM=
Example 3:
Printer API function: Instruct printer to print a test print label
JSON input:
{
"Interface":"TCPIP",
"TCPIPAddress":"10.65.2.75",
"TCPIPPort":"9100",
"Method":"Printer.TestPrint"
}
Output:
{"Result":"Executed"}
Example 4:
Driver API function: Get list of printer driver on the computer
JSON input:
{
“Method":"Driver.GetDriverList"
}
Output:
[{"PrinterModel":"SATO PW208NX","DriverName":"SATO
PW208NX","PortName":"COM1:","Online":false,"Default":false,"Bidirectional":true},
{"PrinterModel":"SATO PW208","DriverName":"SATO
PW208","PortName":"FILE:","Online":true,"Default":false,"Bidirectional":true}]
Page | 30
Example 5:
Driver API function: Get number of print jobs in the printer driver spooler by the
driver name.
JSON input:
{
"Method":"Driver.GetSpoolerPrintJobsNumber",
"Parameters":{
"DriverName":"SATO PW208"}
}
Output:
0
Example 6:
Utils API function: Commands data replace from PRN file
JSON input:
{
"Method":"Utils.CommandDataReplace",
"Parameters":{
"CommandFilePath":"file:///C:/data/my.prn",
"VariablesValue":{
"@var1@":"SATO Printer",
"@var2@":"$100.00",
"@barcode1@":"123456789"}}
}
Output:
GyMjAcK8BgQAAA ……..
Page | 31
CLASSES
string Name
string PortID
string Name
string MACAddress
string IPAddress
string Details
int Buffer
string Code
string Description
bool IsOnline
bool IsError
string JobName
string JobID
string Raw
string State
Page | 32
CLASS FOR DRIVER.INFO
string PrinterModel
string DriverName
string PortName
bool Online
bool Default
bool Bidirectional
string IPAddress
string Port
string Name
Printer.InterfaceType Interface
Page | 33
Extensive contact information of worldwide SATO
operations can be found on the internet at
www.satoworldwide.com
Page | 34