NkaBall
NkaBall

Reputation: 81

How to write TSPL command to BLE printer in iOS?

I am trying to print to BLE printer that uses TSPL commands. Scanning, connecting, discovering services and characteristics are okay. The device information can also be read without a problem. The only problem is writing value to the printer.

let line = "FORMFEED"
peripheral?.writeValue(line.data(using: .utf8)!, for: characteristic, type: .withResponse)

peripheral?.writeValue(line.data(using: String.GBEncoding.GB_18030_2000)!, for: characteristic, type: .withResponse)

peripheral?.writeValue(Data(Array(line.utf8)), for: characteristic, type: .withResponse)

extension String {
    struct GBEncoding {
        public static let GB_18030_2000 = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GB_18030_2000.rawValue)))
    }
}

The delegate method writeValue(_:for:type:) is called without any error. But the printer doesn't perform any action.

I have tried with GB_18030_2000 encoding and byte arrays as well. They are not also working.

I also would like to know how to print a text which includes multiple commands.

TEXT 25,25,"3",0,1,1,"COMMAND TEST"
PRINT 3,1

Upvotes: 2

Views: 376

Answers (0)

Related Questions