You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
295 lines
10 KiB
295 lines
10 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
using DBFactory;
|
|
using CommonLib;
|
|
using System.Threading;
|
|
|
|
namespace WcfControlMonitorLib
|
|
{
|
|
public static class CUpdateIoControl
|
|
{
|
|
static Thread mythread;
|
|
static Thread mythreadDarkCasket;
|
|
static bool exitThread = false;//20091107
|
|
static bool exitThreadDarkCasket = false;
|
|
static string _CUpdateIoControlError = "";//监控调度类错误说明
|
|
|
|
public static string CUpdateIoControlError
|
|
{
|
|
get { return _CUpdateIoControlError; }
|
|
set { _CUpdateIoControlError = value; }
|
|
}
|
|
public static event RefreshMonitorEventHandler RefreshMonitor;
|
|
public static void OnRefreshMonitor(RefreshMonitorEventArgs e)
|
|
{
|
|
if (RefreshMonitor != null)
|
|
{
|
|
RefreshMonitor(e);
|
|
}
|
|
}
|
|
static StringBuilder temp = new StringBuilder();
|
|
static DBOperator dbo = new DBOperator();
|
|
static DBOperator dboM1 = CStaticClass.dboM1;
|
|
static DBOperator dbo1 = CStaticClass.dbo1;
|
|
static object lockThis = new object();
|
|
static object lockThisDarkCasket = new object();
|
|
public static List<string> sql = new List<string>();
|
|
private static void BeginListen()
|
|
{//20091107
|
|
while (!exitThread)
|
|
{
|
|
try
|
|
{
|
|
lock (lockThis)
|
|
{
|
|
// 更新状态方法 add for YB5
|
|
RunSql();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_CUpdateIoControlError = ex.StackTrace + ex.Message;
|
|
}
|
|
finally
|
|
{
|
|
Thread.Sleep(200);
|
|
}
|
|
}
|
|
|
|
}
|
|
private static void BeginListenDarkCasket()
|
|
{//20091107
|
|
while (!exitThreadDarkCasket)
|
|
{
|
|
try
|
|
{
|
|
lock (lockThisDarkCasket)
|
|
{//20130226richard.liu
|
|
RunDark();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_CUpdateIoControlError = ex.StackTrace + ex.Message;
|
|
}
|
|
finally
|
|
{
|
|
Thread.Sleep(200);
|
|
}
|
|
}
|
|
//if (mythread != null && exitThread == true)
|
|
//{
|
|
|
|
// mythread.Abort();
|
|
// mythread = null;
|
|
//}
|
|
}
|
|
|
|
public static void EndListen()
|
|
{
|
|
|
|
//if (sql.Count == 0)
|
|
//{
|
|
// exitThread = true;
|
|
// if (mythread != null)
|
|
// {
|
|
// mythread.Abort();
|
|
// mythread = null;
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
// if (mythread == null)
|
|
// {
|
|
// mythread = new Thread(new ThreadStart(BeginListen));
|
|
// mythread.IsBackground = true;
|
|
// mythread.Start();
|
|
// while (true)
|
|
// {
|
|
// if (sql.Count == 0)
|
|
// {
|
|
// exitThread = true;
|
|
// mythread.Abort();
|
|
// mythread = null;
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// while (true)
|
|
// {
|
|
// if (sql.Count == 0)
|
|
// {
|
|
// exitThread = true;
|
|
// mythread.Abort();
|
|
// mythread = null;
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//}
|
|
|
|
if (CommonClassLib.CCarryConvert.dark.Count == 0)
|
|
{
|
|
exitThreadDarkCasket = true;
|
|
if (mythreadDarkCasket != null)
|
|
{
|
|
mythreadDarkCasket.Abort();
|
|
mythreadDarkCasket = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (mythreadDarkCasket == null)
|
|
{
|
|
mythreadDarkCasket = new Thread(new ThreadStart(BeginListenDarkCasket));
|
|
mythreadDarkCasket.IsBackground = true;
|
|
mythreadDarkCasket.Start();
|
|
while (true)
|
|
{
|
|
if (CommonClassLib.CCarryConvert.dark.Count == 0)
|
|
{
|
|
exitThreadDarkCasket = true;
|
|
mythreadDarkCasket.Abort();
|
|
mythreadDarkCasket = null;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while (true)
|
|
{
|
|
if (CommonClassLib.CCarryConvert.dark.Count == 0)
|
|
{
|
|
exitThreadDarkCasket = true;
|
|
mythreadDarkCasket.Abort();
|
|
mythreadDarkCasket = null;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
public static void StartListen()
|
|
{
|
|
|
|
//exitThread = false;
|
|
//mythread = new Thread(new ThreadStart(BeginListen));
|
|
//mythread.IsBackground = true;
|
|
//mythread.Start();
|
|
|
|
exitThreadDarkCasket = false;
|
|
mythreadDarkCasket = new Thread(new ThreadStart(BeginListenDarkCasket));
|
|
mythreadDarkCasket.IsBackground = true;
|
|
mythreadDarkCasket.Start();
|
|
|
|
}
|
|
public static void RunSql()
|
|
{
|
|
|
|
if (sql.Count > 0)
|
|
{
|
|
for (int i = 0; i < sql.Count; i++)
|
|
{
|
|
try
|
|
{
|
|
// 7 10 11
|
|
if (sql[i].IndexOf("CONTROL_STATUS=10") >= 0)
|
|
{
|
|
temp.Remove(0, temp.Length);
|
|
temp.Append("select CONTROL_STATUS from io_control where CONTROL_ID=").Append(sql[i].Split('|')[1]);
|
|
int a = Convert.ToInt32(dboM1.GetSingle(temp.ToString()));
|
|
if (a != 10 && a != 999)
|
|
{
|
|
dboM1.ExecuteSql(sql[i].Split('|')[0]);
|
|
}
|
|
}// 233 add FOR CATL YB5
|
|
else if (sql[i].IndexOf("CONTROL_STATUS=11") >= 0)
|
|
{
|
|
temp.Remove(0, temp.Length);
|
|
temp.Append("select CONTROL_STATUS from io_control where CONTROL_ID=").Append(sql[i].Split('|')[1]);
|
|
int c = Convert.ToInt32(dboM1.GetSingle(temp.ToString()));
|
|
if (c != 11 && c != 999)
|
|
{
|
|
dboM1.ExecuteSql(sql[i].Split('|')[0]);
|
|
}
|
|
}
|
|
else if (sql[i].IndexOf("SET ERROR_TEXT =''") >= 0)
|
|
{
|
|
//add for CATL YB5
|
|
temp.Remove(0, temp.Length);
|
|
temp.Append("select ERROR_TEXT from io_control where CONTROL_ID=").Append(sql[i].Split('|')[1]);
|
|
//object cc = 0;
|
|
//cc = dboM1.GetSingle(temp.ToString());
|
|
//if (cc== "" || cc == null || cc == string.Empty )
|
|
//{
|
|
object b = dboM1.GetSingle(temp.ToString());
|
|
if (b != "" && b != null && b != string.Empty)
|
|
{
|
|
dboM1.ExecuteSql(sql[i].Split('|')[0]);
|
|
}
|
|
// }
|
|
}
|
|
else
|
|
{
|
|
dboM1.ExecuteSql(sql[i].Split('|')[0]);
|
|
}
|
|
//dbo1.ExecuteSql("insert into test(T1) values('" + sql[i].ToString() + "')");
|
|
|
|
}
|
|
catch (Exception exa)
|
|
{
|
|
|
|
_CUpdateIoControlError = string.Format("解析PLC反馈数据的记录设备状态时发生错误:{0}", exa.StackTrace + exa.Message);
|
|
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", _CUpdateIoControlError);
|
|
OnRefreshMonitor(rmea);
|
|
}
|
|
finally
|
|
{
|
|
sql.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void RunDark()
|
|
{
|
|
|
|
if (CommonClassLib.CCarryConvert.dark.Count > 0)
|
|
{
|
|
for (int i = 0; i < CommonClassLib.CCarryConvert.dark.Count; i++)
|
|
{
|
|
try
|
|
{
|
|
if (CommonClassLib.CCarryConvert.dark[i] == null) { break; }
|
|
string[] aaa = CommonClassLib.CCarryConvert.dark[i].ToString().Split('|');
|
|
CommonClassLib.CCarryConvert.kkk(aaa[0], aaa[1], aaa[2], aaa[3]);
|
|
//dbo1.ExecuteSql("insert into test(T1) values('" + sql[i].ToString() + "')");
|
|
|
|
}
|
|
catch (Exception exa)
|
|
{
|
|
|
|
_CUpdateIoControlError = string.Format("解析PLC反馈数据的记录设备状态时发生错误:{0}", exa.StackTrace + exa.Message);
|
|
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", _CUpdateIoControlError);
|
|
OnRefreshMonitor(rmea);
|
|
}
|
|
finally
|
|
{
|
|
CommonClassLib.CCarryConvert.dark.RemoveAt(i);//i移除,i後面的都往前移了
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|