410 lines
16 KiB
C#
410 lines
16 KiB
C#
using CCYQ_JieFang;
|
||
using DeviceDriver_BasicData;
|
||
using DK_DC_Tool;
|
||
using NJ_ZC;
|
||
using OpcBasic;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Concurrent;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Threading;
|
||
using System.Windows.Forms;
|
||
using SystemFramework;
|
||
using static System.Configuration.ConfigurationManager;
|
||
|
||
namespace MesWork
|
||
{
|
||
public partial class Temp {
|
||
public static MesWorkForm mesWorkForm = null;
|
||
public static DAS_OP10 mesWorkForm1 = null;
|
||
public static DAS_OP20 mesWorkForm2 = null;
|
||
public static DAS_OP30 mesWorkForm3 = null;
|
||
public static DAS_OP40 mesWorkForm4 = null;
|
||
public static DAS_OP50 mesWorkForm5 = null;
|
||
}
|
||
public partial class MesWorkForm
|
||
{
|
||
public static string BasicDataTableFile = AppSettings["BasicDataTableFile"];
|
||
public static int IsDemoMesServer = Convert.ToInt32(AppSettings["IsDemoMesServer"]);
|
||
public static int IsWriteMonitorLog = Convert.ToInt32(AppSettings["IsWriteMonitorLog"]);
|
||
|
||
public static string ConnectionString = AppSettings["ConnectionString"];
|
||
|
||
public static string MesServer_IpPortName = AppSettings["MesServer_IpPortName"];
|
||
public static string MesServer_SendProtocol = AppSettings["MesServer_SendProtocol"];
|
||
public static string MesServer_SendTagProtocol = AppSettings["MesServer_SendTagProtocol"];
|
||
public static string MesServer_SendTagProtocol_MES = AppSettings["MesServer_SendTagProtocol_MES"];
|
||
|
||
//机床测量数据
|
||
public static string MeasureDataString = AppSettings["MeasureDataString"];
|
||
public static string ProgramDataString = AppSettings["ProgramDataString"];
|
||
|
||
public static string WebSvrUrlPort = AppSettings["WebSvrUrlPort"];
|
||
|
||
|
||
public static string ResponseEnterOrLeaveUrl = AppSettings["ResponseEnterOrLeaveUrl"];
|
||
public static string FinishCallUrl = AppSettings["FinishCallUrl"];
|
||
public static string DeviceStatusUrl = AppSettings["DeviceStatusUrl"];
|
||
|
||
public static string IPC_product = AppSettings["IPC_product"];
|
||
public static string IPC_RequestEnterOrLeave = AppSettings["IPC_RequestEnterOrLeave"];
|
||
public static string IPC_WorkFinsih = AppSettings["IPC_WorkFinsih"];
|
||
|
||
// MQTT
|
||
// public static int connectType = Convert.ToInt32(AppSettings["connectType"]);
|
||
// public static string MqttUrl = AppSettings["MqttUrl"];
|
||
// public static string MqttTargetTopic = AppSettings["MqttTargetTopic"];
|
||
|
||
public static int TimerUpdateSql = Convert.ToInt32(AppSettings["TimerUpdateSql"]);
|
||
public static int StationStatus_Interval_Read = Convert.ToInt32(AppSettings["StationStatus_Interval_Read"]);
|
||
public static int StationStatus_Interval_Update = Convert.ToInt32(AppSettings["StationStatus_Interval_Update"]);
|
||
public static int StationStatus_Interval_Insert = Convert.ToInt32(AppSettings["StationStatus_Interval_Insert"]);
|
||
|
||
public static int ExecSql_Interval = Convert.ToInt32(AppSettings["ExecSql_Interval"]);
|
||
|
||
public static string IsLogFilePath = AppSettings["IsLogFilePath"];
|
||
public static string LogFilePath = AppSettings["LogFilePath"];
|
||
public static string IpcConfigPath = AppSettings["IpcConfigPath"];
|
||
|
||
private static StreamWriter streamWriter;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static ConcurrentQueue<ParamT> taskSql = new ConcurrentQueue<ParamT>();
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static string StationName = "DDV";
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static DataTable dt_Robot = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static DataTable dt_EEM = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static DataTable dt_EEM_PLC = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static DataTable dt_CNC = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static DataTable dt_pmc = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static DataTable dt_pmc_Simplify = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static DataTable dt_PLC_Data = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static Hashtable ht_PLM_Old = new Hashtable();
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static Hashtable ht_PLM_Curr = new Hashtable();
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static Hashtable ht_OpName_Status = new Hashtable();
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public static Hashtable ht_OpName_PMCReadTagIDArray = new Hashtable();
|
||
/// <summary>
|
||
/// 监控数据的所有变化,从这里产生
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public override void OPCTagData_TagDataOnChangeMIS(object sender, CustomeEvetnArgs e)
|
||
{
|
||
ThreadPool.QueueUserWorkItem(MIS_Funtion, e);
|
||
}
|
||
|
||
|
||
public void Tighten_E_ScanContent(string hex_str, string raw_str)
|
||
{
|
||
ThreadPool.QueueUserWorkItem(MIS_Tighten, new TightenParam
|
||
{
|
||
hex = hex_str ,
|
||
raw = raw_str
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 定时触发,检测PLC在线状态,周期:3 s
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="eState"></param>
|
||
public override void PlcStateEvent(object sender, PlcStateEvetnArgs eState)
|
||
{
|
||
|
||
}
|
||
|
||
public static string currentOpName = "";
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
[STAThread]
|
||
static void Main()
|
||
{
|
||
|
||
new System.Threading.Mutex(true, "Device Data SCADA", out bool bCanRun);
|
||
if (!bCanRun)
|
||
{
|
||
MessageBox.Show("设备数据采集 程序 已经在运行!不可重复启动!");
|
||
return;
|
||
}
|
||
|
||
Application.EnableVisualStyles();
|
||
Application.SetCompatibleTextRenderingDefault(false);
|
||
Application.Run(Temp.mesWorkForm = new MesWorkForm());
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读写取方法
|
||
/// </summary>
|
||
/// <param name="readWhat"></param>
|
||
/// <param name="opOrIp"></param>
|
||
private void DemoRead(string doWhat, string opOrIp)
|
||
{
|
||
try
|
||
{
|
||
string opName = "OP1010";
|
||
object tagValue = 1;
|
||
bool result = false;
|
||
ConcurrentDictionary<string, object> tagAdrListTagFormat = null;
|
||
|
||
switch (doWhat)
|
||
{
|
||
case "TagID":
|
||
tagValue = ReadPLC("71010001");
|
||
result = WritePLC("71010001", tagValue);
|
||
break;
|
||
case "TagTypeCodeID":
|
||
tagValue = ReadPLC(10, opName);
|
||
result = WritePLC(10, opName, tagValue);
|
||
break;
|
||
//case "Cmd":
|
||
// tagValue = ReadPLC((int)EnumTagTypeCodeID.EngineID, opName);
|
||
// result = WritePLC((int)EnumTagTypeCodeID.EngineID, opName, tagValue);
|
||
// break;
|
||
case "OpAllTag"://OP所有点
|
||
tagAdrListTagFormat = ReadPLC_GroupData(opOrIp);
|
||
break;
|
||
case "OpMonitorTag"://OP监控点
|
||
tagAdrListTagFormat = ReadPLC_GroupMonitor(opOrIp);
|
||
break;
|
||
case "IpAllTag"://IP所有点
|
||
tagAdrListTagFormat = ReadPLC_IpTag(opOrIp);
|
||
break;
|
||
case "IpMonitorTag"://IP监控点
|
||
tagAdrListTagFormat = ReadPLC_IpMonitorTag(opOrIp);
|
||
break;
|
||
case "RegionRead"://按区域读取(起始地址 + 长度)
|
||
{
|
||
string tagStartAdr = "DB411.10";
|
||
ushort tagAdrListMaxLength = 100;
|
||
GetDbAndMaxLengthByOpName(opOrIp, out tagStartAdr, out tagAdrListMaxLength);
|
||
tagAdrListTagFormat = ReadQualityDataList(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||
}
|
||
break;
|
||
case "ReadBytes"://按区域读取(起始地址 + 长度)
|
||
{
|
||
string tagStartAdr = "DB411.10";
|
||
ushort tagAdrListMaxLength = 100;
|
||
var bates1 = ReadByteData_Op(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||
var bates2 = ReadByteData_Ip(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||
}
|
||
break;
|
||
case "WriteBytes"://按区域读取(起始地址 + 长度)
|
||
{
|
||
string tagStartAdr = "DB411.10";
|
||
var result1 = WritePLC_Bytes_Op(opOrIp, tagStartAdr, new byte[1024]);
|
||
var result2 = WritePLC_Bytes_Ip(opOrIp, tagStartAdr, new byte[1024]);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
//ReadByteData_Op(string opName, string startAdrr, ushort length)
|
||
foreach (System.Collections.Generic.KeyValuePair<string, object> de in tagAdrListTagFormat)//得到工位监控点哈希表
|
||
{
|
||
TagFormat TF = (TagFormat)de.Value;
|
||
string recResult = TF.OpName + " (" + TF.TagTypeCodeID + ")" + TF.TagValue.ToString(); ;
|
||
}
|
||
}
|
||
catch (System.Exception err)
|
||
{
|
||
ApplicationLog.WriteLog("listView_ShowQualityData_Init" + err);
|
||
}
|
||
|
||
}
|
||
|
||
public string Hello_You_All_Never_Know(string[] args)
|
||
{
|
||
return Guid.NewGuid().ToString()+ Guid.NewGuid().ToString();
|
||
}
|
||
|
||
|
||
private void Button1_Click(object sender, System.EventArgs e)
|
||
{
|
||
ConcurrentDictionary<string, object> tagTypeCodeIDList = DriverCache[CacheType.Cache_OpTagTypeCodeIDList];
|
||
}
|
||
|
||
|
||
public static void SavePrintLog(int type, string message)
|
||
{
|
||
try
|
||
{
|
||
if (IsLogFilePath == "0") return;
|
||
string directPath = LogFilePath.Trim();
|
||
if (!Directory.Exists(directPath)) //判断文件夹是否存在,如果不存在则创建
|
||
{
|
||
Directory.CreateDirectory(directPath);
|
||
}
|
||
directPath += string.Format(@"\{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
|
||
if (streamWriter == null)
|
||
{
|
||
streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); //判断文件是否存在如果不存在则创建,如果存在则添加。
|
||
}
|
||
streamWriter.WriteLine("***********************************************************************");
|
||
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
|
||
if (message != null)
|
||
{
|
||
if (type == 0)
|
||
{
|
||
streamWriter.WriteLine("记录信息:\r\n" + message);
|
||
}
|
||
else
|
||
{
|
||
streamWriter.WriteLine("异常信息:\r\n" + message);
|
||
}
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
if (streamWriter != null)
|
||
{
|
||
streamWriter.Flush();
|
||
streamWriter.Dispose();
|
||
streamWriter = null;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
static private void Loop()
|
||
{
|
||
while (true)
|
||
{
|
||
taskSql.TryDequeue(out ParamT tp);
|
||
if (tp != null)
|
||
{
|
||
var procedureName = tp.procedureName;
|
||
var sqlParameter = tp.sqlParameter;
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure(procedureName, MesWorkForm.ConnectionString, ref sqlParameter, out string errorMessage);
|
||
if (errorMessage.Length > 0)
|
||
{
|
||
errorMessage = errorMessage.Replace("'","**");
|
||
LogRecord.LogRecord.Insert_Log(LogRecord.LogRecord.Type_Log.Alarm, errorMessage);
|
||
}
|
||
}
|
||
if (taskSql.Count < 5)
|
||
{
|
||
Thread.Sleep(15);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
private void DatatableCol_Simplify(DataTable dt_pmc)
|
||
{
|
||
dt_pmc_Simplify = new DataTable();
|
||
dt_pmc_Simplify.Columns.Add("TagID");
|
||
dt_pmc_Simplify.Columns.Add("TagName");
|
||
dt_pmc_Simplify.Columns.Add("TagValue");
|
||
dt_pmc_Simplify.Columns.Add("工位号");
|
||
dt_pmc_Simplify.Columns.Add("数据来源");
|
||
dt_pmc_Simplify.Columns.Add("IP");
|
||
dt_pmc_Simplify.Columns.Add("TagTypeID");
|
||
dt_pmc_Simplify.Columns.Add("TagLong");
|
||
dt_pmc_Simplify.Columns.Add("DbName");
|
||
dt_pmc_Simplify.Columns.Add("变量类型");
|
||
dt_pmc_Simplify.Columns.Add("变量地址");
|
||
dt_pmc_Simplify.Columns.Add("变量其它");
|
||
dt_pmc_Simplify.Columns.Add("列位置");
|
||
dt_pmc_Simplify.Columns.Add("变量类型代码");
|
||
dt_pmc_Simplify.Columns.Add("变量类型名称");
|
||
dt_pmc_Simplify.Columns.Add("是否启用");
|
||
dt_pmc_Simplify.Columns.Add("是否监控");
|
||
|
||
var dt_pmcT = dt_pmc.Copy();
|
||
|
||
for (int i = 0; i < dt_pmcT.Rows.Count; i++)
|
||
{
|
||
var TagID = dt_pmcT.Rows[i]["TagID"].ToString();
|
||
var TagName = dt_pmcT.Rows[i]["TagName"].ToString();
|
||
var TagValue = "0";
|
||
var 工位号 = dt_pmcT.Rows[i]["工位号"].ToString();
|
||
var 数据来源 = dt_pmcT.Rows[i]["数据来源"].ToString();
|
||
var IP = dt_pmcT.Rows[i]["IP"].ToString();
|
||
var TagTypeID = dt_pmcT.Rows[i]["TagTypeID"].ToString();
|
||
var TagLong = dt_pmcT.Rows[i]["TagLong"].ToString();
|
||
var DbName = dt_pmcT.Rows[i]["DbName"].ToString();
|
||
var 变量类型 = dt_pmcT.Rows[i]["变量类型"].ToString();
|
||
var 变量地址 = dt_pmcT.Rows[i]["变量地址"].ToString();
|
||
var 变量其它 = dt_pmcT.Rows[i]["变量其它"].ToString();
|
||
var 列位置 = dt_pmcT.Rows[i]["列位置"].ToString();
|
||
var 变量类型代码 = dt_pmcT.Rows[i]["变量类型代码"].ToString();
|
||
var 变量类型名称 = dt_pmcT.Rows[i]["变量类型名称"].ToString();
|
||
var 是否启用 = dt_pmcT.Rows[i]["是否启用"].ToString();
|
||
var 是否监控 = dt_pmcT.Rows[i]["是否监控"].ToString();
|
||
|
||
ht_PLM_Old.Add(TagID, "0");
|
||
|
||
dt_pmc_Simplify.Rows.Add(
|
||
TagID,
|
||
TagName,
|
||
TagValue,
|
||
工位号 ,
|
||
数据来源 ,
|
||
IP ,
|
||
TagTypeID ,
|
||
TagLong ,
|
||
DbName ,
|
||
变量类型,
|
||
变量地址 ,
|
||
变量其它 ,
|
||
列位置,
|
||
变量类型代码,
|
||
变量类型名称,
|
||
是否启用,
|
||
是否监控
|
||
);
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
}
|
||
}
|