最近自己接触到的知识有些杂乱。最近涉及到了PLC的自动化控制、煤气柜位预测等方面的内容。PLC的学习目前中断了一阵子,最近接触了柜位预测的相关算法——神经网络、最小二乘法等相关的算法。今天先简单介绍一下,自己做的一个煤气柜位曲线显示的小demo,相关的算法的实现将在以后学习研究介绍吧。
1、界面曲线显示
我选择采用C#来进行实时曲线的显示,C#报表控件有很多,经过比较,在实时显示曲线上C#的开源库zedgraph控件是性能最好的,下面是我的实时曲线显示的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using IGAI.Util.Excel;
namespace ZedGraphExcelTest
{
public partial class Form1 : Form
{
ExcelRead read;
int count = 0;
public Form1()
{
InitializeComponent();
this.timeDraw.Tick += new EventHandler(timeDraw_Tick);
read = new ExcelRead();
}
private void Form1_Load(object sender, EventArgs e)
{
//获取引用
GraphPane myPane = zgc.GraphPane;
//设置标题
myPane.Title.Text = "实时曲线";
//设置X轴说明文字
myPane.XAxis.Title.Text = "时间";
//设置Y轴说明文字
myPane.YAxis.Title.Text = "柜位";
RollingPointPairList list = new RollingPointPairList(86400);
//开始,增加的线是没有数据点的(也就是list为空)
//增加一条名称:Voltage,颜色Color.Red,无符号,无数据的空线条
LineItem curve = myPane.AddCurve("柜位", list, Color.Red, SymbolType.None);
timeDraw.Interval = 50; //设置timer控件的间隔为50毫秒
timeDraw.Enabled = true; //timer可用
timeDraw.Start();
DateTime t1 = new DateTime(2014, 06, 01);
DateTime t2 = new DateTime(2014, 06, 02);
double min = new XDate(t1);
double max = new XDate(t2);
myPane.XAxis.Scale.Min = min;
myPane.XAxis.Scale.Max = max;
myPane.XAxis.Scale.MinorStep = (max - min) / 24; //小刻度是1小时
myPane.XAxis.Scale.MajorStep = (max - min) / 6; //大刻度是4小时
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Format = "yyyy-MM-dd\nHH:mm:ss";
//改变轴的刻度
zgc.AxisChange();
read.initExcelDrive("test.xls", "30万气柜");
}
private void timeDraw_Tick(object sender, EventArgs e)
{
//确保CurveList不为空
if (zgc.GraphPane.CurveList.Count <= 0)
{
return;
}
//取Graph第一个曲线,也就是第一步:在GraphPane.CurveList集合中查找CurveItem
LineItem curve = zgc.GraphPane.CurveList[0] as LineItem;
if (curve == null)
{
return;
}
//第二步:在CurveItem中访问PointPairList(或者其它的IPointList),根据自己的需要增加新数据或修改已存在的数据
IPointListEdit list = curve.Points as IPointListEdit;
if (list == null)
{
return;
}
DateTime time = new DateTime();
Double value = -1;
if (read.isHasData())
{
time = read.getExcelDataDateTime(0);
value = read.getExcelData(1);
}
XDate max= new XDate(time);
XDate min = new XDate(time.AddDays(-1));
Scale xScale = zgc.GraphPane.XAxis.Scale;
if (max>= xScale.Max)
{
xScale.Max = xScale.Max + xScale.MajorStep;
xScale.Min = xScale.Min + xScale.MajorStep;
}
list.Add(max, value);
if (value != -1)
{
//第三步:调用ZedGraphControl.AxisChange()方法更新X和Y轴的范围
zgc.AxisChange();
//第四步:调用Form.Invalidate()方法更新图表
zgc.Invalidate();
}
}
private void Form1_Resize(object sender, EventArgs e)
{
SetSize();
}
private void SetSize()
{
// 控制始终是以10像素插入矩形从客户端的形
Rectangle formRect = this.ClientRectangle;
formRect.Inflate(-10, -10);
if (zgc.Size != formRect.Size)
{
zgc.Location = formRect.Location;
zgc.Size = formRect.Size;
}
}
}
}
2.读取Excel数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
namespace IGAI.Util.Excel
{
public class ExcelRead
{
private OleDbDataReader dataReader;
private OleDbConnection oleDbConnection;
public ExcelRead()
{
}
~ExcelRead()
{
clearExcelDrive();
}
public bool initExcelDrive(string excelFilePath,string sheetName)
{
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + excelFilePath + ";Extended Properties=Excel 8.0;";
dataReader = null;
oleDbConnection = new OleDbConnection(strConn);
OleDbCommand myOleDbCommand = new OleDbCommand("SELECT * FROM ["+sheetName+"$]", oleDbConnection);
try
{
oleDbConnection.Open();
dataReader = myOleDbCommand.ExecuteReader();
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
}
}
public bool isHasData()
{
return dataReader.Read();
}
public Object getExcelVaule(int colNum)
{
return dataReader.GetValue(colNum);
}
public Double getExcelData(int colNum)
{
return dataReader.GetDouble(colNum);
}
public String getExcelDataString(int colNum)
{
return dataReader.GetString(colNum);
}
public DateTime getExcelDataDateTime(int colNum)
{
return dataReader.GetDateTime(colNum);
}
public TimeSpan getExcelTimeSpan(int colNum)
{
return dataReader.GetTimeSpan(colNum);
}
public bool clearExcelDrive()
{
if (dataReader != null)
dataReader.Close();
// Close the connection when done with it.
if (oleDbConnection != null && oleDbConnection.State == System.Data.ConnectionState.Open)
oleDbConnection.Close();
return true;
}
}
}
3.普及一下钢铁企业煤气小知识
焦炉煤气(COG)是钢铁炼焦过程的副产品"炼焦是煤在焦炉炭化室内经过加热干馏转化为焦炭及焦炉煤气的工艺过程"根据炼焦时炉温把其分为高温炼焦!中温炼焦和低温炼焦"通常炼焦都是高温炼焦"煤在炼焦时产生的煤气是煤的组成物质在高温分解时的产品"煤在隔绝空气的情况下逐渐加热时形成煤气的过程为:
第一阶段是煤的基本物质的分解"主要产生一氧化碳(CO)和二氧化碳(coZ),因此这段时间产生的COG的主要成分是CO和COZ"这段时间的炉温和COG的产出量与煤的品质有很大的关系"第一阶段终持续到温度为400e,此时逸出的煤气量占正常炼焦产生的煤气总量的很少部分"
第二阶段即从第一阶段结束到炉温为550e这段时间,这阶段会产生大量的煤气"煤在这阶段内产生的煤焦油,由于炉内的高温进一步分解,变成高温炼焦的焦油并同时产生煤气;这部分煤气主要是由氢气和许多碳氢!碳氧化合物所组成,而且是原焦油分解的最终产物之一"
第三阶段是把第二阶段生成的半焦炭继续加热直到生成最终需要的产物一焦炭"这期间煤气的溢出比较均匀,其体积约为炼焦煤气总量的40%,这阶段产生的煤气主要是氢以及氢的化合物这主要是由第二阶段产生的半焦炭分解得到的"。
高炉煤气(BFG Blast Furnace Gas),高炉炼铁时的副产品,热值低。
转炉煤气(LDG是Linz—Donawitz Process Gas),高炉炼钢时的副产品。
4.本程序的小问题
1)本demo运行后如下图:

2)在横坐标轴滚动大下一天时,会出现如下三幅图所示:



这个是本demo的小bug,目前还未找出原因,您如果知道的话,希望给下回复,谢谢了
















