swiftprintingbluetoothfont-sizecbperipheral

Change font size programmatically on thermal Bluetooth Printer


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?


Solution

  • 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