package service // ESC 指令集 for EMD807 (79.5mm 热敏打印机) // Font A = 12×24 dots, 每行 32 字符; Font B = 9×17 dots, 每行 42 字符 const ( ESC = 0x1B GS = 0x1D DC2 = 0x12 // 设备控制 ) var ( InitCmd = []byte{ESC, '@'} // 初始化打印机 SelfTestCmd = []byte{DC2, 'T'} // DC2 T — 打印自测页 AlignLeftCmd = []byte{ESC, 'a', 0} // 左对齐 AlignCenterCmd = []byte{ESC, 'a', 1} // 居中对齐 CutPaperCmd = []byte{ESC, 'i'} // ESC i — EMD807 全切纸 HalfCutCmd = []byte{ESC, 'm'} // ESC m — 半切(留一点连接) DoubleHeightCmd = []byte{ESC, '!', 0x11} // 双倍高度+宽度 NormalCmd = []byte{ESC, '!', 0x00} // 正常大小 BoldOnCmd = []byte{ESC, 'E', 1} // 加粗 BoldOffCmd = []byte{ESC, 'E', 0} // 取消加粗 FontBCmd = []byte{ESC, 'M', 1} // Font B (9×17, 42 chars/line) PaperStatusCmd = []byte{ESC, 'v'} // 查询纸张状态 ) // ESCPOS_Text 打印一行文字(自动加换行符) func ESCPOS_Text(text string) []byte { return append([]byte(text), '\n') } // ESCPOS_QRCode 打印二维码(GS ( k 指令,兼容 EMD807) func ESCPOS_QRCode(data string) []byte { // GS ( k pL pH cn fn [params] // cn=49 (QR Code), fn=65 (model), fn=67 (size), fn=80 (store), fn=81 (print) pL := byte(len(data) + 3) pH := byte((len(data) + 3) >> 8) cmd := []byte{GS, '('} // 模型选择 cmd = append(cmd, 0x04, 0x00, 0x31, 0x41, 0x32, 0x00) // QR Model 2 cmd = append(cmd, 0x03, 0x00, 0x31, 0x43, 0x08) // Cell size 8 // Store data cmd = append(cmd, GS, '(') cmd = append(cmd, pL, pH, 0x31, 0x50, 0x30) // fn=80 store cmd = append(cmd, []byte(data)...) // Print QR cmd = append(cmd, GS, '(') cmd = append(cmd, 0x03, 0x00, 0x31, 0x51, 0x30) // fn=81 print return cmd }