SCLS/SSWCS_JXDL(2019)/ControlSystem/CParsePLCData.cs

883 lines
39 KiB
C#
Raw Permalink Normal View History

2025-05-19 09:45:29 +08:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBFactory;
using System.Threading;
namespace ControlSystem
{
/// <summary>
/// Creator:Richard.liu
/// <20><><EFBFBD><EFBFBD>PLC<4C><43><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public static class CParsePLCData
{
static int[] AllReturns;//20110216
/// <summary>
/// 20110216<31><36><EFBFBD><EFBFBD>S7Connection<6F><6E>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DB1<42><31><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="sb">S7Connection<6F><6E>ʶ</param>
/// <returns></returns>
public static Model.MDevice GetDevice28AllDB1Data(StringBuilder sb)
{
DataView dv = dbo.ExceSQL("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_DeviceKindIndex = 28 and F_S7Connection='"+sb.ToString()+"')").Tables[0].DefaultView;
if (dv.Count > 0)
{
return Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(dv[0]["F_DeviceIndex"]));
}
else
{
return null;
}
}
static StringBuilder sql = new StringBuilder();
static char[] dd = new char[1] { '.' };//20101124
static string[] sp ;//20101124
static string _CParsePLCError = "";//<2F><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>
public static string CParsePLCError
{
get { return _CParsePLCError; }
set { _CParsePLCError = value; }
}
static DBOperator dbo = new DBOperator();
static DBOperator dboRoute = new DBOperator();
static DBOperator dboMan = new DBOperator("ManConnString", "ManDBFactory");
static Model.MDevice devinfo28 = Model.CGetInfo.GetDeviceInfo(65534);
//static Thread mythreadRoute;
static Thread mythread;
static bool exitThread = false;//20091107
private static void BeginListen()
{//20091107
while (!exitThread )
{
try
{
SetDeviceState();
}
catch (Exception ex)
{
_CParsePLCError = ex.Message;
}
Thread.Sleep(200);//20100710
}
}
public static void EndListen()
{//20091107
exitThread = true;
if (mythread != null)
{
mythread.Abort();
mythread = null;
}
}
public static void StartListen()
{
//20091107
exitThread = false;
mythread = new Thread(new ThreadStart(BeginListen));
mythread.IsBackground = true;
mythread.Start();
//mythreadRoute = new Thread(new ThreadStart(BeginListenRoute));
//mythreadRoute.IsBackground = true;
//mythreadRoute.Start();
}
/// <summary>
/// ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>ȷ<EFBFBD>ϰ<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA>0<EFBFBD><30>1<EFBFBD><31>
/// </summary>
/// <param name="deviceIdx"><3E><EFBFBD><E8B1B8><EFBFBD><EFBFBD></param>
/// <returns>0<><30>1</returns>
public static int GetDevicePhotoelectric(int deviceIdx)
{
try
{
//20110216
AllReturns = CStaticClass.MutiS7ConnReturns[GetDeviceS7Connection(deviceIdx)];
if (AllReturns != null)
{
#region <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
sql.Remove(0, sql.Length);
sql.Append("SELECT F_DeviceIndex, F_DeviceKindIndex,F_DBWGetLength," ).Append(
" F_DBW2Address,F_S7Connection FROM T_Base_Device WHERE ((F_DeviceKindIndex = 14)" ).Append(
" OR (F_DeviceKindIndex = 18)) and (F_DBW2Address is not NULL) and F_DeviceIndex=" ).Append( deviceIdx);
DataView dvle = dbo.ExceSQL( sql.ToString()).Tables[0].DefaultView;
//devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
int glen = 0;
int IfVis = 0;
if (dvle.Count>0)//(devinfo.DeviceKind == 14) || (devinfo.DeviceKind == 18)
{
//20110216
devinfo28 =GetDevice28AllDB1Data(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
int temp = Convert.ToInt32(dvle[0]["F_DBW2Address"]) - devinfo28.Dbw2Address;
if (Convert.ToInt32((Convert.ToDecimal(dvle[0]["F_DBWGetLength"]) * 8 - 1)) > 7)//devinfo.Dbw2Getlength
{
glen = Convert.ToInt32((Convert.ToDecimal(dvle[0]["F_DBWGetLength"]) * 8 - 1)) - 8;
temp = temp + 1;
}
else
{
glen = Convert.ToInt32((Convert.ToDecimal(dvle[0]["F_DBWGetLength"]) * 8 - 1));
}
if (temp >= 0)
{
IfVis = CommonClassLib.CCarryConvert.GetBitFromInteger(AllReturns[temp], glen);
//if (dvle[0]["F_DeviceKindIndex"].ToString() == "18")
//{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7BFAA>0<EFBFBD><30>̽<EFBFBD>1<EFA3AC><31>̽<EFBFBD><EFBFBD><EFA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD>
// if (IfVis == 1)
// {
// IfVis = 0;
// }
// else
// {
// IfVis = 1;
// }
//}
return IfVis;
}
else
{
return -1;
}
}
else
{
return -1;
}
#endregion
}
else
{
return -1;
}
}
catch //(Exception ex)
{
//if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ź<EFBFBD>ʱ<EFBFBD><CAB1>" + ex.Message) < 0)
//{
// FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ź<EFBFBD>ʱ<EFBFBD><CAB1>" + ex.Message, true);
//}
return -1;
}
}
/// <summary>
/// 20101118<31><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>bitλ<74><CEBB>ȡ<EFBFBD><C8A1>F_SplitByte<74><65><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD>bitֵ<74><D6B5>0,1
/// </summary>
/// <param name="deviceIdx"></param>
/// <param name="bit"></param>
/// <returns></returns>
public static int GetDevicePhotoelectric(int deviceIdx, int abit)
{
try
{
//20110216
AllReturns = CStaticClass.MutiS7ConnReturns[GetDeviceS7Connection(deviceIdx)];
if (AllReturns != null)
{
#region <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
sql.Remove(0, sql.Length);
sql.Append("SELECT F_SplitByte,F_S7Connection FROM T_Base_Device WHERE F_DeviceIndex=").Append(deviceIdx).Append(" and F_SplitByte>=0");
DataView dvle = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
int glen = 0;
int IfVis = 0;
if (dvle.Count > 0)
{
//20110216
devinfo28 =GetDevice28AllDB1Data(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
int temp = Convert.ToInt32(dvle[0]["F_SplitByte"]) - devinfo28.Dbw2Address;
if (abit > 7)
{
glen = abit - 8;
temp = temp + 1;
}
else
{
glen = abit;
}
if (temp >= 0)
{
IfVis = CommonClassLib.CCarryConvert.GetBitFromInteger(AllReturns[temp], glen);
//if (dvle[0]["F_DeviceKindIndex"].ToString() == "18")
//{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7BFAA>0<EFBFBD><30>̽<EFBFBD>1<EFA3AC><31>̽<EFBFBD><EFBFBD><EFA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD>
// if (IfVis == 1)
// {
// IfVis = 0;
// }
// else
// {
// IfVis = 1;
// }
//}
return IfVis;
}
else
{
return -1;
}
}
else
{
return -1;
}
#endregion
}
else
{
return -1;
}
}
catch
{
return -1;
}
}
/// <summary>
/// //20101124<32><34><EFBFBD>ݡ<EFBFBD><DDA1><EFBFBD><E8B1B8>.bitλ<74><CEBB><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>F_SplitByte<74><65><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD>bitֵ<74><D6B5>0,1
/// </summary>
/// <param name="deviceIdx"></param>
/// <param name="bit"></param>
/// <returns></returns>
public static int GetDevicePhotoelectric(string devicebit)
{
sp = devicebit.Split(dd);
if (sp.GetLength(0) <= 1) return -1;
int deviceIdx, abit;
int.TryParse(sp[0], out deviceIdx);
int.TryParse(sp[1], out abit);
try
{
//20110216
AllReturns = CStaticClass.MutiS7ConnReturns[GetDeviceS7Connection(deviceIdx)];
if (AllReturns != null)
{
#region <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
sql.Remove(0, sql.Length);
sql.Append("SELECT F_SplitByte,F_S7Connection FROM T_Base_Device WHERE F_DeviceIndex=").Append(deviceIdx).Append(" and F_SplitByte>=0");
DataView dvle = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
int glen = 0;
int IfVis = 0;
if (dvle.Count > 0)
{
//20110216
devinfo28 = GetDevice28AllDB1Data(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
int temp = Convert.ToInt32(dvle[0]["F_SplitByte"]) - devinfo28.Dbw2Address;
if (abit > 7)
{
glen = abit - 8;
temp = temp + 1;
}
else
{
glen = abit;
}
if (temp >= 0)
{
IfVis = CommonClassLib.CCarryConvert.GetBitFromInteger(AllReturns[temp], glen);
//if (dvle[0]["F_DeviceKindIndex"].ToString() == "18")
//{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7BFAA>0<EFBFBD><30>̽<EFBFBD>1<EFA3AC><31>̽<EFBFBD><EFBFBD><EFA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD>
// if (IfVis == 1)
// {
// IfVis = 0;
// }
// else
// {
// IfVis = 1;
// }
//}
return IfVis;
}
else
{
return -1;
}
}
else
{
return -1;
}
#endregion
}
else
{
return -1;
}
}
catch (Exception ex)
{
if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf(<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ź<EFBFBD>ʱ<EFBFBD><CAB1>" + ex.Message) < 0)
{
FrmControlMonitor.FormInstance.FlashPanit("tsStatus", <><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ź<EFBFBD>ʱ<EFBFBD><CAB1>" + ex.Message, true);
}
return -1;
}
}
/// <summary>
/// ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸״̬:[0]<5D><>д<EFBFBD><D0B4>־;[1]״̬;[2]<5D><><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>[3]X<><58><EFBFBD><EFBFBD>;[4]Y<><59><EFBFBD><EFBFBD>;[5]<5D><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
/// </summary>
/// <param name="deviceIdx"><3E><EFBFBD><E8B1B8><EFBFBD><EFBFBD></param>
/// <returns></returns>
public static int[] GetDeviceState(int deviceIdx)
{
try
{
//20110216
AllReturns = CStaticClass.MutiS7ConnReturns[GetDeviceS7Connection(deviceIdx)];
if (AllReturns != null)
{
#region <EFBFBD><EFBFBD>ȡ<EFBFBD>״̬
sql.Remove(0, sql.Length);
sql.Append("SELECT F_DeviceIndex, F_DeviceKindIndex,F_DBWGetLength," ).Append(
" F_DBW2Address,F_S7Connection FROM T_Base_Device WHERE (F_DBW2Address is not NULL) and F_DeviceIndex=").Append(deviceIdx);
DataView dvle = dbo.ExceSQL( sql.ToString()).Tables[0].DefaultView;
//devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
if (dvle.Count>0)//devinfo.Dbw2Address != -1
{
//20110216
devinfo28 =GetDevice28AllDB1Data(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
int temp = Convert.ToInt32(dvle[0]["F_DBW2Address"]) - devinfo28.Dbw2Address;//devinfo.Dbw2Address
decimal glen = Convert.ToDecimal(dvle[0]["F_DBWGetLength"]);//devinfo.Dbw2Getlength
int[] states = new int[6];
switch (dvle[0]["F_DeviceKindIndex"].ToString())//devinfo.DeviceKind.ToString()
{
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case "1"://<2F>Ѷ<EFBFBD><D1B6><EFBFBD>
//states[0] = AllReturns[temp];//<2F><>д<EFBFBD><D0B4>־
//states[1] = AllReturns[temp + 1];//״̬
//states[2] = (AllReturns[temp + 2] << 8) + AllReturns[temp + 3];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//states[3] = AllReturns[temp + 7] + (AllReturns[temp + 6] << 8) + (AllReturns[temp + 5] << 16) + (AllReturns[temp + 4] << 32);//X<><58><EFBFBD><EFBFBD>
//states[4] = AllReturns[temp + 11] + (AllReturns[temp + 10] << 8) + (AllReturns[temp + 9] << 16) + (AllReturns[temp + 8] << 32);//Y<><59><EFBFBD><EFBFBD>
//states[5] = deviceIdx;//<2F><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
states[0] = AllReturns[temp];//<2F><>д<EFBFBD><D0B4>־
states[1] = AllReturns[temp + 1];//״̬
states[2] = (AllReturns[temp + 2] << 8) + AllReturns[temp + 3];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
states[3] = AllReturns[temp + 7] + (AllReturns[temp + 6] << 8) + (AllReturns[temp + 5] << 16) + (AllReturns[temp + 4] << 32);//X<><58><EFBFBD><EFBFBD>
//states[4] = AllReturns[temp + 11] + (AllReturns[temp + 10] << 8) + (AllReturns[temp + 9] << 16) + (AllReturns[temp + 8] << 32);//Y<><59><EFBFBD><EFBFBD>
states[4] = AllReturns[temp + 8] + AllReturns[temp + 9] + AllReturns[temp + 10] + AllReturns[temp + 11];//Y<><59><EFBFBD><EFBFBD>
states[5] = deviceIdx;//<2F><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
case "2"://<2F><><EFBFBD>ͻ<EFBFBD>
states[0] = AllReturns[temp];//<2F><>д<EFBFBD><D0B4>־
states[1] = AllReturns[temp + 1];//״̬
states[2] = (AllReturns[temp + 2] << 8) + AllReturns[temp + 3];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
states[3] = 0;
states[4] = 0;
states[5] = deviceIdx;//<2F><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
case "4"://RGV
states[0] = AllReturns[temp];//<2F><>д<EFBFBD><D0B4>־
states[1] = AllReturns[temp + 1];//״̬
states[2] = (AllReturns[temp + 2] << 8) + AllReturns[temp + 3];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
states[3] = AllReturns[temp + 7] + (AllReturns[temp + 6] << 8) + (AllReturns[temp + 5] << 16) + (AllReturns[temp + 4] << 32);//X<><58><EFBFBD><EFBFBD>
states[4] = 0;
states[5] = deviceIdx;//<2F><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
#endregion
}
return states;
}
else
{
return null;
}
#endregion
}
else
{
return null;
}
}
catch //(Exception ex)
{
//if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ź<EFBFBD>ʱ<EFBFBD><CAB1>" + ex.Message) < 0)
//{
// FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "ȡ<><C8A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ź<EFBFBD>ʱ<EFBFBD><CAB1>" + ex.Message, true);
//}
return null;
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ǰ<EFBFBD><C7B0>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
/// </summary>
public static void SetDeviceState()
{
try
{
bool updateroute = false;
if (CStaticClass.routetime.AddSeconds(30) <= DateTime.Now)
{
updateroute = true;
CStaticClass.routetime = DateTime.Now;
}
int[] States;
foreach (Model.MDevice devinfo1 in Model.CGetInfo.DeviceInfo.Values)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_LockedState = - 1) and F_DeviceIndex=" ).Append( devinfo1.DeviceIndex );
DataView dvv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvv.Count > 0)
{
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, 98);
AlterRoute(devinfo1.DeviceIndex, 98);
}
//20090926
if (devinfo1.ErrorCode != 98)
{
UpdateErrorCode(devinfo1.DeviceIndex, 98);
AlterRoute(devinfo1.DeviceIndex, 98);
devinfo1.RunState = 4;
}
devinfo1.ErrorCode = 98;
}
else
{
if ((devinfo1.DeviceKind == 14) || (devinfo1.DeviceKind == 18))
{
devinfo1.DeviceVisual = GetDevicePhotoelectric(devinfo1.DeviceIndex);
continue;
}
if ((devinfo1.DeviceKind == 2) || (devinfo1.DeviceKind == 3) || (devinfo1.DeviceKind == 5) || (devinfo1.DeviceKind == 17))
{
//<2F><>Щ<EFBFBD><D0A9><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>·<EFBFBD><C2B7><EFBFBD>д<EFBFBD><D0B4>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ƣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>к͹<D0BA><CDB9><EFBFBD>λ<EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD><EFBFBD><EFBFBD>
if (devinfo1.OnlyDetectIO == "1")
{
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+7<EFBFBD><EFBFBD>
devinfo1.RunState = GetDevicePhotoelectric(Convert.ToInt32(devinfo1.DeviceIndex.ToString() + "7"));
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, 0);
AlterRoute(devinfo1.DeviceIndex, 0);
}
if (devinfo1.ErrorCode != 0)
{
AlterRoute(devinfo1.DeviceIndex, 0);
}
//20090926
int err = 0;
//devinfo1.ErrorCode = 0;
#endregion
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+6<EFBFBD><EFBFBD>
if (GetDevicePhotoelectric(Convert.ToInt32(devinfo1.DeviceIndex.ToString() + "6")) == 1)
{
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, 97);
AlterRoute(devinfo1.DeviceIndex, 97);
}
devinfo1.RunState = 2;
if (devinfo1.ErrorCode != 97)
{
UpdateErrorCode(devinfo1.DeviceIndex, 97);
AlterRoute(devinfo1.DeviceIndex, 97);
}
err = 97;
//devinfo1.ErrorCode = 97;
}
//20100131
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, err);
AlterRoute(devinfo1.DeviceIndex, err);
}
if (devinfo1.ErrorCode != err)
{
UpdateErrorCode(devinfo1.DeviceIndex, err);
AlterRoute(devinfo1.DeviceIndex, err);
}
//20100131
devinfo1.ErrorCode = err;
//20090926
#endregion
}
else
{
States = GetDeviceState(devinfo1.DeviceIndex);
if (States == null) continue;
if (States[1] >= 30)
{
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
//20100131
//<2F>޸<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>
if (States[1] != devinfo1.ErrorCode)
{
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
devinfo1.ErrorCode = States[1];
devinfo1.RunState = 2;
}
else if ((States[1] == 0) || (States[1] == 1) || (States[1] == 2))
{
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, 0);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
//20100131
//<2F>޸<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>
if (States[1] != devinfo1.ErrorCode)
{
UpdateErrorCode(devinfo1.DeviceIndex, 0);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
//20090926
if (States[1] == 2)
{
//20090920
devinfo1.RunState = 5;
}
else
{
devinfo1.RunState = States[1];
}
//20100131
//20091006
devinfo1.ErrorCode = States[1];
//20090926
}
devinfo1.TaskNo = States[2];
//20101118
if (devinfo1.SplitByte != -1)
{
devinfo1.SplitByte_0 = GetDevicePhotoelectric(devinfo1.DeviceIndex, 0);
devinfo1.SplitByte_1 = GetDevicePhotoelectric(devinfo1.DeviceIndex, 1);
devinfo1.SplitByte_2 = GetDevicePhotoelectric(devinfo1.DeviceIndex, 2);
devinfo1.SplitByte_3 = GetDevicePhotoelectric(devinfo1.DeviceIndex,3);
}
}
}
if ((devinfo1.DeviceKind == 1) || (devinfo1.DeviceKind == 4))
{
States = GetDeviceState(devinfo1.DeviceIndex);
if (States == null) continue;
if (States[1] >= 30)
{
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
//<2F>޸<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>
if (States[1] != devinfo1.ErrorCode)
{
//20100131
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
devinfo1.ErrorCode = States[1];
devinfo1.RunState = 2;
}
else if ((States[1] == 0) || (States[1] == 1) || (States[1] == 2))
{
if (updateroute == true)
{//20100131
UpdateErrorCode(devinfo1.DeviceIndex, 0);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
//<2F>޸<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>
if (States[1] != devinfo1.ErrorCode)
{
//20100131
UpdateErrorCode(devinfo1.DeviceIndex, 0);
AlterRoute(devinfo1.DeviceIndex, States[1]);
}
//20090926
if (States[1] == 2)
{
//20090920
devinfo1.RunState =5;
}
else
{
devinfo1.RunState = States[1];
}
//20100131
devinfo1.ErrorCode = States[1];
}
devinfo1.TaskNo = States[2];
// 20120518 <20>Ѷ<EFBFBD><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EAA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
if (States[3] > 880888)
devinfo1.XCoor = 40;
else
devinfo1.XCoor = States[3];
devinfo1.YCoor = States[4];
}
int bdv = 0, bdov = 0;
//20101118
if (devinfo1.BindingDevice != null)
{
bdv = GetDevicePhotoelectric(devinfo1.BindingDevice);//20101124
}
if (devinfo1.BindingDeviceOut != null)
{
bdov = GetDevicePhotoelectric(devinfo1.BindingDeviceOut);//20101124
}
//20101118
if ((bdv + bdov) >= 1)
{
devinfo1.HaveGoods = true;
}
else
{
devinfo1.HaveGoods = false;
}
sql.Remove(0, sql.Length);
sql.Append("SELECT F_MonitorIndex,F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6, F_TxtParam FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( devinfo1.TaskNo ).Append( ")");
DataView dvb = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvb.Count > 0)
{
if (devinfo1.DeviceKind == 1)
{
devinfo1.ArrowLocation =string.Format("{0}<7D><>{1}<7D><>{2}<7D><>", dvb[0]["F_NumParam4"].ToString() , dvb[0]["F_NumParam5"].ToString() ,dvb[0]["F_NumParam6"].ToString());
}
if (devinfo1.DeviceKind == 4)
{
devinfo1.ArrowLocation = dvb[0]["F_NumParam1"].ToString();
}
if (devinfo1.DeviceKind == 2)
{
devinfo1.ArrowLocation = dvb[0]["F_NumParam4"].ToString();
}
devinfo1.Barcode = dvb[0]["F_TxtParam"].ToString();
}
else
{
devinfo1.Barcode = "";
devinfo1.ArrowLocation = "";
}
//20091107
dvb = null;
}
Model.CGetInfo.SetDeviceInfo(devinfo1);
//20091107
dvv = null;
}
}
catch(Exception exa)
{
_CParsePLCError = "<22><><EFBFBD><EFBFBD>PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵļ<DDB5>¼<EFBFBD>豸״̬ʱ<CCAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + exa.Message;
}
}
/// <summary>
/// <20>޸ı<DEB8><C4B1><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="devInx"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><E8B1B8><EFBFBD><EFBFBD></param>
/// <returns></returns>
public static bool AlterRoute(int devInx, int state)
{
try
{
//SELECT T_Base_Route_Device.F_RouteIDSub, T_Base_Route_Device.F_RouteID, T_Base_Route_Device.F_DeviceIndex FROM T_Base_Route_Device,T_Base_Device where T_Base_Route_Device.F_DeviceIndex = T_Base_Device.F_DeviceIndex GROUP BY T_Base_Route_Device.F_RouteIDSub, T_Base_Route_Device.F_RouteID, T_Base_Route_Device.F_DeviceIndex HAVING (SUM(T_Base_Device.F_ErrorCode) <= 0) AND (T_Base_Route_Device.F_DeviceIndex = 12030)
sql.Remove(0, sql.Length);
sql.Append("select distinct T_Base_Route.F_RouteID as F_RouteID , F_StartDevice ,F_EndDevice from T_Base_Route_Device ,T_Base_Route where T_Base_Route_Device.F_RouteID =T_Base_Route .F_RouteID and F_DeviceIndex=").Append(devInx);
DataView dv = dboRoute.ExceSQL(sql.ToString()).Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
if (state >= 30)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B6A8>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>
sql.Remove(0, sql.Length);
sql .Append( " SELECT T_Base_Route_Device.F_RouteIDSub, SUM(T_Base_Device.F_ErrorCode) AS ErrorCodes " ).Append(
" FROM T_Base_Route_Device,T_Base_Device where T_Base_Route_Device.F_DeviceIndex = T_Base_Device.F_DeviceIndex" ).Append(
" and T_Base_Route_Device.F_RouteID=" ).Append( dv[i]["F_RouteID"] ).Append( " GROUP BY T_Base_Route_Device.F_RouteIDSub ");
DataView dvr = dboRoute.ExceSQL(sql.ToString()).Tables[0].DefaultView;
bool ifUsable = false;
for (int kk = 0; kk < dvr.Count; kk++)
{
if (Convert.ToInt32( dvr[kk]["ErrorCodes"] )<= 0)
{
ifUsable = true;
break;
}
}
if (ifUsable == false)
{
//20101011
sql.Remove(0, sql.Length);
sql.Append("update t_base_route set F_Status=0 where f_routeid=" ).Append( dv[i]["F_RouteID"] ).Append( " and F_Status=1 and F_AutoUpdate=1 ");
int ups = dboRoute.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=0 where START_DEVICE='").Append(dv[i]["F_StartDevice"]).Append("' and End_Device = '").Append(dv[i]["F_EndDevice"]).Append("' and CONTROL_ROUTE_STATUS=1");
if (ups>0)dboMan.ExceSQL(sql.ToString());
}
}
else
{
sql.Remove(0, sql.Length);
sql.Append("SELECT SUM(T_Base_Device.F_ErrorCode) as errcode FROM T_Base_Device ,T_Base_Route_Device" ).Append(
" where T_Base_Device.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and T_Base_Route_Device.F_RouteID=").Append(dv[i]["F_RouteID"]);
DataView dv1 = dboRoute.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv1.Count > 0)
{
int errcode = 0;
if (Microsoft.VisualBasic.Information.IsNumeric(dv1[0]["errcode"]) == true)
{
errcode =Convert.ToInt32( dv1[0]["errcode"]);
}
if (errcode <= 0)
{
//20101011
sql.Remove(0, sql.Length);
sql.Append("update t_base_route set F_Status=1 where f_routeid=" ).Append( dv[i]["F_RouteID"] ).Append( " and F_Status=0 and F_AutoUpdate=1 ");
int ups= dboRoute.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=1 where START_DEVICE='").Append(dv[i]["F_StartDevice"]).Append("' and End_Device = '").Append(dv[i]["F_EndDevice"]).Append("' and CONTROL_ROUTE_STATUS=0");
if(ups>0)dboMan.ExceSQL(sql.ToString());
}
}
}
}
return true;
}
catch (Exception ex)
{
_CParsePLCError = "<22><><EFBFBD><EFBFBD>PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>޸<EFBFBD>·<EFBFBD><C2B7>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + ex.Message;
return false;
}
}
static void UpdateErrorCode(int devInx, int errorCode)
{
sql.Remove(0, sql.Length);
sql.Append("UPDATE T_Base_Device SET F_ErrorCode = " ).Append( errorCode ).Append( " WHERE (F_DeviceIndex = " ).Append( devInx ).Append( ")and (F_ErrorCode <> " ).Append( errorCode ).Append( ")");
dbo.ExceSQL(sql.ToString());
}
static string GetDeviceS7Connection(int deviceindex)
{//20110216
DataView dv = dbo.ExceSQL("SELECT F_S7Connection FROM T_Base_Device WHERE (F_DeviceIndex = " + deviceindex + ")").Tables[0].DefaultView;
if (dv.Count > 0)
{
return dv[0]["F_S7Connection"].ToString();
}
else
{
return null;
}
}
}
}