using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; namespace POSV.Printer { [Serializable] [JsonObject(MemberSerialization.OptIn)] public class PrinterObject : IEquatable { /// /// 串口 /// public const string COM_PORT_NAME = "port"; /// /// 串口波特率 /// public const string COM_PORT_BAUD = "baud"; /// /// 并口 /// public const string LPT_NAME = "lpt"; public const string USB_PID = "pid"; public const string USB_VID = "vid"; /// /// 网口的IP /// public const string NET_IP_ADDRESS = "ip"; /// /// 驱动名称 /// public const string DRIVE_NAME = "drive"; public PrinterObject() { this.Id = ""; this.Name = ""; this.DynamicLibrary = DynamicLibrary.通用打印模式; this.PageWidth = 80; this.Dpi = 203; var data = new Dictionary(); data.Add(COM_PORT_NAME , "COM1"); data.Add(COM_PORT_BAUD , "19200"); data.Add(LPT_NAME , "LPT1"); data.Add(USB_PID , "0"); data.Add(USB_VID , "0"); data.Add(NET_IP_ADDRESS , "127.0.0.1"); data.Add(DRIVE_NAME , "None"); this.Data = data; this.EscPosCommand = new EscPosCommand(); } /// /// 打印机ID /// [JsonProperty(PropertyName = "id")] public string Id { get; set; } /// /// 打印机名称 /// [JsonProperty(PropertyName = "name")] public string Name { get; set; } /// /// 打印机接口类型 /// [JsonProperty(PropertyName = "port")] public PortType PortType { get; set; } /// /// 打印机动态库支持 /// [JsonProperty(PropertyName = "dynamic")] public DynamicLibrary DynamicLibrary { get; set; } /// /// 页宽 /// [JsonProperty(PropertyName = "width")] public int PageWidth { get; set; } /// /// 打印机分辨率 /// [JsonProperty(PropertyName = "dpi")] public int Dpi { get; set; } /// /// 打印机参数配置 /// [JsonProperty(PropertyName = "data")] public Dictionary Data { get;} /// /// 打印机ESC/POS指令 /// [JsonProperty(PropertyName = "command")] public EscPosCommand EscPosCommand { get; set; } /// /// 自动切纸 /// [JsonProperty(PropertyName = "cutpager")] public bool CutPager { get; set; } /// /// 自动开钱箱 /// [JsonProperty(PropertyName = "cashbox")] public bool OpenCashbox { get; set; } /// /// 打印机蜂鸣 /// [JsonProperty(PropertyName = "beep")] public bool Beep { get; set; } = false; /// /// 回退纸张行数 /// [JsonProperty(PropertyName = "feedBack")] public int FeedBackRow { get; set; } = 0; public bool Equals(PrinterObject other) { if (other == null) { return false; } if (this.Data.Keys.Count != other.Data.Keys.Count) { return false; } foreach (var key in this.Data.Keys) { if (!(this.Data[key].Equals(other.Data[key]))) { return false; } } return this.PortType == other.PortType && this.Name == other.Name && this.Id == other.Id; } public override string ToString() { return this.Name; } } public enum PortType { None, 串口, 并口, 网口, USB, 驱动 } public enum DynamicLibrary { 通用打印模式, 北洋打印机专用 } }