Example #1
0
 //
 public MeterCom(SerialPortConfig config, ConnectionMultiplexer redis, Form1 form1)
 {
     comPort               = new SerialPort(config.portName, config.baudrate, config.parityCheck, config.databits, config.stopbits);
     this.redis            = redis;
     comPort.DataReceived += new SerialDataReceivedEventHandler(ComDataReceive);
     this.buffer           = new byte[1024];
     this.window           = form1;
     this.portName         = config.portName;
     this.id               = config.id;
 }
Example #2
0
        public Form1()
        {
            InitializeComponent();
            this.timer               = new System.Timers.Timer(1000 * 60);
            this.timer.Elapsed      += new ElapsedEventHandler(TimerTimeout);
            this.buffer              = new byte[1024];
            this.locker              = new Object();
            this.buttonOpen.Enabled  = true;
            this.buttonClose.Enabled = false;
            this.path             = @"D:\Work";
            this.configList       = new List <SerialPortConfig>();
            this.sattiliteComList = new List <MeterCom>();

            StreamReader sr = new StreamReader("config.csv", Encoding.UTF8);
            String       line;

            char[] chs = { ',' };
            while ((line = sr.ReadLine()) != null)
            {
                string[] items = line.Split(chs);
                //COM23,9600,None,8,1,牛栏江桥上行线7#桥墩
                SerialPortConfig config = new SerialPortConfig(items[0], items[1], items[2], items[3], items[4], items[6]);
                MeterCom         sc     = new MeterCom(config, this);
                this.configList.Add(config);
                this.sattiliteComList.Add(sc);

                ListViewItem listItem = new ListViewItem(items);
                this.listView1.Items.Add(listItem);
            }
            sr.Close();

            /*
             * chart1.Series.Add("工况瞬时流量");
             * chart1.Series["工况瞬时流量"].ChartType = SeriesChartType.Line;
             * //chart1.Series["工况瞬时流量"].IsValueShownAsLabel = true;
             *
             * chart2.Series.Add("标况瞬时流量");
             * chart2.Series["标况瞬时流量"].ChartType = SeriesChartType.Line;
             * //chart1.Series["标况瞬时流量"].IsValueShownAsLabel = true;
             *
             * chart3.Series.Add("燃气温度");
             * chart3.Series["燃气温度"].ChartType = SeriesChartType.Line;
             * //chart1.Series["燃气温度"].IsValueShownAsLabel = true;
             *
             * chart4.Series.Add("燃气绝对压力");
             * chart4.Series["燃气绝对压力"].ChartType = SeriesChartType.Line;
             * //chart1.Series["燃气温度"].YAxisType = AxisType.Secondary;
             * //chart1.Series["燃气绝对压力"].IsValueShownAsLabel = true;
             */

            //chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
        }
Example #3
0
 //
 public MeterCom(SerialPortConfig config, Form1 form1)
 {
     comPort = new SerialPort(config.portName, config.baudrate, config.parityCheck, config.databits, config.stopbits);
     comPort.DataReceived += new SerialDataReceivedEventHandler(ComDataReceive);
     comPort.ReadTimeout   = 1500;
     this.buffer           = new byte[1024];
     this.window           = form1;
     this.portName         = config.portName;
     this.period           = config.period;
     this.index            = 0;
     minuteTimer           = new System.Timers.Timer(1000 * period);
     minuteTimer.Elapsed  += new System.Timers.ElapsedEventHandler(MinuteTimer_TimesUp);
     minuteTimer.AutoReset = true; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true)
 }