• LED客显的类


    using System;
    using System.IO.Ports;
    
    namespace Common
    {
        public class LedHelper
        {
            private static int _baudRate = 2400;
            private static string _portName = "COM2";
            /// <summary>
            /// 串型端口对象
            /// </summary>
            private static SerialPort _serialPort;
            /// <summary>
            /// 波特率
            /// </summary>
            public static int BaudRate
            {
                get { return _baudRate; }
                set { _baudRate = value; }
            }
            /// <summary>
            /// 端口
            /// </summary>
            public static string PortName
            {
                get { return _portName; }
                set { _portName = value; }
            }
            /// <summary>
            /// 清空屏幕
            /// </summary>
            public static void ScreenClean()
            {
                Open();
    
                Clear();
    
                Close();
            }
            /// <summary>
            /// 显示单价
            /// </summary>
            /// <param name="price"></param>
            public static void ShowUnitPrice(string price)
            {
                Open();
                UnitPrice(price);
                Close();
            }
            /// <summary>
            /// 显示应收
            /// </summary>
            /// <param name="money"></param>
            public static void ShowSum(string money)
            {
                Open();
                Sum(money);
                Close();
            }
            /// <summary>
            /// 显示实际收钱
            /// </summary>
            /// <param name="money"></param>
            public static void ShowRealMoney(string money)
            {
                Open();
                
                CollectMoney(money);
                Close();
            }
            /// <summary>
            /// 找零
            /// </summary>
            /// <param name="money"></param>
            public static void ShowOddChange(string money)
            {
                Open();
                OddChange(money);
                Close();
            }
            /// <summary>
            /// 全暗
            /// </summary>
            public static void ShowNone(string money)
            {
                Open();
                GetBlack(money);
                Close();
            }
    
    
            /// <summary>
            /// GetSum 总价
            /// </summary>
            /// <param name="value">The value.</param>
            private static void Sum(string value)
            {
                //clear();            
                NewData(value);
                GetSum();
            }
            /// <summary>
            /// GetUnitPrice 单价
            /// </summary>
            /// <param name="value">The value.</param>
            private static void UnitPrice(string value)
            {
                //clear();
                NewData(value);
    
                GetUnitPrice();
            }
            /// <summary>
            /// GetCollectMoney 实收
            /// </summary>
            /// <param name="value">The value.</param>
            private static void CollectMoney(string value)
            {
                //clear();
                NewData(value);
                GetCollectMoney();
            }
            /// <summary>
            /// GetOddChange 找零
            /// </summary>
            /// <param name="value">The value.</param>
            private static void OddChange(string value)
            {
                //clear();
                NewData(value);
                GetOddChange();
            }
            /// <summary>
            /// 全黑
            /// </summary>
            /// <param name="value"></param>
            private static void GetBlack(string value)
            {
                //clear();
                NewData(value);
                AllBlack();
            }
    
            /// <summary>
            ///全暗.是找零 全价 GetCollectMoney 这几个灯
            /// </summary>
            private static void AllBlack()
            {
                // serialPort1.WriteLine(@"s0");
                _serialPort.Write(@"s0");
            }
            /// <summary>
            /// 清屏.
            /// </summary>
            private static void Clear()
            {
                //serialPort1.WriteLine("f");
                _serialPort.Write(((char)(12)).ToString());
            }
            private static void GetUnitPrice()
            {
                //serialPort1.WriteLine(@"s1");//其实有数据的那个空格
                _serialPort.Write(@"s1");//其实有数据的那个空格
            }
            private static void GetSum()
            {
                _serialPort.WriteLine(@"s2");
            }
            private static void GetCollectMoney()
            {
                _serialPort.WriteLine(@"s3");
            }
            private static void GetOddChange()
            {
                _serialPort.WriteLine(@"s4");
            }
            private static void NewData(string data)
            {
                //serialPort1.WriteLine(@"QA" + data);
                _serialPort.Write(@"QA" + data + ((char)(13)).ToString());
            }
            /// <summary>
            /// 打开串口,可能抛出异常
            /// </summary>
            private static void Open()
            {
                try
                {
                    if (_serialPort == null)
                    {
                        _serialPort = new SerialPort();
                        _serialPort.PortName = _portName;
                        _serialPort.BaudRate = _baudRate;
                    }
                    if (!_serialPort.IsOpen)
                    {
                        _serialPort.Open();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("打开串口失败!错误信息为:" + ex.Message);
                }
    
            }
            /// <summary>
            /// 关闭串口
            /// </summary>
            private static void Close()
            {
                if (_serialPort != null && _serialPort.IsOpen)
                    _serialPort.Close();
            }
        }
    }
  • 相关阅读:
    easyui loadFilter 使用
    控件setText与setValue赋值顺序先后区别
    JS选中和取消选中checkbox
    easyui 解决连弹两个dialog时候,第二个dialog居中问题
    bootstrap基础学习【导航条、分页导航】(五)
    bootstrap基础学习【菜单、按钮、导航】(四)
    sublime设置
    《啊哈!算法》笔记
    《编码的奥秘》笔记
    Effective Objective-C 2.0 — 第14条:理解“类对象“的用意
  • 原文地址:https://www.cnblogs.com/mengxingxinqing/p/3603487.html
Copyright © 2020-2023  润新知