Printer

com.rscja.deviceapi

## Class Printer

- java.lang.Object
- - com.rscja.deviceapi.Printer

-     public class Printer
      extends java.lang.Object

  Author:
    Administrator

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Printer.BarcodeType` 1D条码类型
    `static class` | `Printer.PrinterStatus`
    `static interface` | `Printer.PrinterStatusCallBack`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearCache()` 立即清空打印缓存,清空打印机接收缓冲区和打印缓冲区 Clear up printing cache, clear printer receive zone and buffer zone
    `boolean` | `free()` 关闭打印机模块 Switch off printer module
    `static Printer` | `getInstance()` 获取打印机模块操作实例 Acquire printer module operation Instance
    `boolean` | `init()` 打开打印机模块 Switch on printer module
    `boolean` | `isPowerOn()` 判断设备是否上电 Judge the device is powered on or not.
    `void` | `print(Bitmap bitmap)` 打印图片 print picture
    `void` | `print(Bitmap bitmap, int interval)` 打印图片 print picture
    `void` | `print(Bitmap bitmap, int mode, int interval)` 打印图片 print pciture
    `void` | `print(byte[] content)` 打印字符 print character
    `void` | `print(java.lang.String content)` 打印字符 printe character
    `void` | `print(java.lang.String barcodeData, Printer.BarcodeType barcodeType)` 打印条码 print barcode
    `void` | `print(java.lang.String content, java.lang.String charsetName)` 打印字符 print character
    `int` | `receiveData(byte[] outData)` 接收串口数据 receive serial port data
    `void` | `restoreDefault()` 参数还原默认值 parameter reset to default
    `int` | `sendAndReceiveData(byte[] sendData, byte[] outData)` 收发数据 sent/received data
    `int` | `sendData(byte[] sendData)` 发送数据到串口 send data to serial port
    `void` | `setBarcodeHeight(int height)` 设置一维条码的高度 Setup 1D barcode height
    `void` | `setBarcodeHRI(int position)` 设置一维条码可读字符（HRI）打印位置 setup 1D barcode readable character (HRI) print position
    `void` | `setBarcodeWidth(int width)` 设置一维条码的宽度 Setup 1D barcode width
    `void` | `setFeedRow(int n)` 打印并进纸 n行 print and paper infeed n
    `void` | `setPrintCharacterStyle(boolean italic, boolean frame, boolean bold, boolean doubleWidth, boolean doubleHigh, boolean white, boolean underline)` 设置字体样式 set font style
    `void` | `setPrinterStatusCallBack(Printer.PrinterStatusCallBack callBack)` 设置接收打印机状态的回调 set call back of printer received status
    `void` | `setPrinterStatusCallBackEnable(boolean b)` 设置是否接收打印机状态回调消息 Setup receive printer status return message or not
    `void` | `setPrintGrayLevel(int gray)` 设置打印 灰度 setup print grey level
    `void` | `setPrintLeftMargin(int margin)` 设置左边距 Setup left margin
    `void` | `setPrintRightMargin(int margin)` 设置左边距 Setup right margin
    `void` | `setPrintRowSpacing(int spacing)` 设置行间距(若设定的行间距小于一行中的最大字符高度，那么该行行间距等于最大字符高度) Setup line spacing (if the set value is less than max.charater height, then the line spacing equals to max.character height)
    `void` | `setPrintSpeed(int speed)` 设置打印速度 setup print velocity

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInstance

          public static Printer getInstance()
                                     throws ConfigurationException

      获取打印机模块操作实例
      Acquire printer module operation Instance
      Returns:
        打印机模块操作实例
        printer module operation Instance
      Throws:
        `ConfigurationException`

    - #### setPrinterStatusCallBackEnable

          public void setPrinterStatusCallBackEnable(boolean b)

      设置是否接收打印机状态回调消息
      Setup receive printer status return message or not
      Parameters:
        `b` - true:表示接收打印机回调消息，false:表示不接收回调消息,默认是true
        ture: means receive return infor of printer, false: means donot receive return infor,default is ture.

    - #### receiveData

          public int receiveData(byte[] outData)

      接收串口数据
      receive serial port data
      Parameters:
        `outData` - 接收到的数据
        outData received data
      Returns:
        返回接收数据的长度
        length of returned data

    - #### sendData

          public int sendData(byte[] sendData)

      发送数据到串口
      send data to serial port
      Parameters:
        `sendData` - 发送的数据
        send data
      Returns:
        返回发送数据的长度
        length of return sent data

    - #### sendAndReceiveData

          public int sendAndReceiveData(byte[] sendData,
                                        byte[] outData)

      收发数据
      sent/received data
      Parameters:
        `sendData` - 发送的数据
        sent data
        `outData` - 接收的数据
        received data
      Returns:
        返回接收的数据长度(-1表示发送失败)
        returned data length(-1 means send failed)

    - #### setPrinterStatusCallBack

          public void setPrinterStatusCallBack(Printer.PrinterStatusCallBack callBack)

      设置接收打印机状态的回调
      set call back of printer received status
      Parameters:
        `callBack` -

    - #### init

          public boolean init()

      打开打印机模块
      Switch on printer module
      Returns:
        成功true，失败false

    - #### free

          public boolean free()

      关闭打印机模块
      Switch off printer module
      Returns:
        成功true，失败false
        true means success, false means failed

    - #### print

          public void print(byte[] content)

      打印字符
      print character
      Parameters:
        `content` - 打印的内容

    - #### print

          public void print(java.lang.String content)

      打印字符
      printe character
      Parameters:
        `content` - 打印的内容
        print content

    - #### print

          public void print(java.lang.String content,
                            java.lang.String charsetName)

      打印字符
      print character
      Parameters:
        `content` - 打印的内容
        print content
        `charsetName` - 字符编码格式
        character coding format

    - #### print

          public void print(Bitmap bitmap,
                            int mode,
                            int interval)

      打印图片
      print pciture
      Parameters:
        `bitmap` - 要打印的图片
        picture for printing
        `mode(0,1,32,33)` - 点图格式:
        picture format:
        模式 水平比例 垂直比例
        format horizontal scale vertical scale
        0: 8 点单密度 ×2 ×3
        0: 8 point single density ×2 ×3
        1: 8 点双密度 ×1 ×3
        1: 8 point dual density ×1 ×3
        32:24 点单密度 ×2 ×1
        32:24 point single density ×2 ×1
        33:24 点双密度 ×1 ×1
        33:24 point dual density ×1 ×1

    - #### print

          public void print(Bitmap bitmap,
                            int interval)

      打印图片
      print picture
      Parameters:
        `bitmap` - 图片数据
        bitmap picture data
        `interval` - 发送每行数据的时间间隔
        Time interval for sending per row of data

    - #### print

          public void print(Bitmap bitmap)

      打印图片
      print picture
      Parameters:
        `bitmap` - 图片数据
        bitmap picture data

    - #### print

          public void print(java.lang.String barcodeData,
                            Printer.BarcodeType barcodeType)
                     throws PrinterBarcodeInvalidException

      打印条码
      print barcode
      Parameters:
        `barcodeData` - 条码数据
        barcodeData
        `barcodeType` - 条码类型
        barcodeType
      Throws:
        `PrinterBarcodeInvalidException`

    - #### setFeedRow

          public void setFeedRow(int n)

      打印并进纸 n行
      print and paper infeed n
      Parameters:
        `n(0-255)` -

    - #### setPrintRowSpacing

          public void setPrintRowSpacing(int spacing)

      设置行间距(若设定的行间距小于一行中的最大字符高度，那么该行行间距等于最大字符高度)
      Setup line spacing (if the set value is less than max.charater height, then the line spacing equals to max.character height)
      Parameters:
        `spacing` - (0 ≤ spacing ≤ 255), 默认值33
        spacing (0≤ spacing ≤ 255), default 33

    - #### setPrintLeftMargin

          public void setPrintLeftMargin(int margin)

      设置左边距
      Setup left margin
      Parameters:
        `margin` - (0 ≤ left margin ≤ 47，且 0 ≤ （左边距 + 右边距） ≤ 47), 默认值0
        margin (0 ≤ left margin ≤ 47,0 ≤ （left margin + right margin, ≤ 47),default 0.

    - #### setPrintRightMargin

          public void setPrintRightMargin(int margin)

      设置左边距
      Setup right margin
      Parameters:
        `margin` - (0 ≤ left margin ≤ 47，且 0 ≤ （左边距 + 右边距） ≤ 47), 默认值0
        margin (0 ≤ left margin ≤ 47,0 ≤ （left margin + right margin, ≤ 47),default 0.

    - #### setPrintCharacterStyle

          public void setPrintCharacterStyle(boolean italic,
                                             boolean frame,
                                             boolean bold,
                                             boolean doubleWidth,
                                             boolean doubleHigh,
                                             boolean white,
                                             boolean underline)

      设置字体样式
      set font style
      Parameters:
        `italic` - 斜体
        italic
        `frame` - 边框
        frame
        `bold` - 加粗
        bold
        `doubleWidth` - 倍宽
        doubleWidth
        `doubleHigh` - 倍高
        douleHigh
        `white` - 反白
        white
        `underline` - 下划线
        underline

    - #### setPrintSpeed

          public void setPrintSpeed(int speed)

      设置打印速度
      setup print velocity
      Parameters:
        `speed` - 0:低速,1:中速,2:高速
        speed 0:low,1:medium,2:high
        备注：默认是1
        comment: default is 1

    - #### setPrintGrayLevel

          public void setPrintGrayLevel(int gray)

      设置打印 灰度
      setup print grey level
      Parameters:
        `gray` - 1-8
        gray 1-8
        备注：默认是4
        comment: default is 4

    - #### restoreDefault

          public void restoreDefault()

      参数还原默认值
      parameter reset to default

    - #### clearCache

          public void clearCache()

      立即清空打印缓存,清空打印机接收缓冲区和打印缓冲区
      Clear up printing cache, clear printer receive zone and buffer zone

    - #### setBarcodeHeight

          public void setBarcodeHeight(int height)

      设置一维条码的高度
      Setup 1D barcode height
      Parameters:
        `height` - 高度(1-255),默认值:64
        height(1-255), default:64

    - #### setBarcodeWidth

          public void setBarcodeWidth(int width)

      设置一维条码的宽度
      Setup 1D barcode width
      Parameters:
        `width` - 宽度(1-6),默认值:2
        width(1-6), default:2

    - #### setBarcodeHRI

          public void setBarcodeHRI(int position)

      设置一维条码可读字符（HRI）打印位置
      setup 1D barcode readable character (HRI) print position
      Parameters:
        `position(0-3)` - 默认是0; [0:不打印, 1: 条码的上方 , 2:条码的下方, 3:条码的上方和下方]
        position(0-3) default is 0; [0:not print, 1:barcode up side 2: barcode down side, 3: barcode up and down]

    - #### isPowerOn

          public boolean isPowerOn()

      判断设备是否上电
      Judge the device is powered on or not.
      Returns: