Giter Site home page Giter Site logo

terratempest / android_niimprint Goto Github PK

View Code? Open in Web Editor NEW
19.0 1.0 0.0 135 KB

This repository contains an Android client for printing via the Niimbot D11 Bluetooth printer. It is designed to simplify the integration of printing features in your Android applications, specifically targeting the Niimbot D11 model. With this client, you can easily send print jobs to the Niimbot D11 printer from your custom Android apps.

License: MIT License

Kotlin 100.00%
android api-client niimbot printer-bluetooth niimbot-d11 label-maker thermal-printer

android_niimprint's Introduction

Buy Me A Coffee

(WIP) Niimbot printer client code to implement in android

Have only tested this code with a Niimbot D11

Code based of python implementation found here: https://github.com/kjy00302/niimprint

Usage

// Initialize and connect to the printer
val printer = NiimbotPrinterClient(bluetoothAddress: String, bluetoothAdapter: BluetoothAdapter)

// Print bitmap image
printer.printLabel(image: Bitmap, width: Int, height: Int, labelQty: Int = 1, labelType: Int = 1, labelDensity: Int = 2)

Documentation for NiimbotPrinterClient

Overview: This utility class provides functionalities to interact with a Niimbot D11 label printer over a network socket. The main operations include sending, receiving, and processing packets between the application and the printer, and several print utility functions.

The main functionality of this utility class can be handled with the printLabel method without dealing with any other methods of this class.

To use the utility, you need to have an instance of the class and an established socket connection. With the socket in place, you can call the printLabel method to handle sending the image data to the printer.

Methods:

recv(): Receives Niimbot packets from the printer.
    Returns: A list of Niimbot packets.
    This method continuously reads data from the printer's input stream and constructs Niimbot packets based on specific start and end bytes.

send(packet: NiimbotPacket): Sends a packet to the printer.
    Parameters: packet – The Niimbot packet to be sent.
    This method writes the packet to the printer's output stream.

transceive(reqCode: RequestCodeEnum, data: ByteArray, respOffset: Int = 1): Sends a packet to the printer and waits for a response.
    Parameters:
        reqCode – The request code enum.
        data – Byte data to be sent.
        respOffset – An offset for the response code, defaults to 1.
    Returns: A Niimbot packet or null if no response is received after several attempts.

getInfo(key: InfoEnum): Retrieves printer information based on a given key.
    Parameters: key – The information enum key.
    Returns: Printer information related to the provided key.

getRfid(): Fetches RFID related data from the printer.
    Returns: A map with RFID data like uuid, barcode, serial, used_len, total_len, and type.

heartbeat(): Fetches the printer's heartbeat data.
    Returns: A map with printer's status like closingstate, powerlevel, paperstate, and rfidreadstate.

Printing-related methods: Methods to configure and control the printing process. These include:
    setLabelType(n: Int): Set label type.
    setLabelDensity(n: Int): Set label density.
    startPrint(), endPrint(), startPagePrint(), endPagePrint(): Control printing lifecycle.
    allowPrintClear(): Allows clearing the print.
    setDimension(w: Int, h: Int): Set dimensions for printing.
    setQuantity(n: Int): Set quantity of labels to print.
    getPrintStatus(): Retrieve print status.
    printLabel(image: Bitmap, width: Int, height: Int, labelQty: Int = 1, labelType: Int = 1, labelDensity: Int = 2): Print a given image as a label.

Utility methods: Methods to support various operations.
    packetToInt(packet: NiimbotPacket): Converts a packet to an integer.
    resizeBitmap(source: Bitmap, desiredWidth: Int, desiredHeight: Int): Resizes a bitmap to desired dimensions.
    rotateBitmap(bitmap: Bitmap, degrees: Float): Rotates a bitmap by a given degree.

android_niimprint's People

Contributors

terratempest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

android_niimprint's Issues

bitmap working sample ?

HI, Thanks for sharing your work. I was glad to find it. Thanks to this repo i was able to send commands to my printer. But unfortunatelly wasn't able to print a valid bitmap yet. Could you share a working bitmap sample you have used on ur D11 printer ?

trying to figure out why my bitmap isn't being printed. Getting the error below:

Screenshot 2024-01-02 at 11 20 48 PM Screenshot 2024-01-02 at 11 21 32 PM

hello image:
hellosprite

java.io.IOException: socket closed

Hello, i have Niimbot b1 printer and try to use your client for sample printing

But when i try no print, it leads me to exception that socket was closed

What is the actual order to make successful print? maybe i should connect to it some other way?

Proof, that printer is discovered and exists -
telegram-cloud-photo-size-2-5393442394004903242-y

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.