README StarIO PortablePrinter Android SDK
README StarIO PortablePrinter Android SDK
Supported Versions
StarIOPort3.1.jar
Android OS 2.1
StarIOPort.jar
Tools
Needed:
JDK 6
Eclipse
Android SDK Manager
ADT (Android Development Tool) Plugin for Eclipse
USB Windows Driver by Android Device Manufacturer
StarIO Android SDK
Table of Contents
v About this Manual
v Star Portable Printer Compatibility Chart
v Connecting a Star Portable Printer to an Android Device
o Bluetooth
o Network Interface
v Configuring an Android Device for Development
v How to Import and Run the Android SDK
v Using the SDK with Star Micronics Portable Printers
o Wireless LAN
o Bluetooth Port Discovery
o Bluetooth Manual Port Entry
v
v Overview of how this Android SDK is designed
v StarIO - (StarIOPort3.1.jar)
o Selecting a StarIO library
o How to include StarIO into your project
o StarIO Methods Quick Overview
v StarIO Android SDK Functionality
o Port Discovery
o Help
o Get Status
o Sample Receipts
o Begin / End Checked Printing
o 1D Barcodes
o 2D Barcodes
o Text Formatting
o Japanese Kanji Text Formatting
o Raster Graphics Printing
o Image Printing
o MSR
v Tips for software application development when using StarIO
v Additional Resources
o Star Micronics Developers Network
o ASCII Table
v SDK Version History
Key Legend:
Warning
Note
CAUTION:
Status
Sample Receipts
2D Barcodes
Text Formatting
Sample Images
MSR
SM-S200
Bluetooth
(*1)
(*2)
(*2)
SM-S210i
Bluetooth
Bluetooth
Bluetooth
(*1)
(*2)
(*2)
(*1)
(*2)
(*2)
SM-S220i
(Excluding Jp
model)
SM-T300
WLAN
Raster Graphics
Interface
Model
Port Discovery
Star Printer
SM-S300
Bluetooth
(*1)
(*2)
(*2)
SM-T300i
Bluetooth
SM-S400
Bluetooth
(*1)
(*2)
(*2)
SM-T400i
Bluetooth
5. Enter the PIN number. The factory default for standard Star Portable Printers is
1234.
5
6. Older Android Operating Systems, such as V2.2 in the above screenshot, display the
message Paired but not connected. This can be neglected as connection is
established at the time of printing.
Wireless LAN
1. Assign an IP Address to the Star Printer and connect it to the network. Standard Star
Printers do not ship with an IP Address pre-assigned; this can set by using the WLAN
Setup Utility for Mobile Printers available on Stars website.
2. Tap Settings.
2. Tap Security.
It is assumed Eclipse has already been configured to support Android development. Should you
need assistance with this, refer to Stars Android Setup Guide in the documentation folder of
this SDK package.
This section will explain:
1. How to import the Android SDK project into Eclipse.
2. Enabling debug mode in Eclipse.
3. Running the project.
How to import the Android SDK project into Eclipse:
1. Execute Eclipse.
10
4. Browse to the location where the Star SDK is saved. Click Finish.
11
1. Click AndroidManifest.xml.
12
1. Choose PrinterTypeActivity.java.
2. Click the green arrow.
Tip: The above error occurs if you attempt to reinstall the .apk from a different host.
To remedy it, delete the application on your Android device and rerun the app.
13
Port Name
BT:
BT:Device Name
Port Settings
mini
mini
mini
TCP:IP Address
mini
1. Tap Star Mobile Printers. This section contains all Mobile Printer samples.
14
15
1. Tap Search to find all connected Star Printers. Alternatively, the device name can be
manually typed into the PortName field. See here for details.
16
There are three types of port details that can be used for Star Bluetooth Printers:
1. BT: If only one Star Bluetooth Printer is connected, using BT: with no parameters
will automatically communicate to the only printer connected.
2. BT:<DeviceName> Add the full device name after BT: without brackets. This is
case sensitive so ensure it matches exactly.
3. BT:<MAC Address> Add the printers MAC Address after BT: without brackets.
17
18
StarIO (StarIOPort3.1.jar)
The file StarIOPort3.1.jar is a library that you can include into your Java projects to expose
StarIO methods.
Selecting a StarIO Library:
The StarIO SDK contains two library files. Use the one which corresponds to the Android OS
Version your application is being developed for.
Supported Versions
Android OS 2.2 and Higher
Android OS 2.1
import com.starmicronics.stario.StarIOPort;
import com.starmicronics.stario.StarIOPortException;
import com.starmicronics.stario.StarPrinterStatus;
19
20
Android OS V2.1:
Include the legacy library: StarIOPort.jar
Upon including this library, the source code of the StarIO SDK application must be modified.
21
Property
StarIO Port class includes 3 properties; portName(String),portSettings(String),and timeout(int).
These 3 variables will be read only if accessed directly. To assign them use
getPort(portName,portSettings,timeout); which will allow you to pass in
variables to this methods which then assigns the 3 class variables with values.
portName is what you will be using to specify the port of communication to the printer.
Ex. TCP:192.168.1.2 / BT:DeviceName
timeout is a
22
GetPort is what you will be using to open the port to the printer. Using one of the valid
inputs for portName and portSettings as mentioned previously before this, you can pass your
connection string into the StarIO class so that it will correctly set its private variables.
//The following would be an actual usage of getPort:
StarIOPort port = null;
try
{
port = StarIOPort.getPort(portName, portSettings, 10000);
}
catch (StarIOPortException e)
{
//There was an error opening the port
}
StarIOPort is a part of StarIO and this will allow you to create a port handle. The
above example shows the port being created and set to null then being assigned the actual
port hook on the following line that contains getPort.
Always use a try, catch when using getPort. If the port cannot be opened
because of connection problems, your program will crash unless you use a
try, catch like the above example.
When Sleep Mode is enabled, it is necessary to execute getPort() and
releasePort() before the printer physically enters Sleep Mode
23
searchPrinter gets Bluetooth devices which connect with Android terminal, as a list.
When set BT: as a Argument value, return all Bluetooth devices, set BT: with specifc
string returns Bluetooth deivces which name from specific strings.
PortInfo class of return value includes, PortName, MAC address for Bluetooth devices and
you can get them by String getPortName(), and String getMacAddress() method.).
You can use PortName as a Argument value of getPort().
24
This sample shows, get connected Bluetooth devices which name start from Star
and output to log.
searchPrinter detects not only Star portable printers but also any
Bluetooth devices. To use original name, just search specific pritners.
25
This method reads data from the device. Only use this if you really need to
read raw bytes from the printer.
Do not use this method to read raw status.
Use retreiveStatus for getting status.
Parameters:
readBuffer
offset
size
Returns:
The number of bytes that were actually read. Under some interface types, this
function will succeed even when no data was read in. Your application should
call this function a limited number of times until the expected data has been
read in or until an application determined retry threshold has been reached.
Throws:
StarIOPortException
26
Parameters:
port StarIOPort type representing a previously initialized port.
When do not send the data, release (close) ports.
Leaving a port open will cause future calls to open the port to fail.
27
This method writes data to the device. Use this to print to the printer, send
commands, etc. The following is an example of how to use this method:
Please keep in mind this is the simplest way to send data to the printer.
The SDK has code in printToPrinter that is more complex than this but that code block will show you
how to verify data transmission to the printer whereas this code is just dumping it:
//Set a byte array to send to the printer
//command = { A, B, C, D, Feed 3mm, Full Cut}
Byte[] command = new Byte[] { 0x41, 0x42, 0x43, 0x44, 0x1B, 0x7A, 0x00, 0x1B, 0x64, 0x02 };
try
{
port.writePort(command, 0, command.length);
}
catch (StarIOPortException e)
{
//There was an error writing to the port
}
Parameters:
writeBuffer
offset
size
Returns:
The number of bytes that were actually written. Under some interface types, this
function will succeed even when no data was written out. Your application should call
this function a limited number of times until all the data has been written out or until an
application determined retry threshold has been reached.
Throws:
StarIOPortException
28
This method retrieves detailed status from the printer with StarIO.
Returns:
StarPrinterStatus structure giving the current device status
Throws:
StarIOPortException
This method uses a class structure that is included with StarIO called StarPrinterStatus
This structure gives the printer's status in both boolean and binary form.
Create the StarPrinterStatus object in your project by doing the following:
StarPrinterStatus status = port.retreiveStatus();
if (printerStatus.offline == false)
{
if (status.blackMarkError == true) {
//There was a black mark error
}
if (status.compulsionSwitch == true) {
//Cash drawer is open
}
else {
//Cash drawer is closed
}
}
else {
//If true, then the printer is offline.
}
29
throws StarIOPortException
This method is used in combination with endCheckedBlock and checks the completion of
printing. To check if the whole data is completely printed, you need to run this method just
before sending print data and endCheckedBlock just after sending print data.
Returns:
StarPrinterStatus structure giving the current device status
Throws:
StarIOPortException
endCheckedBlock
public StarPrinterStatus endCheckdBlock ()
throws StarIOPortException
This method is used in combination with beginCheckedBlock and checks the completion of
printing. If an error has occurred while printing, can get the return value which is the current
device status when this method is executed. You must run beginCheckedBlock just before
sending print data.
Returns:
StarPrinterStatus structure giving the current device status
Throws:
StarIOPortException
try
{
}
catch (StarIOPortException e)
{
Log.d("StarIOSample", "An timeout error has occurred during printing.");
}
finally
{
if (port != null)
{
try
{
StarIOPort.releasePort(port);
}
catch (StarIOPortException e) {}
}
}
31
generateBitImageCommand
public byte[] generateBitImageCommand (int width, int height,
byte[] imageData, String portSettings)
throws StarIOPortException
height
imageData
portSettings
Port settings
mini is specified for a portable printer
Returns:
Success: Print command
Failure: null
Throws:
StarIOPortException
32
Contents
Type
Detail
blackMarkError
boolean
compulsionSwitch
Compulsion SW
boolean
coverOpen
Cover Status
boolean
cutterError
Auto-cutter Error
boolean
etbAvailable
boolean
etbCounter
ETB Counter
int
headThermistorError
boolean
offline
ONLINE/OFFLINE
Status
boolean
overTemp
boolean
presenterPaperJamError
boolean
presenterState
Presenter Paper
Position
int
raw
byte[63]
rawLength
raw length
int
raw length
receiptPaperEmpty
Paper end
boolean
receiptPaperNearEmptyInner
boolean
receiveBufferOverflow
Receive Buffer
Overflow
boolean
unrecoverableError
Non-recoverable Error
boolean
voltageError
boolean
33
SMS200
SMS300
SMS400
SM-S210i
(Jp model only)
SM-S220i
( Excluding
Jp model )
SMT300i
SMT400i
raw
rawLength
receiptPaperEmpty
Member name
blackMarkError
compulsionSwitch
coverOpen
cutterError
etbAvailable
etbCounter
headThermistorError
offline
overTemp
presenterPaperJamError
presenterState
receiptPaperNearEmptyInner
receiveBufferOverflow
unrecoverableError
voltageError
34
35
36
Automatically detects which Star Micronics Bluetooth Printers are paired. Tap the printer to
connect to it. This feature is documented in greater detail here. Wireless portable printers
currently do not support this feature.
Help
Displays rules for manually entering the printers port data into the PortName field.
Manually entering port data is unnecessary if Port Discovery is used.
37
StarPrinterStatus
public boolean retreiveStatus()
offline
other
Sample Receipts
Prints a premade sample receipt in the chosen command type. Sample Receipt outputs a
receipt in English, while JP Sample Receipt outputs one in Japanese.
Select the samples width and tap OK to print it. This part of the source code is heavily
commented to demonstrate how receipts can be fully customized.
38
39
0 n 255
1n8
Print Barcode
GS k m n d1...dn NUL m = Barcode Type
n = Number of data
d1dn = Barcode Data
40
Select QR Code
GS Z n
n = 2 (QR Code)
Print QR Code
ESC Z m a k nL nH d1dn
m = Version of the symbol
a = Correction Level
k = Model Size
k = 1~8
41
Select PDF417
GS Z n
n = 0 (PDF417)
1n8
Print PDF417
ESC Z m a k nL nH d1dn
m = Column Number
1 m 30
a = Correction Level
0n8
k = Horizontal/Vertical Ratios
2k5
42
43
Underline
ESC n
Emphasized
ESC E n
1 = On
0 = Off [Default]
1 = On
0 = Off [Default]
1 = On
0 = Off [Default]
0n8
Left Margin
GS L nL nH
0 nL 255
0 nH 255
0 = Left [Default]
1 = Center
Alignment
ESC a n
44
2 = Right
This functionality is the same as that of Text Formatting, except Japanese Kanji is supported.
45
Emphasized
ESC E n
1 = On
0 = Off [Default]
1 = On
0 = Off [Default]
1 = On
0 = Off [Default]
0n8
Left Margin
GS L nL nH
0 nL 255
0 nH 255
0 = Left [Default]
1 = Center
Alignment
ESC a n
46
2 = Right
Raster Mode converts all print data into image data and then outputs it to the printer. This
enables Star Printers to print at high speeds, regardless of outputting receipts with only text or
text and logos/coupons. As there are many options on how to customize output in Raster Mode,
refer to the programming manual for a listing of all Raster commands. These commands are also
conveniently listed right on the Android device by tapping the Help button on the screen.
Note: If send large amounts of raster data command, refer to the following in order to prevent "data
defective". Detail refer to the "printBitmap" method in the "MiniPrinterFunctions.java".
[Printer Device Firmware version 2.4 later]
Use beginCheckedBlock / endCheckBlock method before / after sending data by writePort method.
[Printer Device Firmware version 2.3 earlier]
For confirming the end of printing, send query commands after writePort data.
47
Use the dropdown box to select one of four different sample images to print via Raster Graphics
and choose the desired paper width.
Raster Mode converts all print data into image data and then outputs it to the printer. This
enables Star Printers to print at high speeds, regardless of outputting receipts with only text or
text and logos/coupons. As there are many options on how to customize output in Raster Mode,
refer to the programming manual for a listing of all Raster commands. These commands are also
conveniently listed right on the Android device by tapping the Help button on the screen.
Note: If send large amounts of raster data command, refer to the following in order to prevent "data
defective". Detail refer to the "printBitmapImage" method in the "MiniPrinterFunctions.java".
48
49
50
Additional Resources
Please get the programmers manual for Star Portable Printers from the link below.
Star Micronics Developers Network
Browse Star Micronics FAQs, ask a question, look up information, etc.
The Developers Network gets you access to:
51
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
TAB
LF
VT
FF
CR
SO
SI
40
41
42
43
44
45
46
47
48
49
4A
4B
4C
4D
4E
4F
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D
1E
1F
DLE
DC1
DC2
DC3
DC4
NAK
SYN
ETB
CAN
EM
SUB
ESC
FS
GS
RS
US
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
5D
5E
5F
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
20 (space)
21
!
22
"
23
#
24
$
25
%
26
&
27
'
28
(
29
)
2A
*
2B
+
2C
,
2D
2E
.
2F
/
60
61
62
63
64
65
66
67
68
69
6A
6B
6C
6D
6E
6F
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
30
31
32
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
7D
7E
7F
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
SDK Package
Version
Jul. 3 2013
3.7.0
Feb. 25 2013
3.4.0
Jan. 18 2013
3.3.0
- Added SM-S210i
- Updated Raster Graphical Text Printing,
- Updated Begin / End Checked Block method
Nov. 30 2012
3.2.0
Jul. 27 2012
3.1.0
May. 31 2012
2.4.0
Mar. 15 2012
2.3.0 Beta
Jan. 18 2012
2.2.0 Beta
Jan. 12 2012
2.1.0
Oct. 14 2011
2.0.0
Jun. 03 2011
1.0.0
- Initial Release
53
Update