using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; using System.Threading; using smartpos.wpos.App.Common; using smartpos.wpos.App.Common.DataDictionary; using smartpos.wpos.App.Common.Locator;
namespace smartpos.wpos.App.Components.SystemSetting.CustomerDisplay { /// <summary> /// 客显(HK-V110) /// </summary> public class CustomerDisplay { #region 成员变量
private static string spPortName; private static int spBaudRate; private static StopBits spStopBits; private static int spDataBits;
#endregion --成员变量
#region 属性 /// <summary> /// 客显发送类型 /// </summary> public static CustomerDispiayType DispiayType { private get; set; } #endregion --属性
#region 构造函数 /// <summary> /// 构造函数 /// </summary> /// <param name="_spPortName">端口名称(COM1,COM2,COM3...)</param> /// <param name="_spBaudRate">通信波特率(2400,9600....)</param> /// <param name="_spStopBits">停止位</param> /// <param name="_spDataBits">数据位</param> //public CustomerDisplay(string _spPortName, int _spBaudRate, string _spStopBits, int _spDataBits) //{ // CustomerDisplay.spBaudRate = _spBaudRate; // CustomerDisplay.spDataBits = _spDataBits; // CustomerDisplay.spPortName = _spPortName; // CustomerDisplay.spStopBits = (StopBits)(Enum.Parse(typeof(StopBits), _spStopBits)); //}
static CustomerDisplay() { try { IntiVar(); } catch (Exception ex) { WXLog.Error("顾显数据CustomerDisplay", ex); } } /// <summary> /// 初始化变量 /// </summary> public static void IntiVar() { var info = ServiceLocator.MachineSetting.GuestDisplayer; CustomerDisplay.spPortName = info.Parameter.Port; CustomerDisplay.spBaudRate = Convert.ToInt32(info.Parameter.Baudrate); CustomerDisplay.spStopBits = (StopBits)(Enum.Parse(typeof(StopBits), info.Parameter.StopBit)); CustomerDisplay.spDataBits = int.Parse(info.Parameter.DataBit); }
#endregion --构造函数
#region Method #region 公共方法 /// <summary> /// 顾显数据展现 /// </summary> /// <param name="data">发送的数据(清屏可以为null或者空)</param> public static void DisplayData(string data) { WXLog.Info("顾显数据展现开始。"); try { if (ServiceLocator.MachineSetting.GuestDisplayer.Parameter.Type == "0") { return; } if (Array.IndexOf<string>(SerialPort.GetPortNames(), spPortName) != -1) { SerialPort serialPort = new SerialPort(); serialPort.PortName = spPortName; serialPort.BaudRate = spBaudRate; serialPort.StopBits = spStopBits; serialPort.DataBits = spDataBits; if (!serialPort.IsOpen) { serialPort.Open(); } // serialPort.BaseStream.Flush(); //先清屏 // serialPort.Write(((char)12).ToString()); //先清屏 // serialPort.WriteLine(((char)12).ToString()); //指示灯 int i = 0; switch (DispiayType) { case CustomerDispiayType.Clear: i = 48; break; case CustomerDispiayType.Price: i = 49; break; case CustomerDispiayType.Total: i = 50; break; case CustomerDispiayType.Recive: i = 51; break; case CustomerDispiayType.Change: i = 52; break; } //状态 serialPort.Write(((char)27).ToString() + ((char)115).ToString() + ((char)i).ToString());
//发送数据 if (!string.IsNullOrEmpty(data.ToString())) { string str = ((char)27).ToString() + ((char)81).ToString() + ((char)65).ToString() + data.ToString() + ((char)13).ToString(); serialPort.Write(str); } serialPort.Close(); serialPort.Dispose(); } } catch (Exception ex) { WXLog.Error("顾显数据展现", ex); } finally { WXLog.Info("顾显数据展现结束。"); } }
#endregion --公共方法 #endregion --Method }
/// <summary> /// 客显类型 /// </summary> public enum CustomerDispiayType { /// <summary> /// 清屏 /// </summary> Clear, /// <summary> /// 单价 /// </summary> Price, /// <summary> /// 合计 /// </summary> Total, /// <summary> /// 收款 /// </summary> Recive, /// <summary> /// 找零 /// </summary> Change } }
Ps:相关文件已上传
|
请发表评论