本文主要介绍.NET(C#)中,连接Godex(科诚)条码打印机,和打印条形码的方法,以及相关的示例代码。

1、连接打印机

//项目代码:https://github.com/cjavapy/EZio_Sample_C-
   private void ConnectPrinter()
        {
            if (RBtn_USB.Checked == true)
            {
                Printer.Open(PortType.USB);
            }
            else if (RBtn_COM.Checked == true)
            {
                if (Cbo_COM.SelectedItem != null)
                {
                    Printer.Open(Cbo_COM.SelectedItem.ToString());
                    Printer.SetBaudrate(int.Parse(Txt_Baud.Text));
                }
            }
            else if (RBtn_LPT.Checked == true)
            {
                if (Cbo_LPT.SelectedIndex == 0)
                    Printer.Open(PortType.LPT1);
                else
                    Printer.Open(PortType.LPT2);
            }
            else if (RBtn_Driver.Checked == true)
            {
                Printer.Open(Cbo_Driver.SelectedItem.ToString());
            }
            else if (RBtn_NET.Checked == true)
            {
                Printer.Open(Txt_IP.Text, int.Parse(Txt_NetPort.Text));
            }
        }

2、设置条码标签

//项目代码:https://github.com/cjavapy/EZio_Sample_C-
      private void LabelSetup()
        {
            Printer.Config.LabelMode((PaperMode)Cbo_PaperType.SelectedIndex, (int)Num_Label_H.Value, (int)Num_GapFeed.Value);
            Printer.Config.LabelWidth((int)Num_Label_W.Value);
            Printer.Config.Dark((int)Num_Dark.Value);
            Printer.Config.Speed((int)Num_Speed.Value);
            Printer.Config.PageNo((int)Num_Page.Value);
            Printer.Config.CopyNo((int)Num_Copy.Value);
        }

3、打印条码和其它文本字符

//项目代码:https://github.com/cjavapy/EZio_Sample_C-
  private void Btn_PrintCode39_Click(object sender, EventArgs e)
        {
            ConnectPrinter();
            LabelSetup();
            Printer.Command.Start();
            Printer.Command.PrintText(10, 10, 34, "Arial", "Code 39");
            Printer.Command.PrintBarCode(BarCodeType.Code39, 10, 50, "1234");           // Code39
            Printer.Command.PrintText(10, 210, 34, "Arial", "EAN128");
            Printer.Command.PrintBarCode(BarCodeType.EAN128, 10, 250, "1234");          // EAN128(GS1128)
            Printer.Command.PrintText(10, 410, 34, "Arial", "Code128 Subset A");
            Printer.Command.PrintBarCode(BarCodeType.Code128_Subset, 10, 450, 2, 6, 80, 0, 1, "A1234");     // Code128 Subset A
            Printer.Command.End();
            DisconnectPrinter();
        }

注意:如需要其它语言的示例代码,扫右侧二维码加群,群共享中有相关项目代码。

完整项目源码https://github.com/cjavapy/EZio_Sample_C-

推荐文档