Reputation: 73
I am using Epos printer iOS SDK in my project. I am able to print a receipt but unable to open a cash drawer. Any suggestions which methods in epos SDK to be used to send commands to cash drawer? (Printer EPSON TM-U220B, APG Cash Drawer.)
Tried with below code but not working
let builder:Epos2Printer = Epos2Printer.init(printerSeries:15, lang: 1)
var result:Int32
let a : Int = 1
let b : Int32 = Int32(a)
//To send commands to cash drawer
result = builder.addPulse(b, time:0)
let str:String = "<XCT>27,112,0,25,250"
let data:NSData = str.dataUsingEncoding(NSUTF8StringEncoding)!
result = builder.addCommand(data)
Upvotes: 0
Views: 1483
Reputation: 146
I used to struggle doing this I remember... I built my own wrapper around their builder but bellow is my function to open the cashdrawer (the sequence of byte to send is taken from their printer documentation). Also, this works for TM-TII printer so the byte sequence may differ with your model but you can definitely use the same approach to send bytes through.
ps: transport
is an internal function of my wrapper that uses promises to communicate with the printer.
func openCashDrawer() {
transport {
let cashDrawerOpenCmd: [Int8] = [0x1B, 0x70, 0x0, 0x20, 0x20]
self.builder?.addCommand(NSData(bytes: cashDrawerOpenCmd, length: 5))
}.fail { error in
// @TODO properly handle error
print("openCashDrawer() error: \(error)")
}
}
Upvotes: 1