com.starmicronics.stario
Class StarIOPort

java.lang.Object
  extended by com.starmicronics.stario.StarIOPort

public abstract class StarIOPort
extends java.lang.Object


Constructor Summary
StarIOPort()
           
 
Method Summary
abstract  StarPrinterStatus beginCheckedBlock()
          Starts a checked block to ensure that the printer successfully finished its job.
protected abstract  void closeNative()
           
static byte[] compressRasterData(int width, int height, byte[] imageData, java.lang.String portSettings)
           
abstract  StarPrinterStatus endCheckedBlock()
          Only call this after a call to
This function blocks until either the printer goes off line or the print job finished
static byte[] generateBitImageCommand(int width, int height, byte[] imageData, java.lang.String portSettings)
          Deprecated. compressRasterData(int width, int height, byte[] imageData, String portSettings)
abstract  java.util.Map<java.lang.String,java.lang.Boolean> getDipSwitchInformation()
          Get DIP switch settings of DK-AirCash
In getting DIP switch settings of DK-AirCash, specify the "DIPSW11" or "DIPSW12"
or "DIPSW13" or "DIPSW14" or "DIPSW15" or "DIPSW16" or "DIPSW17" or "DIPSW18" or "DIPSW21"
or "DIPSW22" or "DIPSW23" or "DIPSW24" or "DIPSW25" or "DIPSW26" or "DIPSW27" or "DIPSW28" to key
abstract  java.util.Map<java.lang.String,java.lang.String> getFirmwareInformation()
          Get printer model name and printer firmware version
In getting printer firmware version, specify the "FirmwareVersion" to key
In getting printer model name, specify the "ModelName" to key
static StarIOPort getPort(java.lang.String portName, java.lang.String portSettings, int ioTimeoutMillis)
          Opens a connection to either a TCP or BlueTooth StarMicronics™ printer for printing
static StarIOPort getPort(java.lang.String portName, java.lang.String portSettings, int ioTimeoutMillis, android.content.Context currentContext)
          Opens a connection to either a TCP, BlueTooth, or USB StarMicronics™ printer for printing .
 java.lang.String getPortName()
          Retrieves the port name that were used to open the port
 java.lang.String getPortSettings()
          Retrieves the port settings that were use to open the port
static java.lang.String getStarIOVersion()
          Get StarIO Version
static void InterruptOpen()
          Interrupts the opening of any bluetooth printer an immediately throws an StarIOPortException on all threads opening a bluetooth connection.
abstract  int readPort(byte[] readBuffer, int offSet, int size)
          Read data from the printer into a byte array
static void releasePort(StarIOPort port)
          Closes a connection to an open printer
abstract  StarPrinterStatus retreiveStatus()
          Gets the current status of the printer
static java.util.ArrayList<PortInfo> searchPrinter(java.lang.String target)
          Search printer on LAN or paired bluetooth device.
static java.util.ArrayList<PortInfo> searchPrinter(java.lang.String target, android.content.Context Context)
          Search printer on LAN, paired bluetooth device or USB device.
abstract  void setEndCheckedBlockTimeoutMillis(int endCheckedBlockTimeoutMillis)
          Sets the timeout time in milliseconds of endCheckedBlock method.
abstract  void writePort(byte[] writeBuffer, int offset, int size)
          Writes a byte array out to the printer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StarIOPort

public StarIOPort()
Method Detail

searchPrinter

public static java.util.ArrayList<PortInfo> searchPrinter(java.lang.String target)
                                                   throws StarIOPortException
Search printer on LAN or paired bluetooth device.

Parameters:
target - Identifies the interface type to search (ex. "TCP:", "BT:", "BT:xxx")
Returns:
List of printers that were found.
Throws:
StarIOPortException

searchPrinter

public static java.util.ArrayList<PortInfo> searchPrinter(java.lang.String target,
                                                          android.content.Context Context)
                                                   throws StarIOPortException
Search printer on LAN, paired bluetooth device or USB device.

Parameters:
target - Identifies the interface type to search (ex. "TCP:", "BT:", "USB:")
Context - The context of the android application. Only necessary for USB connections. The context is used to autoask the use for permission to use the usb port. Only asked if permission is necessary.
Returns:
List of printers that were found.
Throws:
StarIOPortException

getPort

public static StarIOPort getPort(java.lang.String portName,
                                 java.lang.String portSettings,
                                 int ioTimeoutMillis)
                          throws StarIOPortException
Opens a connection to either a TCP or BlueTooth StarMicronics™ printer for printing

Parameters:
PortName - Identifies the printer to use
Ethernet and WiFi: Usage - TCP:IPAddress (eg, TCP:192.168.1.23)
BlueTooth: Usage - BT: (finds and uses the first star BlueTooth printer paired with your device)
BT:DeviceName (eg, BT:SMS200)
BT:<MacAddress> (eg, BT:00:15:0E:45:00:12)

PortSettings - The settings for the port
Ethernet Settings: portable;escpos - Using for a ESC/POS mode portable printer
a - Set socket to keep alive
n - Use TCP no delay
Examples: "portable;escpos;a;n", "portable;escpos;a", ";a", ";n", ""
BlueTooth Settings: portable - Using for a portable printer
l - Automatically retry connection process until timeout occurs
f - Automatically flush after data is written to stream
u - use SPP (unsecure) for Bluetooth connection. (Only for android api level 10 or later)
p - use Pin code security for Bluetooth connection. (Only for android api level 10 or later)
d[timeout value] - Perform data cancel function. When the printer during the specified time does not receive data.
Using for POSPrinter TSP650II Bluetooth model and Frimware Version 1.3 or later
The timeout range is 0-255.[unit: second] If you specify 0, this setting is disabled.
Example: ";d127" - Perform data cancel function when it does not receive data 127 seconds during printing.
Examples: "portable;l", "portable", ";p;l", ";f", ";d127"
ioTimeoutMillis - The time out in milliseconds used when writing or reading from the port
Returns:
StarIOPort The port that is used to write and read data to the printer
Throws:
StarIOPortException - If for some reason communication with the printer can't be established, if the error "device discovery failed" repeatedly shows up try pairing again with the priner

getPort

public static StarIOPort getPort(java.lang.String portName,
                                 java.lang.String portSettings,
                                 int ioTimeoutMillis,
                                 android.content.Context currentContext)
                          throws StarIOPortException
Opens a connection to either a TCP, BlueTooth, or USB StarMicronics™ printer for printing . This function is only avaible to andorid 3.1 and up.

Parameters:
PortName - Identifies the printer to use
Ethernet and WiFi: Usage - TCP:IPAddress (eg, TCP:192.168.1.23)
BlueTooth: Usage - BT: (finds and uses the first star BlueTooth printer paired with your device)
BT:DeviceName (eg, BT:SMS200)
BT:<MacAddress> (eg, BT:00:15:0E:45:00:12)
By using StarIOPort3.1.jar instead of the standard StarIOPort.jar usb connections become available. USB connection should also only be opened on a thread or else it will prevent the user from using the usb permission request screen
USB Connections: Usage - USB:<Printer Number> (eg, USB:1) - Use the first USB star printer (currently StarIO only supports one usb printer at a time)
USB: (eg, USB:) - Find and use the first USB star printer
USBVEN: (eg, USBVEN:) - Find and use the first USB vendor class star printer
USBVEN: (eg, USBVEN:) - Find and use the first USB printer class star printer

PortSettings - The settings for the port
Ethernet Settings: portable;escpos - Using for a ESC/POS mode portable printer
a - Set socket to keep alive
n - Use TCP no delay
Examples: "portable;escpos;a;n", "portable;escpos;a", "a", "n", ""
BlueTooth Settings: portable - Using a portable printer (this is required for all BlueTooth printers)
f - Automatically flush after data is written to stream
u - use unsecure bluetooth connection. (Only for android api level 10 and up)
Examples: "portable;u;f", "portable"
ioTimeoutMillis - The time out in milliseconds used when writing or reading from the port
Context - The context of the android aplication. Only nessesary for USB connections. The context is used to autoask the use for permission to use the usb port. Only asked if permission is nessasary.
Returns:
StarIOPort The port that is used to write and read data to the printer
Throws:
StarIOPortException - If for some reason communication with the printer can't be established, if the error "device discovery failed" repeatedly shows up try repairing with the printer

InterruptOpen

public static void InterruptOpen()
                          throws StarIOPortException
Interrupts the opening of any bluetooth printer an immediately throws an StarIOPortException on all threads opening a bluetooth connection. Already open connections won't be affected.

Throws:
StarIOPortException

releasePort

public static void releasePort(StarIOPort port)
                        throws StarIOPortException
Closes a connection to an open printer

Parameters:
port - Opened StarIOPort that will be closed
Throws:
StarIOPortException - should never happen

generateBitImageCommand

@Deprecated
public static byte[] generateBitImageCommand(int width,
                                                        int height,
                                                        byte[] imageData,
                                                        java.lang.String portSettings)
                                      throws StarIOPortException
Deprecated. compressRasterData(int width, int height, byte[] imageData, String portSettings)

Generate mobile printer command for printing bitmap image

Parameters:
width - The width of the bitmap data. - width > 0
height - The height of the bitmap data. - height > 0
imageData - The bitmap data of array binary
PortSettings - The settings for the port
Ethernet Settings: portable - Using a portable printer
a - Set socket to keep alive
n - Use TCP no delay
Examples: "portable;a;n", "portable;a", "a", "n", ""
BlueTooth Settings: portable - Using a portable printer (this is required for all BlueTooth printers)
f - Automatically flush after data is written to stream
u - use unsecure bluetooth connection. (Only for android api level 10 and up)
Examples: "portable;u;f", "portable"
Returns:
The Array of binary which is print command.
Throws:
StarIOPortException - If specified width, height, imageData is invalid, show error message.

compressRasterData

public static byte[] compressRasterData(int width,
                                        int height,
                                        byte[] imageData,
                                        java.lang.String portSettings)
                                 throws StarIOPortException
Throws:
StarIOPortException

getPortName

public java.lang.String getPortName()
Retrieves the port name that were used to open the port

Returns:
The port name

getPortSettings

public java.lang.String getPortSettings()
Retrieves the port settings that were use to open the port

Returns:
The port settings

writePort

public abstract void writePort(byte[] writeBuffer,
                               int offset,
                               int size)
                        throws StarIOPortException
Writes a byte array out to the printer

Parameters:
writeBuffer - The array containing the data to be written
offset - The start offset for writing data
size - The amount of data that should be written to the printer
Throws:
StarIOPortException - Thrown if the data can reach the printer

readPort

public abstract int readPort(byte[] readBuffer,
                             int offSet,
                             int size)
                      throws StarIOPortException
Read data from the printer into a byte array

Parameters:
readBuffer - The byte array to store the data read from the printer
offSet - The offset in the readbuffer at which the data is written
size - The maximum number of bytes to read
Returns:
The number of bytes actually read from the printer
Throws:
StarIOPortException - Thrown if data cannot be read from the printer

closeNative

protected abstract void closeNative()
                             throws StarIOPortException
Throws:
StarIOPortException

retreiveStatus

public abstract StarPrinterStatus retreiveStatus()
                                          throws StarIOPortException
Gets the current status of the printer

Returns:
A StarPrinterStatus object containing all the information about the printers status
Throws:
StarIOPortException - Thown if the connection to the printer is lost

beginCheckedBlock

public abstract StarPrinterStatus beginCheckedBlock()
                                             throws StarIOPortException
Starts a checked block to ensure that the printer successfully finished its job. Call when finished printing

Returns:
A StarPrinterStatus object containing all the information about the printers status
A print job should not be started unless the printer is online
Throws:
StarIOPortException - Thrown if connection to the printer is lost

endCheckedBlock

public abstract StarPrinterStatus endCheckedBlock()
                                           throws StarIOPortException
Only call this after a call to
This function blocks until either the printer goes off line or the print job finished

Returns:
A StarPrinterStatus object containing all the information about the printers status
The the status object return indicates that the printer is offline than the print job failed
Throws:
StarIOPortException - Thrown if connection to the printer is lost

getFirmwareInformation

public abstract java.util.Map<java.lang.String,java.lang.String> getFirmwareInformation()
                                                                                 throws StarIOPortException
Get printer model name and printer firmware version
In getting printer firmware version, specify the "FirmwareVersion" to key
In getting printer model name, specify the "ModelName" to key

Returns:
A Map object containing printer model name and printer firmware version.
Throws:
StarIOPortException

getDipSwitchInformation

public abstract java.util.Map<java.lang.String,java.lang.Boolean> getDipSwitchInformation()
                                                                                   throws StarIOPortException
Get DIP switch settings of DK-AirCash
In getting DIP switch settings of DK-AirCash, specify the "DIPSW11" or "DIPSW12"
or "DIPSW13" or "DIPSW14" or "DIPSW15" or "DIPSW16" or "DIPSW17" or "DIPSW18" or "DIPSW21"
or "DIPSW22" or "DIPSW23" or "DIPSW24" or "DIPSW25" or "DIPSW26" or "DIPSW27" or "DIPSW28" to key

Returns:
A Map object containing DIP switch settings of DK-AirCash.
Throws:
StarIOPortException

getStarIOVersion

public static java.lang.String getStarIOVersion()
Get StarIO Version

Returns:
StarIO version.

setEndCheckedBlockTimeoutMillis

public abstract void setEndCheckedBlockTimeoutMillis(int endCheckedBlockTimeoutMillis)
Sets the timeout time in milliseconds of endCheckedBlock method.