1.根據說明書調試硬件,校准介質還有色帶(很重要),我自己搞了好幾天才搞明白。
2.設置好參數,比如打印介質連續、非連續,熱敏還是熱轉質
3.打印機上電后悔自動校准,校准成功后就可以直接通過串口打印,設置好通訊參數
4.主要代碼
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ZebraQRCode { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { serialPort1.Open(); } private void button1_Click(object sender, EventArgs e) { // 打印機的指令用“^”作為開頭,任何打印指令都是從^XA開始,到^XZ結束 if (string.IsNullOrEmpty(textBox1.Text)) return; StringBuilder strZPL = new StringBuilder(); strZPL.Append("^XA"); // 開始指令 strZPL.Append("^FO108,55"); // ^FOx,y x代表橫坐標,y代表縱坐標 /* * ^BQa,b,c * a代表二維碼方向,默認是N * b代表二維碼的版本,可選值有【1,2】,1是原始版本,2是增強版本,推薦用2,因為1掃不出來。 * c代表二維碼的放大程度,可選值【1-10】 */ strZPL.Append("^BQN,2,10"); /* * ^FDab,cd^FS * a:錯誤糾正率,【H,Q,M,L】H是超高可靠度,L是高密度,建議使用H * b:數據輸入模式,【A,M】A是自動模式(參數c可省略),M是手動模式(需要指定參數c的字符類型) * c:字符模式,【N】數字,【A】字符,【B】字節,【K】Kanji(日文漢字) * d:二維碼的內容 */ strZPL.Append("^FDMM,A" + textBox1.Text + "^FS"); strZPL.Append("^XZ"); // 結束指令 serialPort1.Write(strZPL.ToString()); } } }
5.源碼地址 https://github.com/LicwStack/ZebraQRCode
6. 有用的參考 https://blog.csdn.net/bfz_50/article/details/82468621, https://blog.csdn.net/weixin_38211198/article/details/95961605