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.
1255 lines
50 KiB
1255 lines
50 KiB
5 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using DBFactory;
|
||
|
using CommonLib;
|
||
|
using System.Threading;
|
||
|
namespace WcfControlMonitorLib
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Creator:Richard.liu
|
||
|
/// ����PLC���ص�����
|
||
|
/// </summary>
|
||
|
public class CParsePLCDataMutiConn
|
||
|
{
|
||
|
Dictionary<string, Model.MDevice> _devicesInfo;
|
||
|
string _ReadSubscription = string.Empty;
|
||
|
CParsePLCDataMutiConn(string readSubscription)
|
||
|
{
|
||
|
_ReadSubscription = readSubscription;
|
||
|
AddDeviceInfo(_ReadSubscription);
|
||
|
}
|
||
|
void AddDeviceInfo(string readSubscription)
|
||
|
{
|
||
|
|
||
|
sql.Remove(0, sql.Length);
|
||
|
sql.Append(string.Format("select * from T_Base_Device where F_ReadSubscription='{0}' order by F_DeviceIndex asc", readSubscription));
|
||
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
||
|
for (int i = 0; i < dv.Count; i++)
|
||
|
{
|
||
|
Model.MDevice devinfo = new Model.MDevice();
|
||
|
if (dv[i]["F_AppendBarcode"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.AppendBarcode = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.AppendBarcode = (int)dv[i]["F_AppendBarcode"];
|
||
|
}
|
||
|
if (dv[i]["F_BeDetected"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.BeDetected = null;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.BeDetected = dv[i]["F_BeDetected"].ToString();
|
||
|
}
|
||
|
if (dv[i]["F_BindingDevice"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.BindingDevice = null;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.BindingDevice = dv[i]["F_BindingDevice"].ToString();
|
||
|
}
|
||
|
if (dv[i]["F_BindingDeviceOut"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.BindingDeviceOut = null;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.BindingDeviceOut = dv[i]["F_BindingDeviceOut"].ToString();
|
||
|
}
|
||
|
if (dv[i]["F_CommType"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.CommType = null;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.CommType = dv[i]["F_CommType"].ToString();
|
||
|
}
|
||
|
|
||
|
if (dv[i]["F_DBW1Address"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.Dbw1Address = -1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.Dbw1Address = (int)(dv[i]["F_DBW1Address"]);
|
||
|
}
|
||
|
if (dv[i]["F_DBWSendLength"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.Dbw1SendLength = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.Dbw1SendLength = (int)dv[i]["F_DBWSendLength"];
|
||
|
}
|
||
|
if (dv[i]["F_DBW2Address"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.Dbw2Address = -1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.Dbw2Address = (int)dv[i]["F_DBW2Address"];
|
||
|
}
|
||
|
if (dv[i]["F_DBWGetLength"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.Dbw2Getlength = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.Dbw2Getlength = (decimal)dv[i]["F_DBWGetLength"];
|
||
|
}
|
||
|
if (dv[i]["F_DeviceIndex"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.DeviceIndex = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.DeviceIndex = (int)dv[i]["F_DeviceIndex"];
|
||
|
}
|
||
|
if (dv[i]["F_DeviceKindIndex"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.DeviceKind = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.DeviceKind = (int)dv[i]["F_DeviceKindIndex"];
|
||
|
}
|
||
|
if (dv[i]["F_DeviceName"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.DeviceName = null;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.DeviceName = (string)dv[i]["F_DeviceName"];
|
||
|
}
|
||
|
if (dv[i]["F_DeviceVisual"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.DeviceVisual = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.DeviceVisual = (int)dv[i]["F_DeviceVisual"];
|
||
|
}
|
||
|
if (dv[i]["F_KeyDevice"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.IfKeyDevice = '0';
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.IfKeyDevice = Convert.ToChar(dv[i]["F_KeyDevice"]);
|
||
|
}
|
||
|
if (dv[i]["F_MaxSendCount"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.MaxSendCount = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.MaxSendCount = (int)dv[i]["F_MaxSendCount"];
|
||
|
}
|
||
|
if (dv[i]["F_NeedOptimize"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.NeedOptimize = '0';
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.NeedOptimize = Convert.ToChar(dv[i]["F_NeedOptimize"]);
|
||
|
}
|
||
|
if (dv[i]["F_SendInterval"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.SendInterval = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.SendInterval = (int)dv[i]["F_SendInterval"];
|
||
|
}
|
||
|
if (dv[i]["F_LocalIP"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.LocalIP = "";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.LocalIP = (string)dv[i]["F_LocalIP"];
|
||
|
}
|
||
|
if (dv[i]["F_LocalPort"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.LocalPort = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.LocalPort = (int)dv[i]["F_LocalPort"];
|
||
|
}
|
||
|
if (dv[i]["F_RemoteIP"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.RemoteIP = "";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.RemoteIP = (string)dv[i]["F_RemoteIP"];
|
||
|
}
|
||
|
if (dv[i]["F_RemotePort"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.RemotePort = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.RemotePort = (int)dv[i]["F_RemotePort"];
|
||
|
}
|
||
|
if (dv[i]["F_OPCProgID"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.OPCProgID = "";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.OPCProgID = (string)dv[i]["F_OPCProgID"];
|
||
|
}
|
||
|
if (dv[i]["F_ErrorTaskNo"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.ErrorTaskNo = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.ErrorTaskNo = (int)dv[i]["F_ErrorTaskNo"];
|
||
|
}
|
||
|
if (dv[i]["F_SendOutDetect"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.SendOutDetect = "0";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.SendOutDetect = dv[i]["F_SendOutDetect"].ToString();
|
||
|
}
|
||
|
//
|
||
|
if (dv[i]["F_OnlyDetectIO"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.OnlyDetectIO = "0";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.OnlyDetectIO = dv[i]["F_OnlyDetectIO"].ToString();
|
||
|
}
|
||
|
if (dv[i]["F_UseCommonDB"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.UseCommonDB = "0";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.UseCommonDB = dv[i]["F_UseCommonDB"].ToString();
|
||
|
}
|
||
|
if (dv[i]["F_IfCorrelDoubleFork"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.IfCorrelDoubleFork = "0";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.IfCorrelDoubleFork = dv[i]["F_IfCorrelDoubleFork"].ToString();
|
||
|
}
|
||
|
|
||
|
if (dv[i]["F_DoubleFork"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.DoubleFork = "0";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.DoubleFork = dv[i]["F_DoubleFork"].ToString();
|
||
|
}
|
||
|
//20100609
|
||
|
if (dv[i]["F_SerialPort"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.SerialPort = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.SerialPort = Convert.ToInt32(dv[i]["F_SerialPort"]);
|
||
|
}
|
||
|
//20100609
|
||
|
if (dv[i]["F_CommSettings"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.CommSettings = "0";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.CommSettings = dv[i]["F_CommSettings"].ToString();
|
||
|
}
|
||
|
//20100714
|
||
|
if (dv[i]["F_S7Connection"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.S7Connection = "S7:[S7 connection_1]";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.S7Connection = dv[i]["F_S7Connection"].ToString();
|
||
|
}
|
||
|
//20101118
|
||
|
if (dv[i]["F_SplitByte"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.SplitByte = -1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.SplitByte = Convert.ToInt32(dv[i]["F_SplitByte"]);
|
||
|
}
|
||
|
if (dv[i]["F_ManTaskReserve"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.ManTaskReserve = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.ManTaskReserve = Convert.ToInt32(dv[i]["F_ManTaskReserve"]);
|
||
|
}
|
||
|
if (dv[i]["F_HaveGoods"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.LogicHaveGoods = false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.LogicHaveGoods = Convert.ToInt32(dv[i]["F_HaveGoods"]) == 1 ? true : false;
|
||
|
}
|
||
|
if (dv[i]["F_ReadSubscription"] == DBNull.Value)
|
||
|
{
|
||
|
devinfo.ReadSubscription = "0";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo.ReadSubscription = dv[i]["F_ReadSubscription"].ToString();
|
||
|
}
|
||
|
if (_devicesInfo.ContainsKey(readSubscription) == false)
|
||
|
{
|
||
|
_devicesInfo.Add(readSubscription, devinfo);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
public static event CDeviceStateChangeEventHandler DeviceStateChange;
|
||
|
public static void OnDeviceStateChange(object sender,CDeviceStateChangeEventArgs e)
|
||
|
{
|
||
|
System.Object lockThis = new System.Object();
|
||
|
lock (lockThis)
|
||
|
{
|
||
|
|
||
|
if (DeviceStateChange != null)
|
||
|
{
|
||
|
DeviceStateChange(sender, e);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
int[] AllReturns;//20110216
|
||
|
/// <summary>
|
||
|
/// 20110216����S7Connection��ʶ��������DB2���ݵ������豸����ʼ��������ַ
|
||
|
/// </summary>
|
||
|
/// <param name="sb">S7Connection��ʶ</param>
|
||
|
/// <returns></returns>
|
||
|
int GetDevice28KindDBW2Address(StringBuilder sb)
|
||
|
{
|
||
|
DataView dv = dbo.ExceSQL("SELECT F_DBW2Address FROM T_Base_Device WHERE (F_DeviceKindIndex = 28 and F_S7Connection='" + sb.ToString() + "')").Tables[0].DefaultView;
|
||
|
if (dv.Count > 0)
|
||
|
{
|
||
|
return Convert.ToInt32(dv[0]["F_DBW2Address"]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
StringBuilder sql = new StringBuilder();
|
||
|
char[] dd = new char[1] { '.' };//20101124
|
||
|
string[] sp ;//20101124
|
||
|
string _CParsePLCError = "";//���ص���������˵��
|
||
|
public string CParsePLCError
|
||
|
{
|
||
|
get { return _CParsePLCError; }
|
||
|
set { _CParsePLCError = value; }
|
||
|
}
|
||
|
DBOperator dbo = new DBOperator();
|
||
|
DBOperator dboRoute = new DBOperator();
|
||
|
DBOperator dboMan = new DBOperator("ManConnString", "ManDBFactory");
|
||
|
Thread mythread;
|
||
|
bool exitThread = false;//20091107
|
||
|
private void BeginListen()
|
||
|
{//20091107
|
||
|
while (!exitThread )
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string dt = DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond.ToString();
|
||
|
SetDeviceState();
|
||
|
string dt1 = DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond.ToString();
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_CParsePLCError = ex.Message;
|
||
|
}
|
||
|
//Thread.Sleep(200);//20100710
|
||
|
}
|
||
|
}
|
||
|
public void EndListen()
|
||
|
{//20091107
|
||
|
exitThread = true;
|
||
|
|
||
|
if (mythread != null)
|
||
|
{
|
||
|
|
||
|
mythread.Abort();
|
||
|
mythread = null;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
public 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>
|
||
|
/// ȡ��ָ�����翪�أ�ȷ�ϰ�ť���豸�������źţ�0��1��
|
||
|
/// </summary>
|
||
|
/// <param name="deviceIdx">�豸����</param>
|
||
|
/// <returns>0��1</returns>
|
||
|
public int GetDevicePhotoelectric(string S7Connection, int deviceIdx)
|
||
|
{
|
||
|
TimeSpan dt = DateTime.Now.TimeOfDay;
|
||
|
try
|
||
|
{
|
||
|
//20110216
|
||
|
AllReturns = CStaticClass.MutiReadSubscriptionDeviceStateReturns[S7Connection];
|
||
|
if (AllReturns != null)
|
||
|
{
|
||
|
#region ��ȡ��������ֵ
|
||
|
|
||
|
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
|
||
|
int temp = Convert.ToInt32(dvle[0]["F_DBW2Address"]) - GetDevice28KindDBW2Address(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
|
||
|
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")
|
||
|
//{//�����������翪��0��̽�1��̽�������ȡ������������
|
||
|
// 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("ȡ��ָ�����翪�ص��ź�ʱ��" + ex.Message) < 0)
|
||
|
//{
|
||
|
|
||
|
// FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "ȡ��ָ�����翪�ص��ź�ʱ��" + ex.Message, true);
|
||
|
//}
|
||
|
return -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
TimeSpan dt1 = DateTime.Now.TimeOfDay;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 20101118�����豸�ź�bitλ��ȡ��F_SplitByte���Ĺ���bitֵ��0,1
|
||
|
/// </summary>
|
||
|
/// <param name="deviceIdx"></param>
|
||
|
/// <param name="bit"></param>
|
||
|
/// <returns></returns>
|
||
|
public int GetDevicePhotoelectric(string S7Connection, int deviceIdx, int abit)
|
||
|
{
|
||
|
TimeSpan dt = DateTime.Now.TimeOfDay;
|
||
|
try
|
||
|
{
|
||
|
//20110216
|
||
|
AllReturns = CStaticClass.MutiReadSubscriptionDeviceStateReturns[S7Connection];
|
||
|
if (AllReturns != null)
|
||
|
{
|
||
|
#region ��ȡ��������ֵ
|
||
|
|
||
|
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
|
||
|
int temp = Convert.ToInt32(dvle[0]["F_SplitByte"]) - GetDevice28KindDBW2Address(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
|
||
|
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")
|
||
|
//{//�����������翪��0��̽�1��̽�������ȡ������������
|
||
|
// if (IfVis == 1)
|
||
|
// {
|
||
|
// IfVis = 0;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// IfVis = 1;
|
||
|
// }
|
||
|
//}
|
||
|
return IfVis;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
TimeSpan dt1 = DateTime.Now.TimeOfDay;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// //20101124���ݡ��豸��.bitλ�����ַ�����ȡ��F_SplitByte���Ĺ���bitֵ��0,1
|
||
|
/// </summary>
|
||
|
/// <param name="deviceIdx"></param>
|
||
|
/// <param name="bit"></param>
|
||
|
/// <returns></returns>
|
||
|
public int GetDevicePhotoelectric(string S7Connection, string devicebit)
|
||
|
{
|
||
|
TimeSpan dt = DateTime.Now.TimeOfDay;
|
||
|
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.MutiReadSubscriptionDeviceStateReturns[S7Connection];
|
||
|
if (AllReturns != null)
|
||
|
{
|
||
|
#region ��ȡ��������ֵ
|
||
|
|
||
|
|
||
|
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
|
||
|
|
||
|
int temp = Convert.ToInt32(dvle[0]["F_SplitByte"]) - GetDevice28KindDBW2Address(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
|
||
|
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")
|
||
|
//{//�����������翪��0��̽�1��̽�������ȡ������������
|
||
|
// if (IfVis == 1)
|
||
|
// {
|
||
|
// IfVis = 0;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// IfVis = 1;
|
||
|
// }
|
||
|
//}
|
||
|
return IfVis;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
CParsePLCError = "ȡ��ָ�����翪�ص��ź�ʱ��" + ex.Message;
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
TimeSpan dtt = DateTime.Now.TimeOfDay;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// ȡ��ָ���豸�������豸״̬:[0]��д��־;[1]״̬;[2]�����ţ�[3]X����;[4]Y����;[5]�豸����
|
||
|
/// </summary>
|
||
|
/// <param name="deviceIdx">�豸����</param>
|
||
|
/// <returns></returns>
|
||
|
public int[] GetDeviceState(string S7Connection,int deviceIdx)
|
||
|
{TimeSpan dt0 = DateTime.Now.TimeOfDay;
|
||
|
TimeSpan dt1;
|
||
|
TimeSpan dt2 ;
|
||
|
try
|
||
|
{
|
||
|
|
||
|
|
||
|
//20110216
|
||
|
|
||
|
dt1 = DateTime.Now.TimeOfDay;
|
||
|
AllReturns = CStaticClass.MutiReadSubscriptionDeviceStateReturns[S7Connection];
|
||
|
dt2 = DateTime.Now.TimeOfDay;
|
||
|
if (AllReturns != null)
|
||
|
{
|
||
|
#region ��ȡ�豸״̬
|
||
|
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
|
||
|
int temp = Convert.ToInt32(dvle[0]["F_DBW2Address"]) - GetDevice28KindDBW2Address(new StringBuilder(dvle[0]["F_S7Connection"].ToString()));
|
||
|
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 �����豸
|
||
|
case "1"://�Ѷ���
|
||
|
|
||
|
states[0] = AllReturns[temp];//��д��־
|
||
|
states[1] = AllReturns[temp + 1];//״̬
|
||
|
states[2] = (AllReturns[temp + 2] << 8) + AllReturns[temp + 3];//������
|
||
|
states[3] = AllReturns[temp + 7] + (AllReturns[temp + 6] << 8) + (AllReturns[temp + 5] << 16) + (AllReturns[temp + 4] << 32);//X����
|
||
|
states[4] = AllReturns[temp + 11] + (AllReturns[temp + 10] << 8) + (AllReturns[temp + 9] << 16) + (AllReturns[temp + 8] << 32);//Y����
|
||
|
states[5] = deviceIdx;//�豸������
|
||
|
|
||
|
break;
|
||
|
case "2"://���ͻ�
|
||
|
states[0] = AllReturns[temp];//��д��־
|
||
|
states[1] = AllReturns[temp + 1];//״̬
|
||
|
states[2] = (AllReturns[temp + 2] << 8) + AllReturns[temp + 3];//������
|
||
|
states[3] = 0;
|
||
|
states[4] = 0;
|
||
|
states[5] = deviceIdx;//�豸������
|
||
|
|
||
|
break;
|
||
|
case "4"://RGV
|
||
|
states[0] = AllReturns[temp];//��д��־
|
||
|
states[1] = AllReturns[temp + 1];//״̬
|
||
|
states[2] = (AllReturns[temp + 2] << 8) + AllReturns[temp + 3];//������
|
||
|
states[3] = AllReturns[temp + 7] + (AllReturns[temp + 6] << 8) + (AllReturns[temp + 5] << 16) + (AllReturns[temp + 4] << 32);//X����
|
||
|
states[4] = 0;
|
||
|
states[5] = deviceIdx;//�豸������
|
||
|
|
||
|
break;
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
|
||
|
return states;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch //(Exception ex)
|
||
|
{
|
||
|
//if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("ȡ��ָ�����翪�ص��ź�ʱ��" + ex.Message) < 0)
|
||
|
//{
|
||
|
|
||
|
// FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "ȡ��ָ�����翪�ص��ź�ʱ��" + ex.Message, true);
|
||
|
//}
|
||
|
return null;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// ���������豸�ĵ�ǰ��̬����
|
||
|
/// </summary>
|
||
|
public 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 _devicesInfo.Values)
|
||
|
{
|
||
|
if (devinfo1.DeviceKind >= 6 && devinfo1.DeviceKind <= 30) continue;
|
||
|
string dt = DateTime.Now.Second.ToString()+"-"+DateTime.Now.Millisecond.ToString();
|
||
|
string dt0; string dt1; string dtt;
|
||
|
#region �豸��ͣ��
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
else
|
||
|
{
|
||
|
#region ���翪���ࣨ���Ӽ��У��°��Ѿ�ȡ��
|
||
|
|
||
|
if ((devinfo1.DeviceKind == 14) || (devinfo1.DeviceKind == 18))
|
||
|
{
|
||
|
devinfo1.DeviceVisual = GetDevicePhotoelectric(devinfo1.S7Connection,devinfo1.DeviceIndex);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region ���ͻ���
|
||
|
|
||
|
if ((devinfo1.DeviceKind == 2) || (devinfo1.DeviceKind == 3) || (devinfo1.DeviceKind == 5) )
|
||
|
{
|
||
|
//��Щ���ͻ����������ڵ���·���д��ڣ����Dz���Ҫ��������ָ������Լ����ƣ�ֻ�����Ƿ����к���λ�Ϳ�����
|
||
|
if (devinfo1.OnlyDetectIO == "1")
|
||
|
{
|
||
|
|
||
|
#region ����λ���豸����+7��
|
||
|
devinfo1.RunState = GetDevicePhotoelectric(devinfo1.S7Connection, 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 ����λ���豸����+6��
|
||
|
if (GetDevicePhotoelectric(devinfo1.S7Connection, 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.S7Connection, 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
|
||
|
|
||
|
//��·����
|
||
|
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
|
||
|
|
||
|
//��·����
|
||
|
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.S7Connection, devinfo1.DeviceIndex, 0);
|
||
|
devinfo1.SplitByte_1 = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.DeviceIndex, 1);
|
||
|
devinfo1.SplitByte_2 = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.DeviceIndex, 2);
|
||
|
devinfo1.SplitByte_3 = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.DeviceIndex, 3);
|
||
|
devinfo1.SplitByte_4 = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.DeviceIndex, 4);
|
||
|
devinfo1.SplitByte_5 = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.DeviceIndex, 5);
|
||
|
devinfo1.SplitByte_6 = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.DeviceIndex, 6);
|
||
|
devinfo1.SplitByte_7 = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.DeviceIndex, 7);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region �ƶ��豸��
|
||
|
|
||
|
if ((devinfo1.DeviceKind == 1) || (devinfo1.DeviceKind == 4))
|
||
|
{
|
||
|
States = GetDeviceState(devinfo1.S7Connection, devinfo1.DeviceIndex);
|
||
|
|
||
|
if (States == null) continue;
|
||
|
|
||
|
|
||
|
if (States[1] >= 30)
|
||
|
{
|
||
|
if (updateroute == true)
|
||
|
{//20100131
|
||
|
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
|
||
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
||
|
}
|
||
|
//��·����
|
||
|
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]);
|
||
|
}
|
||
|
//��·����
|
||
|
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];
|
||
|
devinfo1.XCoor = States[3];
|
||
|
devinfo1.YCoor = States[4];
|
||
|
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
if (devinfo1.DeviceKind == 1 || devinfo1.DeviceKind == 2 || devinfo1.DeviceKind == 3 || devinfo1.DeviceKind == 4 || devinfo1.DeviceKind == 5 || devinfo1.DeviceKind == 31)
|
||
|
{
|
||
|
#region �豸����
|
||
|
|
||
|
int bdv = 0, bdov = 0;
|
||
|
//20101118
|
||
|
|
||
|
|
||
|
if (devinfo1.BindingDevice != null)
|
||
|
{
|
||
|
|
||
|
bdv = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.BindingDevice);//20101124
|
||
|
}
|
||
|
if (devinfo1.BindingDeviceOut != null)
|
||
|
{
|
||
|
|
||
|
bdov = GetDevicePhotoelectric(devinfo1.S7Connection, devinfo1.BindingDeviceOut);//20101124
|
||
|
|
||
|
}
|
||
|
//20101118
|
||
|
if ((bdv + bdov) >= 1)
|
||
|
{
|
||
|
devinfo1.HaveGoods = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo1.HaveGoods = false;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
dtt = DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond.ToString();
|
||
|
|
||
|
#region �豸������
|
||
|
|
||
|
|
||
|
sql.Remove(0, sql.Length);
|
||
|
sql.Append("SELECT F_HaveGoods FROM T_Base_Device WHERE F_DeviceIndex=").Append(devinfo1.DeviceIndex);
|
||
|
dvv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
||
|
if (dvv.Count > 0)
|
||
|
{
|
||
|
if (dvv[0]["F_HaveGoods"].ToString() == "1")
|
||
|
{
|
||
|
devinfo1.LogicHaveGoods = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
devinfo1.LogicHaveGoods = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
dt0 = DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond.ToString();
|
||
|
|
||
|
#region ����������
|
||
|
|
||
|
sql.Remove(0, sql.Length);
|
||
|
sql.Append("SELECT 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}��{1}��{2}��", 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 = "";
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
dvb = null;
|
||
|
}
|
||
|
dt1 = DateTime.Now.Second.ToString()+"-"+DateTime.Now.Millisecond.ToString();
|
||
|
//20091107
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
Model.CGetInfo.SetDeviceInfo(devinfo1);
|
||
|
|
||
|
CDeviceStateChangeEventArgs csce = new CDeviceStateChangeEventArgs(devinfo1);
|
||
|
OnDeviceStateChange("CParsePLCData", csce);
|
||
|
|
||
|
//20091107
|
||
|
dvv = null;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
catch(Exception exa)
|
||
|
|
||
|
{
|
||
|
|
||
|
_CParsePLCError = "����PLC�������ݵļ�¼�豸״̬ʱ����������" + exa.Message;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// �ı���·������������������·�����Լ�����������
|
||
|
/// </summary>
|
||
|
/// <param name="devInx">�������ϵ��豸����</param>
|
||
|
/// <returns></returns>
|
||
|
public bool AlterRoute(int devInx, int state)
|
||
|
{
|
||
|
|
||
|
|
||
|
try
|
||
|
{
|
||
|
sql.Remove(0, sql.Length);
|
||
|
sql.Append("select distinct F_RouteID from T_Base_Route_Device where F_DeviceIndex=" ).Append( devInx);
|
||
|
DataView dv = dboRoute.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
||
|
for (int i = 0; i < dv.Count; i++)
|
||
|
{
|
||
|
if (state >= 30)
|
||
|
{
|
||
|
//������·����������ʱ�������趨��·�����IJ�����
|
||
|
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 CONTROL_ROUTE_ID='" ).Append( dv[i]["F_RouteID"] ).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; int a = 0;
|
||
|
if (int.TryParse (dv1[0]["errcode"].ToString(),out a ) == 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 CONTROL_ROUTE_ID='" ).Append( dv[i]["F_RouteID"] ).Append( "' and CONTROL_ROUTE_STATUS=0");
|
||
|
if(ups>0)dboMan.ExceSQL(sql.ToString());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_CParsePLCError = "����PLC�������ݵ���·��ʱ����������" + ex.Message;
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
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());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|