条码打印机智能脱机打印
- 使用BCC中国定制条码打印机
- 打印机指令
- 打印机底层是运行在Unix系统上的
- 操作步骤
- 图片
- 代码Demo
使用BCC中国定制条码打印机
BCC打印机 PM42 PM43打印机
打印机指令
打印机指令罗列一下:
- Honeywell 打印机 ,FP,DP,DPL指令;
- ZEBRA打印机 ZPL||,EPL,CPCL指令;
- ESPON打印机 ESC-POS指令 ;
- TSC打印机 TSPL指令 ;
各厂家打印机指令各有千秋。
打印机底层是运行在Unix系统上的
操作步骤
-
环境搭建
Windows开启程序功能—>Telnet Client 功能 -
打开DOS系统 Win+R输入命令cmd
telnet 192.168.0.120 网线连接打印机 打印机IP地址192.168.0.120
login输入:user
$ 输入:busybox
再次输入:Mono apps/HelloWorld.exe -
在VS2017中生成事件—后期生成事件命令行(C:\SmartPrinting\Utils\FtpPut.exe ( T a r g e t F i l e N a m e ) f t p : / / 192.168.1.10 / a p p s / (TargetFileName) ftp://192.168.1.10/apps/ (TargetFileName)ftp://192.168.1.10/apps/(TargetFileName) user pass)。
-
- FileZilla ftp文件软件可以查看打印机的系统文件 字体Font C#程序apps等等。
图片
连接打印机的图片:
VS2017生成事件的图片
:
代码Demo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.IO;
using System.Xml.Serialization;
using Intermec.Printer;
namespace HoneywellPrinterDemo
{
class Program
{
static UI.Canvas canvas;
static UI.Canvas.Timer timer;
static UI.Keypad keypad;
static Communication.Autohunt autohunt;
static string ReadData = "";static int num = 0;static Color white = new Color(255, 255, 255, 255);static Color black = new Color(0, 0, 0, 255);static UI.Canvas.Text varTextL1; //UI 第一行static UI.Canvas.Text varTextL2; //UI 第二行static UI.Canvas.Text varTextL3; //UI 第三行static void Main(string[] args){Console.WriteLine("HelloWorld Application is running V1.1.4!"); //Telnet 上显示canvas = new UI.Canvas();canvas.Clear();UI.Canvas.Rectangle bg = new UI.Canvas.Rectangle(0, 0, canvas.Width,canvas.Height, black); //画背景图canvas += bg;UI.Canvas.Text titleText = new UI.Canvas.Text(5, 0, "Honeywell 中国", "MHeiGB18030C-Medium", 30, white);//UI第一行标题canvas += titleText;varTextL1 = new UI.Canvas.Text(5, 40, "请扫描条码!", "MHeiGB18030C-Medium", 26, white);//UI 第一行文字canvas += varTextL1;varTextL2 = new UI.Canvas.Text(5, 70, "", "MHeiGB18030C-Medium", 26, white);//UI 第二行文字canvas += varTextL2;varTextL3 = new UI.Canvas.Text(5, 100, "", "MHeiGB18030C-Medium", 26, white);//UI 第三行文字canvas += varTextL3;//140UI.Canvas.Text varTextFeed = new UI.Canvas.Text(5, 170, "按确认键测试认纸", "MHeiGB18030C-Medium", 26, white);canvas += varTextFeed;//170UI.Canvas.Text varTextExit = new UI.Canvas.Text(5, 200, "按返回键退出智能打印程序", "MHeiGB18030C-Medium", 26, white);canvas += varTextExit;//Autohunt 自动绑定USB和串口autohunt = new Communication.Autohunt();string[] usbPortNames = Communication.USBHost.GetPortNames();foreach (string usbPortName in usbPortNames){Communication.USBHost usbHost =new Communication.USBHost(usbPortName);usbHost.Open();if (usbHost.IsOpen){autohunt.AddStream(usbHost.GetStream());Console.WriteLine("Added: " + usbPortName);}}// Add Serial ports to autohuntstring[] serialPortNames = Communication.SerialPort.GetPortNames();foreach (string serialPortName in serialPortNames){Communication.SerialPort serialPort =new Communication.SerialPort(serialPortName);serialPort.Open();serialPort.BaudRate = 115200; //串口参数,可以调整serialPort.Encoding = System.Text.Encoding.UTF8;serialPort.Parity = System.IO.Ports.Parity.None;serialPort.StopBits = System.IO.Ports.StopBits.One;serialPort.DataBits = 8;serialPort.Handshake = System.IO.Ports.Handshake.None;autohunt.AddStream(serialPort.BaseStream);Console.WriteLine("Added: " + serialPortName); //Telnet上显示}keypad = new UI.Keypad(); //键盘事件keypad.KeyUp += new UI.Keypad.KeyEventHandler(KeyHandlerUp); //键盘事件timer = new UI.Canvas.Timer(); //定时器timer.Interval = 500; //刷新间隔500mstimer.Tick += new UI.Canvas.TimerEventHandler(GetData);timer.Start();canvas.Run();timer.Enabled = false;keypad.Dispose();autohunt.Dispose();canvas.Refresh();canvas.Exit();canvas.Dispose();}public static void KeyHandlerUp(Object o, UI.Keypad.KeyEventArgs eventArgs) //按键事件{int keycode;keycode = eventArgs.KeyChar;// Output on consoleConsole.WriteLine("Key code: " + keycode.ToString());if (keycode == 9) //返回键{timer.Enabled = false;timer.Stop();varTextL1.Data = "程序正在退出"; //更新UI第一行varTextL2.Data = "请耐心等待!"; //更新UI第二行varTextL3.Data = ""; //更新UI第三行canvas.Exit();canvas.Dispose();}if (keycode == 11) //走纸{Feed(1);}if (keycode == 10){Feed(2);}}public static void GetData(Object obj, UI.Canvas.TimerEventArgs eventArgs) //获取USB/串口数据{timer.Stop();string tempL1, tempL2, tempL3, tempL4;int i;Byte[] bytes = new Byte[256];if ((i = autohunt.Read(bytes, 0, bytes.Length)) > 0){string data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);// Console.WriteLine("ReadData Value : {0}", data);Console.WriteLine("Begin read {0} bytes: {1}", data.Length, data);//data.IndexOf("\n") > 0 || data.IndexOf("\r") > 0 ||if (data.IndexOf("\n") > 0 || data.IndexOf("\r") > 0){data = ReadData + data; //将USB串口数据存储为data// data = data.Replace("\n", "");//删除回车//data =data.Replace("\r", "");//删除换行 chinaautoid.comReadData = "";Console.WriteLine("read {0} bytes: {1}", data.Length, data);varTextL1.Data = "扫描到数据:"; //更新UI第一行if (data.Length > 20) //如果扫描数据> 20{varTextL2.Data = data.Substring(0, 20); //分2行显示,截取前20位varTextL3.Data = data.Substring(20, data.Length - 20);}else{ //如果扫描数据< 20varTextL2.Data = data;varTextL3.Data = "";}Console.WriteLine("Print Function!");if (data.Length == 14){PrintLabelType1(data); //打印第一种标签}else{PrintLabelType2();}canvas.Refresh(); //刷新UI}else{Console.WriteLine("NOCR read {0} bytes: {1}", data.Length, data);ReadData += data;}}timer.Start();}private static void Feed(int FeedType){PrintControl printControl = new PrintControl();State state = State.NoError;if (FeedType == 1){state = printControl.FormFeed();}if (FeedType == 2){state = printControl.TestFeed();}if (state == State.NoError){Console.WriteLine("Feed 1 label");}printControl.Dispose();}private static void PrintLabelType1(string data){Console.WriteLine("In Print 1 Function");PrintControl printControl = new PrintControl();Drawing drawing = new Drawing();drawing.Clear();//清空画图Console.WriteLine(data);// Status status = new Status();// State state = status.GetState();State state = State.NoError;num++;Drawing.Text text = new Drawing.Text();text.CharacterEncoding = CharacterEncoding.UTF8;text.Point = new Point(100, 150); //打印文字的X,Ytext.Data = "脱机打印SmartSystem"+num.ToString(); //文字内容text.Height = 12; //文字高度text.FontName = "MHeiGB18030C-Medium"; //字体高度drawing += text;Drawing.Barcode barc = new Drawing.Barcode(120, 50, "CODE128", data); //Code128,X,Y位置,条码内容barc.Height = 40; //条码高度barc.Text.Enabled = true; //人眼可识别文字开启barc.Text.FontName = "Univers"; //字体名barc.BarWidthWide = 3;barc.BarWidthNarrow = 1;barc.WidthMagnification = 1;drawing += barc;state = printControl.PrintFeed(drawing, 1); //打印一张if (state != State.NoError){Console.WriteLine("PrintFeed failed: {0}", state.ToString());}Console.WriteLine("Exit");printControl.Dispose();drawing.Dispose();}private static void PrintLabelType2(){Console.WriteLine("In Print 1 Function");PrintControl printControl = new PrintControl();Drawing drawing = new Drawing();drawing.Clear();//清空画图// Status status = new Status();// State state = status.GetState();State state = State.NoError;Drawing.Text text = new Drawing.Text();text.CharacterEncoding = CharacterEncoding.UTF8;text.Point = new Point(100, 150); //打印文字的X,Ytext.Data = "Error"; //文字内容text.Height = 12; //文字高度text.FontName = "MHeiGB18030C-Medium"; //字体高度drawing += text;Drawing.Text text1 = new Drawing.Text();text1.CharacterEncoding = CharacterEncoding.UTF8;text1.Point = new Point(100, 170); //打印文字的X,Ytext1.Data = "Honeyewll"; //文字内容text1.Height = 12; //文字高度text1.FontName = "MHeiGB18030C-Medium"; //字体高度drawing += text1;state = printControl.PrintFeed(drawing, 1); //打印一张if (state != State.NoError){Console.WriteLine("PrintFeed failed: {0}", state.ToString());}Console.WriteLine("Exit");printControl.Dispose();drawing.Dispose();}private static void PrintLabelType3(string data){Console.WriteLine("In Print 2 Function");PrintControl printControl = new PrintControl();Drawing drawing = new Drawing();drawing.Clear();//清空画图//Status status = new Status();// State state = status.GetState();State state = State.NoError;//Console.WriteLine("Printer State: {0}", state.ToString());Drawing.Text text = new Drawing.Text();text.Point = new Point(150, 30); //打印文字的X,Ytext.Data = data; //文字内容text.Height = 12; //文字高度text.FontName = "MHeiGB18030C-Medium"; //字体高度drawing += text;state = printControl.PrintFeed(drawing, 1);if (state != State.NoError){Console.WriteLine("PrintFeed failed: {0}", state.ToString());}Console.WriteLine("Exit");printControl.Dispose();drawing.Dispose();}
}
}