2

I have a 58mm 'MINI Thermal Printer', Model: ZJ-5805DD to use as POS printer with my POS App.

I've successfully programmatically connected my App to the Printer via Bluetooth and can print text fine using

KitchenPrinter.writeValue(myStringData, for: A2orC2, type: .withoutResponse)

*note: A2 or C2 [see-below] characteristics produce same text print out.


Changing the font print size has become a dead end for me. I know it's possible because the printer manuel had me download print tester "POS-PrinterV1.0" from the AppStore which can change font size

Upon Service/Characteristic Discovery, we find 4 Services A, B, C, D (for simplicity of discussion)

A:

CBService: 0x1c0a6a5c0, isPrimary = YES, UUID = 49535343-FE7D-4AE5-8FA9-9FAFD205E455

CBCharacteristic: 0x1c02adf80, UUID = 49535343-1E4D-4BD9-BA61-23C647249616, properties = 0x10, value = (null), notifying = NO

contains NOTIFY

CBCharacteristic: 0x1c02bba80, UUID = 49535343-8841-43F4-A8D4-ECBE34729BB3, properties = 0xC, value = (null), notifying = NO

contains WRITE WRITEWITHOUTRESPONSE


B:

CBService: 0x1c0a6ce80, isPrimary = YES, UUID = E7810A71-73AE-499D-8C15-FAA9AEF0C3F2

  CBCharacteristic: 0x1c02adfe0, UUID = BEF8D6C9-9C21-4C9E-B632-BD58C1009F9F, properties = 0x3E, value = (null), notifying = NO

contains WRITE WRITEWITHOUTRESPONSE NOTIFY READ INDICATE


C:

CBService: 0x1c0a69100, isPrimary = YES, UUID = 18F0

  CBCharacteristic: 0x1c02b8000, UUID = 2AF0, properties = 0x30, value = (null), notifying = NO

contains NOTIFY INDICATE

  CBCharacteristic: 0x1c02a5700, UUID = 2AF1, properties = 0xC, value = (null), notifying = NO

contains WRITE WRITEWITHOUTRESPONSE


D:

CBService: 0x1c0a68300, isPrimary = YES, UUID = Device Information

  CBCharacteristic: 0x1c02a5dc0, UUID = Serial Number String, properties = 0x2, value = (null), notifying = NO

contains READ

  CBCharacteristic: 0x1c02a77a0, UUID = Software Revision String, properties = 0x2, value = (null), notifying = NO

contains READ

  CBCharacteristic: 0x1c02a76e0, UUID = Hardware Revision String, properties = 0x2, value = (null), notifying = NO

contains READ

  CBCharacteristic: 0x1c02a6060, UUID = Manufacturer Name String, properties = 0x2, value = (null), notifying = NO

contains READ


I've been scouring the internet for days for a Swift solution. Please can someone help?

Chameleon
  • 1,608
  • 3
  • 21
  • 39

2 Answers2

2

Resolved: After finding ESC/POS commands and this StackOverflow post I was able to change the print size on the printer known as M58-LL or ZJ-5805 using the following function which takes an array of hexcodes, transform them into UnicodeScalar, then to Character and appends them to a String which is sent to the printer same as a text printout.

let hexs = [0x1b,0x21,0x20] //doubleWide
var hexString = String() 
for all in hexs {
    if let scalar = UnicodeScalar(all) {
        hexString.append(Character(scalar))
    }
}
let theData = hexString.data(using: .utf8)!
myPrinter.writeValue(theData, for: printCharacteristic, type: .withoutResponse)

//printCharacteristic corresponds with Service/Characteristic B

[0x1b,0x21,0x00] //default
[0x1b,0x21,0x01] //small font
[0x1b,0x21,0x08] //bold
[0x1b,0x21,0x10] //doubleHeight
[0x1b,0x21,0x20] //doubleWidth
[0x1b,0x21,0x20] //doubleHeightAndWidth
Chameleon
  • 1,608
  • 3
  • 21
  • 39
0

I know it is too late but this can help to other programmers. I created POS Android Application. It has Bluetooth and Wi-Fi POS Printer to print cheques. I used custom style to print all Bluetooth and Wi-Fi POS Printer.

Bluetooth POS Printer

private fun printCustom(msg: String, size: Int, align: Int) {
    //Print config "mode"
    val normal = byteArrayOf(0x1B, 0x21, 0x03) // 0- normal size text
    val bold = byteArrayOf(0x1B, 0x21, 0x08) // 1- only bold text
    val boldMedium = byteArrayOf(0x1B, 0x21, 0x20) // 2- bold with medium text
    val boldLarge = byteArrayOf(0x1B, 0x21, 0x10) // 3- bold with large text
    try {
        when (size) {
            0 -> outputStream!!.write(normal)
            1 -> outputStream!!.write(bold)
            2 -> outputStream!!.write(boldMedium)
            3 -> outputStream!!.write(boldLarge)
        }
        when (align) {
            0 ->                     //left align
                outputStream!!.write(byteArrayOf(0x1b, 'a'.code.toByte(), 0x00))
            1 ->                     //center align
                outputStream!!.write(byteArrayOf(0x1b, 'a'.code.toByte(), 0x01))
            2 ->                     //right align
                outputStream!!.write(byteArrayOf(0x1b, 'a'.code.toByte(), 0x02))
        }
        outputStream!!.write(msg.toByteArray())
        outputStream!!.write(0x0A)
    } catch (e: IOException) {
        e.printStackTrace()
    }
}

You can use it like

// Print Command
        try {
            outputStream = mBluetoothSocket!!.outputStream
            val printFormat = byteArrayOf(0x1B, 0x21, 0x03)
            outputStream!!.write(printFormat)

            printCustom("\n", 0, 0)

            printCustom("This is text print", 0, 1)

            printCustom("\n", 0, 0)

            outputStream!!.flush()

        } catch (e: Exception) {
            e.printStackTrace()
        }

End of your code you need to write this code

outputStream!!.flush()

Wi-Fi POS Printer

private fun printCustom(list: ArrayList<ByteArray>, msg: String, size: Int) {
    //Print config "mode"
    val normal = byteArrayOf(0x1B, 0x21, 0x03) // 0- normal size text
    val bold = byteArrayOf(0x1B, 0x21, 0x08) // 1- only bold text
    val boldMedium = byteArrayOf(0x1B, 0x22, 0x20) // 2- bold with medium text
    val boldLarge = byteArrayOf(0x1B, 0x21, 0x20) // 3- bold with large text
    try {

        when (size) {
            0 -> list.add(normal)
            1 -> list.add(bold)
            2 -> list.add(boldMedium)
            3 -> list.add(boldLarge)
        }

        list.add(msg.toByteArray())

    } catch (e: IOException) {
        e.printStackTrace()
    }
}

You can use it like Bluetooth but not much but you cannot set text align or I didn't find about that. So use Printer commands just like SDK. You can find it its own website. if you have any question feel free to ask on Any social media by contacting @OgabekDev.

If it work, Please give positive feedback.

Thank you all.

OgabekDev
  • 21
  • 3