MES系统通过采集OPC温湿度数据以及生产计划数据,按照设定频率进行数据刷新并投放到LED中,同时实现对LED屏幕操作控制。
public NetLedForm()
{
InitializeComponent();
}
#region 定义全局变量
ArrayList array = new ArrayList();
BusinessLogic.OpcAccessLogic opclogic = null;
BusinessLogic.CommonLogic logic = null;
//0为计划模式 1为标语模式 2 为混合模式 3简洁模式
int userSelectType99 = 2;
//贮柜信息
string mutiled = "";
string[] led = null;
DataTable temphumidt = null;
private int temphumicount = 0;
private string tempstr = "";
private string humistr = "";
private bool opcconnect = false;
#endregion
#region 窗体载入
private void NetLedForm_Load(object sender, EventArgs e)
{
// opclogic = (BusinessLogic.OpcAccessLogic)(Activator.GetObject(typeof(BusinessLogic.OpcAccessLogic), "tcp://" + getValue("OpcIp", "ServerIp") + ":8605/OpcAccessLogic"));
LBL_Mode.Text = "混合模式";
//在内存中建立一个存储温度和湿度的表
temphumidt = new DataTable();
DataColumn temphumiledno = new DataColumn();
temphumiledno.ColumnName = "Led屏";
temphumiledno.DataType = typeof(string);
temphumidt.Columns.Add(temphumiledno);
DataColumn tempcolumn = new DataColumn();
tempcolumn.ColumnName = "温度";
tempcolumn.DataType = typeof(string);
temphumidt.Columns.Add(tempcolumn);
DataColumn humicolumn = new DataColumn();
humicolumn.ColumnName = "湿度";
humicolumn.DataType = typeof(string);
temphumidt.Columns.Add(humicolumn);
mutiled = getValue("SumLed", "Sum");
led = mutiled.Split(',');
foreach (string str in led)
{
//初始化温度
string temperature = getValue(str, "temperature");
string humidity = getValue(str, "humidity");
if (temperature != "" && humidity != "")
{
tempstr += temperature + ",";
humistr += humidity + ",";
}
}
if (tempstr != "" && humistr != "")
{
tempstr = tempstr.Substring(0, tempstr.LastIndexOf(','));
humistr = humistr.Substring(0, humistr.LastIndexOf(','));
string allstr = tempstr + "," + humistr;
temphumicount = allstr.Split(',').Length;
try
{
////if (opclogic.NetLinkServer(getValue("OpcServer", "Opc"), getValue("NodeName", "Node")))
////{
//// opcconnect = true;
//// opclogic.InitItem(allstr.Split(','));
////}
////else
////{
//// MessageBox.Show("无法连接到空调服务器(" + getValue("NodeName", "Node") + ")\n" + "空调数据将不会显示");
//// //return;
////}
}
catch (Exception opcexe)
{
MessageBox.Show("无法连接到空调服务器(" + getValue("NodeName", "Node") + ")\n错误信息:" + opcexe.Message);
//return;
}
//获取温湿度信息
OpcDataCollect();
if (Ping(getValue("99", "ip")))
{
SetScreenParm(getValue("99", "ip"), 704, 288);
SetScreenParm(getValue("98", "ip"), 704, 288);
SendScreen();
}
}
}
#endregion
#region 函数读取配置某项值
private string getValue(string screen, string tagname)
{
string tagValue = "";
XmlDocument xmlDoc = new XmlDocument();
string strFileName = "C:\\NETLED\\Led.xml";
xmlDoc.Load(strFileName);
XmlNodeList nodeList = xmlDoc.SelectSingleNode("app").ChildNodes;
foreach (XmlNode xn in nodeList)
{
XmlElement xe = (XmlElement)xn;
if (xe.GetAttribute("name").Contains(screen))
{
XmlNodeList nls = xe.ChildNodes;
foreach (XmlNode xnnode in nls)
{
XmlElement xechildnode = (XmlElement)xnnode;
if (xechildnode.Name == tagname)
{
tagValue = xechildnode.InnerText;
}
}
break;
}
}
return tagValue;
}
#endregion
#region 绘制屏幕图片
private void GetPlanDrawBmp()
{
try
{
//获取今日计划
if (Directory.Exists("C:\\NETLED\\Plan99\\"))
{
Directory.Delete("C:\\NETLED\\Plan99\\", true);
}
Directory.CreateDirectory("C:\\NETLED\\Plan99\\");
DataTable dtbz = new DataTable();
string strsqlbz = "select MACHINESHORTNAME,PRODUCTNAME,TOTALPRODUCTION,STATUSNAME ,PRODUCTIONTYPE,CLASSNAME from mv_led_gd102data order by MACHINESHORTNAME ";
dtbz = Select(strsqlbz);
drawString(99, temphumidt, dtbz, 991);
DataTable dtjb = new DataTable();
string strsqljb = "select MACHINESHORTNAME,PRODUCTNAME,TOTALPRODUCTION,STATUSNAME,PRODUCTIONTYPE,CLASSNAME from mv_led_pt102data order by MACHINESHORTNAME";
dtjb = Select(strsqljb);
drawString(99, temphumidt, dtjb, 992);
}
catch (Exception)
{
throw;
}
}
#endregion
#region LED屏幕连接函数
//设定屏幕参数
private bool SetScreenParm(string iptext, int width, int height)
{
try
{
int nreturn;
userSetScreenParameter(1, width, height, 2, 2, 0, 0, 0, 0, 2, "ParametetData1");
//如果设置显示屏参数失败请将点阵类型改为2
nreturn = userSendTCPIPData(iptext, 5005, 193, width, height, 2, "ParametetData1");
if (nreturn == 0)
return true;
else
return false;
}
catch (Exception)
{
throw;
}
}
//发送屏幕信息
private bool SendScreenMes(int m_screenno, ArrayList fn, int showTime, int width, int height, int nWeek)
{
try
{
string iptext = "";
int nreturn;
int nreturn1;
userGetAllDataHead(1, 1, "SendAllDataHead1");
userUnionAreaDataToFile("SendAllDataHead1", "SendAllData1", 1);
userGetProgramHead(0, 3, 0, 10, 0x7F, 8, 0, 0, 20, 0, 0, "ProgramHead1");
userUnionAreaDataToFile("ProgramHead1", "SendAllData1", 0);
//发送系统时间区域
userSetScreenDateTime(0, 3, 450, 28, "宋体", 16, 1, "", 1, 1, 0, 0, 1, 1, nWeek, 1, 1, 1, 0, "SendDateTime");
userUnionAreaDataToFile("SendDateTime", "SendAllData1", 0);
iptext = getValue(m_screenno.ToString(), "ip");
string strTemp = GetTemp(99);
//发送温湿度区域
userSetScreenTitle(430, 0, 451, 28, 2, 2, "宋体", 16, 1, 0, 0, 0, strTemp, 1, 200, 200, "STitle1");
userUnionAreaDataToFile("STitle1", "SendAllData1", 0);
//发送屏幕图片区域
for (int i = 0; i < fn.Count; i++)
{
if (i == 0)
{
userSetScreenBmpText(0, 29, width, 258, 2, 2, fn[i].ToString(), 0, 1, 10, showTime, "Sbmp", 1);
}
else
{
userSetScreenBmpText(0, 29, width, 258, 2, 2, fn[i].ToString(), 0, 1, 10, showTime, "Sbmp", 0);
}
}
userUnionAreaDataToFile("Sbmp", "SendAllData1", 0);
userGetCurDataTime("CurTimeData1");
userUnionAreaDataToFile("CurTimeData1", "SendAllData1", 0);
nreturn = userSendTCPIPData(iptext, 5005, 209, width, height, 2, "SendAllData1");
nreturn1 = userSendTCPIPData(getValue("98", "ip"), 5005, 209, width, height, 2, "SendAllData1");
if (nreturn == 0)
return true;
else
return false;
}
catch (Exception)
{
throw;
}
}
完成项目代码:https://download.csdn.net/download/bjhtgy/89678216