Class BluetoothPrinter

  • Direct Known Subclasses:
    CitizenPrinter, MPTPrinter

    public class BluetoothPrinter
    extends java.lang.Object
    Used as interface to printers that uses Bluetooth to communicate with the device. See the CitizenPrinter javadocs if you plan to use one.

    Note: during tests, we found that some printers require to fill their buffer to start printing. So, if you have problems printing, try the following code after you instantiate this class:

     cp = new CitizenPrinter(); // or new BluetoothPrinter();
     cp.write(new byte[2048]); // fill the buffer
     cp.newLine();
     ...
     
    • Constructor Summary

      Constructors 
      Constructor Description
      BluetoothPrinter()
      Creates a new BluetoothPrinter instance, using PortConnector.BLUETOOTH port at 57600 baud rate.
      BluetoothPrinter​(Stream con)
      Creates a new BluetoothPrinter instance, using the given PortConnector as bridge to the printer.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void close()  
      void escape​(int command)
      Sends an escape command to the printer.
      void escape​(int command, int value1)
      Sends an escape command to the printer.
      void escape​(int command, int value1, int value2)
      Sends an escape command to the printer.
      void gs​(int command, int value1)
      Sends a GS command to the printer.
      void gs​(int command, int value1, int value2)
      Sends an escape command to the printer.
      void newLine()
      Sends a new line to the printer.
      void newLine​(int count)
      Sends a number of new lines to the printer.
      void print​(java.lang.String str)
      Prints the given String.
      void print​(MonoImage img)
      Prints the given MonoImage.
      void print​(MonoImage img, byte imageMode)
      Deprecated.
      Use the other print method without imageMode parameter.
      void write​(byte[] data)
      Sends the given raw data to the printer.
      void write​(byte[] data, int ofs, int len)
      Sends the given raw data to the printer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BluetoothPrinter

        public BluetoothPrinter()
                         throws IOException
        Creates a new BluetoothPrinter instance, using PortConnector.BLUETOOTH port at 57600 baud rate.
        Throws:
        IOException
      • BluetoothPrinter

        public BluetoothPrinter​(Stream con)
                         throws IOException
        Creates a new BluetoothPrinter instance, using the given PortConnector as bridge to the printer. Note that PortConnector can use any port (including infrared), however, it is not guaranteed that it will work with that port. For example, IR does not work on Palm OS devices.
        Throws:
        IOException
    • Method Detail

      • write

        public void write​(byte[] data)
                   throws IOException
        Sends the given raw data to the printer.
        Throws:
        IOException
      • write

        public void write​(byte[] data,
                          int ofs,
                          int len)
                   throws IOException
        Sends the given raw data to the printer.
        Throws:
        IOException
      • escape

        public void escape​(int command)
                    throws IOException
        Sends an escape command to the printer.
        Throws:
        IOException
      • escape

        public void escape​(int command,
                           int value1)
                    throws IOException
        Sends an escape command to the printer.
        Throws:
        IOException
      • escape

        public void escape​(int command,
                           int value1,
                           int value2)
                    throws IOException
        Sends an escape command to the printer.
        Throws:
        IOException
      • gs

        public void gs​(int command,
                       int value1)
                throws IOException
        Sends a GS command to the printer.
        Throws:
        IOException
      • gs

        public void gs​(int command,
                       int value1,
                       int value2)
                throws IOException
        Sends an escape command to the printer.
        Throws:
        IOException
      • print

        public void print​(java.lang.String str)
                   throws IOException
        Prints the given String.
        Throws:
        IOException
      • print

        public void print​(MonoImage img)
                   throws ImageException,
                          IOException
        Prints the given MonoImage. In the image, only black pixels are written. The maximum width is 576 pixels for single density is 192, and for double density is 384; the image is trimmed to fit these values.
        Throws:
        ImageException
        IOException
      • newLine

        public void newLine​(int count)
                     throws IOException
        Sends a number of new lines to the printer.
        Throws:
        IOException