SATO Printer Interface API

SATO Printer Interface API
Version 1.2
16-OCT-2014
SATO Global Business Services Pte. Ltd.
SATO Printer Interface API
Page | 1
CONTENTS
Software License Agreement ................................................................................................................ 3
Copyrights ............................................................................................................................................. 4
Limitation of Liability.............................................................................................................................. 4
Trademarks ........................................................................................................................................... 4
Software updating disclaimer................................................................................................................ 4
Overview ............................................................................................................................................... 5
System Requirements ........................................................................................................................... 5
Software development environment ................................................................................................. 5
Client computer ................................................................................................................................. 5
Download .............................................................................................................................................. 5
Setup ..................................................................................................................................................... 6
Using the SATO Printer Interface API .................................................................................................. 7
Printer communication functions ....................................................................................................... 7
Connection ..................................................................................................................................... 7
Get list of ports ............................................................................................................................... 7
Set interface port ........................................................................................................................... 8
Set interface type ........................................................................................................................... 9
Send single query and receive single reply ................................................................................ 10
Send single DATA ....................................................................................................................... 11
Asynchronous send ..................................................................................................................... 11
Disconnection .............................................................................................................................. 12
Receive data from printer using async send method .................................................................. 12
Printer driver functions .................................................................................................................... 13
Initiate the functions ..................................................................................................................... 13
Get list of installed printer driver .................................................................................................. 13
Get number of jobs in spooler from printer driver ....................................................................... 14
Get port information from printer driver ....................................................................................... 14
Send string data through Driver .................................................................................................. 14
Send byte array data through Driver ........................................................................................... 15
Classes ............................................................................................................................................ 16
Class for USBInfo ........................................................................................................................ 16
Class for TCPIPInfo ..................................................................................................................... 16
Class for DriverInfo ...................................................................................................................... 16
Class for PrinterInfo ..................................................................................................................... 16
SATO Printer Interface API
Page | 2
SOFTW ARE LICENSE AGREEMENT
PLEASE READ THE FOLLOWING TERMS AND
CONDITIONS BEFORE USING THIS PRODUCT. BY
INSTALLING THE PRODUCT YOU THEREBY INDICATE
YOUR ACCEPTANCE OF THESE TERMS AND
CONDITIONS. SHOULD YOU DISAGREE WITH ANY OF
THE TERMS OR CONDITIONS LISTED BELOW,
PROMPTLY REMOVE ALL FILES RELATED TO THIS
PRODUCT FROM YOUR HOST PLATFORM AND
RETURN THE PRODUCT TO SATO CORPORATION.
1.
You explicitly agree to accept a non-exclusive license
to use the Software identified on the distribution
media solely for your own customary business or
personal purposes. Your local and national laws
govern this Agreement.
2.
Henceforth, “Software” shall refer to the digitally
encoded, machine-readable data and program. The
term “Software Product” includes the Software
identified on the distribution media, including any
accompanying documentation. The term “Distribution
Media” refers to any method by which the Software
Product is delivered to the end user, including but not
limited to Floppy Disks, CD-ROM, Magnetic Tape
and On-Line distribution via the Internet. The
Software Product is licensed (not sold) to you, and
SATO® either owns or licenses from other vendors
who own all copyright, trade secret, patent and other
proprietary rights in the Software Product.
3.
4.
To protect the proprietary rights of SATO Corporation,
you agree to maintain the Software Product and other
proprietary information concerning the Software
Product in strict confidence and to establish
reasonable procedures regulating access to and use
of the software.
You shall not sub-license, sell, lease, or otherwise
transfer all or any portion of the Software Product
separate from the printer(s), without the prior written
consent of SATO Corporation.
6.
You may not modify or prepare derivative works of
the Software Product. You may not transmit the
Software Product over a network, by telephone, or
electronically using any means; or reverse engineer,
decompile or disassemble the Software.
7.
You may transfer the Software Product with the
printer(s), but only if the recipient agrees to accept
the terms and conditions of this Agreement. Your
license is automatically terminated if you transfer the
Software Product and printer(s).
This License remains in force until terminated, and
may be terminated by agreement between you and
SATO Corporation, or by SATO Corporation, if you
fail to comply with the terms of this License if such
failure is not corrected within thirty (30) days after
notice. When this License is terminated, you shall
either return to the place you obtained them from,
SATO Printer Interface API
9.
SATO Corporation warrants that for ninety (90) days
after delivery, the Software will perform in
accordance with specifications published by SATO
Corporation, and that the distribution media will be
free from defects in material and workmanship.
SATO Corporation does not warrant that the
Software is free from all bugs, errors and omissions.
10. Your exclusive remedy and the sole liability of SATO
Corporation in connection with the Software is
replacement of defective distribution media upon
their return to SATO Corporation. SATO
Corporation will not be liable for any loss or damage
caused by delays in furnishing a Software Product or
any other performance under this Agreement. SATO
Corporation does not warrant that the functions
contained in the Software will meet your
requirements or that the operation of the Software will
be uninterrupted or error free.
11. Use, duplication or disclosure by the Government is
subject to restrictions as set forth in the relevant
guidelines of your country, such as the Rights in
Technical Data and Computer Software clause at
FAR 242.227- 7013, subdivision (b) (3) (ii) or
subparagraph (c) (1) (ii), as appropriate. Further use,
duplication or disclosure is subject to restrictions
applicable to restricted rights software as set forth in
FAR 52.227-19 (c) (2) or equivalent rules.
THE PARTIES AGREE THAT ALL OTHER WARRANTIES,
EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF
FITNESS FOR A PARTICULAR PURPOSE AND
MERCHANTABILITY ARE EXCLUDED.
SATO Corporation reserves the right to make changes
and/or improvements in the Software without notice at any
time.
You agree not to duplicate or copy the Software
except that you may make one backup copy. You
agree that any such copy shall contain the same
proprietary notices as those appearing on the
original.
5.
8.
or destroy, the printer and all copies of the Software
and documentation.
IN NO EVENT WILL SATO CORPORATION BE LIABLE
FOR LOST PROFITS, LOST DATA, BUSINESS
INTERRUPTIONS OR ANY OTHER DIRECT, INDIRECT,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OF OR INABILITY TO USE THIS
PRODUCT, EVEN IF SATO CORPORATION HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES,
OR ANY DAMAGES CAUSED BY ABUSE OR
MANIPULATION OF THE SOFTWARE. SOME STATES
DO NOT ALLOW THE EXCLUSION OR LIMITATION OF
LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL
DAMAGES, SO THE ABOVE LIMITATION MAY NOT
APPLY TO YOU.
YOU ACKNOWLEDGE THAT YOU HAVE READ THIS
AGREEMENT, UNDERSTAND IT, AND AGREE TO BE
BOUND BY ITS TERMS AND CONDITIONS. NEITHER
PARTY SHALL BE BOUND BY ANY STATEMENT NOR
REPRESENTATION NOT CONTAINED IN THIS
AGREEMENT. NO CHANGE IN THIS AGREEMENT IS
EFFECTIVE UNLESS WRITTEN AND SIGNED BY
PROPERLY AUTHORIZED REPRESENTATIVES OF
EACH PARTY. BY INSTALLING THIS SOFTWARE
PRODUCT, YOU AGREE TO ACCEPT THE TERMS
AND-CONDITIONS OF THIS AGREEMENT.
Page | 3
COPYRIGHTS
Any unauthorized reproduction of the contents of this document, in part or whole, is
strictly prohibited.
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
SATO is a registered trademark of SATO Corporation and/or its subsidiaries in
Japan, the U.S and other countries.
Microsoft and Windows are registered trademarks of Microsoft Corporation.
All other trademarks are the property of their respective owners.
SOFTW ARE UPDATING DISCLAIMER
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.
SATO Printer Interface API
Page | 4
OVERVIEW
The SATO Printer Interface 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 Interface 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
SOFTW ARE DEVELOPMENT ENVIRONMENT
•
Microsoft Visual Studio 2010 (or higher version)
•
Microsoft .NET Framework 4.0 (or higher version)
•
Visual C++ Redistributable Package for Visual Studio 2013
o
Available on Microsoft website [URL].
Please download and install the package for x86 platform [vcredist_x86.exe].
CLIENT COMPUTER
Custom application developed with SATO Printer Interface API must be distributed
with the DLL files of SATO Printer Interface API. And also 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 Interface API is available on following URL
webpage.
http://www.satoworldwide.com/software/sato-printer-interface-api.aspx
SATO Printer Interface API
Page | 5
SETUP
Execute the SATO Printer Interface API setup package and follow the guidance of
the setup wizard. By default, the SATO Printer Interface API files will be install in
below folder.
x86 environment:
C:¥Program Files¥SATO¥SATO Printer Interface API
x64 environment:
C:¥Program Files (x86)¥SATO¥SATO Printer Interface API
Copy all assembly (dlls) into project folder. Add reference both assembly into
project references.
SATO Printer Interface API
Page | 6
USING THE SATO PRINTER INTERFACE API
PRINTER COMMUNICATION FUNCTIONS
CONNECTION
Initialize the API to get list of ports, send data to printer or receive data from printer.
Syntax
Connection()
Parameters
Not Applicable
Return Values
Not Applicable
Example (C#)
using SATOPrinterInterface;
Connection SATOPrinter = new Connection();
GET LIST OF 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
printer connection. For USB, this returns connected SATO printer ports. TCPIP will
return list of SATO printer IP address, Mac address, Name and Details information.
Syntax
COM port:
GetCOMPortList()
LPT port:
GetLPTPortList()
USB port:
GetUSBPrinterList()
SATO Printer Interface API
Page | 7
TCPIP:
GetTCPIPPrinterList()
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
Example (C#)
COM port:
List<string> COMPorts = SATOPrinter.GetCOMPortList();
LPT port:
List<string> LPTPorts = SATOPrinter.GetLPTPortList();
USB port:
List<USBInfo> USBList = SATOPrinter.GetUSBPrinterList();
TCPIP:
List<TCPIPInfo> TCPIPList = SATOPrinter.GetTCPIPPrinterList();
SET INTERFACE PORT
Before send data to printer, you have to specify port or IP address of printer. Below
properties allow you to set COM, LPT or USB port or IP address and IP Port of
printer you want to communicate.
Syntax
COM port:
.COMPort
LPT port:
.LPTPort
USB port:
.USBPortID
SATO Printer Interface API
Page | 8
TCP/IP port:
.TCPIPAddress
.TCPIPPort
Parameters
Not Applicable
Return Values
Not Applicable
Example (C#)
COM port:
SATOPrinter.COMPort = “COM1”;
LPT port:
SATOPrinter.LPTPort = “LPT1”;
USB port:
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";
SET INTERFACE TYPE
After set port, you have to set interface type. Below properties allow you to set
interface type COM, LPT, LPT or TCP/IP.
Syntax
.Type
Parameters
Not Applicable
Return Values
Not Applicable
SATO Printer Interface API
Page | 9
Example (C#)
COM port:
SATOPrinter.Type = InterfaceType.COM;
LPT port:
SATOPrinter.Type = InterfaceType.LPT;
USB port:
SATOPrinter.Type = InterfaceType.USB;
TCP/IP port:
SATOPrinter.Type = InterfaceType.TCPIP;
SEND SINGLE QUERY AND RECEIVE SINGLE REPLY
Query method will send single command to printer and return received single reply
from printer. This method will connect to printer before send command and
disconnect from printer reply is received. You do not need to disconnect after you
use this method. You have to set interface port and type before you use this method.
Default timeout for each interface are (USB: 1 sec, COM: 4.2 sec, LPT: 3 sec,
TCPIP: 2.5 sec), once timeout it will throw exception with message “No Reply
received!”
Syntax
Query(byte[] data)
Parameters
Byte Array data
Return Values
Byte Array data
Example (C#)
Byte[] Printer_Reply = SATOPrinter.Query(<Byte Array SBPL Query command>);
SATO Printer Interface API
Page | 10
SEND SINGLE DATA
Send method will send single command to printer. This method will connect to
printer before send command and disconnect from printer after sent the command.
You do not need to disconnect after you use this method. You have to set interface
port and type before you use this method.
Syntax
Send(byte[] data)
Parameters
Byte Array data
Return Values
Not Applicable
Example (C#)
SATOPrinter.Send(<Byte Array SBPL command>);
ASYNCHRONOUS SEND
With AsyncSend method, you can send multiple data to printer and also receive
multiple replies from printer asynchronously. This method will connect to printer
before send first command. However this will not disconnect from printer thus, you
have to disconnect once you have completed sending data to printer and/or
receiving data from printer. You have to set interface port and type before you use
this method.
To handle reply from printer using this method, you must use event handler. You
may refer to receive data from printer using async send method section of this
document.
Syntax
AsyncSend(byte[] data)
Parameters
Byte Array data
Return Values
Not Applicable
SATO Printer Interface API
Page | 11
Example (C#)
SATOPrinter.AsyncSend(<Byte Array SBPL command>);
DISCONNECTION
After you use asynchronous send method, you must disconnect from printer.
Syntax
Disconnect()
Parameters
Not Applicable
Return Values
Not Applicable
Example (C#)
SATOPrinter.Disconnect();
RECEIVE DATA FROM PRINTER USING ASYNC SEND METHOD
To process reply data from printer while you are using asynchronous send method,
you need to use event handler. Below example in C# shows for initialize the event
Example (C#)
SATOPrinter.ByteAvailable += new
EventHandler<Connection.ByteAvailableEventArgs>(ReadMsg);
private void ReadMsg(object sender, Connection.ByteAvailableEventArgs e)
{
byte[] b = e.Data;
string temp = SATOPrinter.ByteArray2String(b);
}
SATO Printer Interface API
Page | 12
PRINTER DRIVER FUNCTIONS
INITIATE THE FUNCTIONS
Initialize the API to use the printer driver functions.
Syntax
PrinterDriver()
Parameters
Not Applicable
Return Values
Not Applicable
Example (C#)
PrinterDriver printerDriver = new PrinterDriver();
GET LIST OF INSTALLED PRINTER DRIVER
Gets list of installed printer driver on the computer. This will reply SATO printer
driver only.
Syntax
GetDriverList()
Parameters
Not Applicable
Return Values
List of DriverInfo
Example (C#)
List<DriverInfo> ListOfSATODriver = printerDriver.GetDriverList();
SATO Printer Interface API
Page | 13
GET NUMBER OF JOBS IN SPOOLER FROM PRINTER DRIVER
Gets number of jobs in printer driver spooler of specified printer driver name.
Syntax
GetSpoolerPrintJobsNumber(string DriverName)
Parameters
String of Driver Name
Return Values
Integer
Example (C#)
Int NoOfPrintJob = printerDriver.GetSpoolerPrintJobsNumber(“SATO CL412e”);
GET PORT INFORMATION FROM PRINTER DRIVER
Gets port information of specified printer driver name.
Syntax
GetIPAddressAndPortFromDriver(string DriverName)
Parameters
String of Driver Name
Return Values
List of PrinterInfo
Example (C#)
List <PrinterInfo> printerInfo =
printerDriver.GetIPAddressAndPortFromDriver(“SATO CL412e”);
SEND STRING DATA THROUGH DRIVER
Send string data to specified printer driver name.
Syntax
SendStringViaDriver(string DriverName, string Data)
Parameters
String of Driver Name
SATO Printer Interface API
Page | 14
String of data
Return Values
Bool of send result
Example (C#)
bool sentResult = printerDriver.SendStringViaDriver(“SATO CL4NX
203dpi”,<String of SPBL Command>);
SEND BYTE ARRAY DATA THROUGH DRIVER
Send byte array data to specified printer driver name.
Syntax
SendBytesViaDriver(string DriverName, byte[] Data)
Parameters
String of Driver Name
Byte Array of data
Return Values
Bool of send result
Example (C#)
bool sentResult = printerDriver.SendBytesViaDriver(“SATO CL4NX
203dpi”,<Byte array of SPBL Command>);
SATO Printer Interface API
Page | 15
CLASSES
CLASS FOR USBINFO
string Name
string PortID
CLASS FOR TCPIPINFO
string Name
string MacAddress
string IPAddress
string Details
CLASS FOR DRIVERINFO
string PrinterModel
string DriverName
string PortName
bool Online
CLASS FOR PRINTERINFO
string IPAddress
string Port
InterfaceType Type
SATO Printer Interface API
Page | 16
Extensive contact information of worldwide SATO
operations can be found on the internet at
www.satoworldwide.com
SATO Printer Interface API
Page | 17