init: 潍柴发动机线 中央控制程序 项目首次入库
This commit is contained in:
477
SCADA/Core/AppConfig.cs
Normal file
477
SCADA/Core/AppConfig.cs
Normal file
@@ -0,0 +1,477 @@
|
||||
using DataLinkMesWork;
|
||||
using ExternalDataSync;
|
||||
using NPOI.POIFS.Properties;
|
||||
using OpcBasic;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using SystemFramework;
|
||||
using static System.Configuration.ConfigurationManager;
|
||||
|
||||
namespace MesWork
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class Temp {
|
||||
public static MesWorkForm mesWorkForm = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 配置信息
|
||||
/// </summary>
|
||||
public partial class MesWorkForm
|
||||
{
|
||||
|
||||
public static int workerThreads = 4000;
|
||||
public static int completionPortThreads = 2000;
|
||||
|
||||
public static string NotHandlerSignal = AppSettings["NotHandlerSignal"];
|
||||
public static string BasicDataTableFile = AppSettings["BasicDataTableFile"];
|
||||
public static int IsDemoMesServer = Convert.ToInt32(AppSettings["IsDemoMesServer"]);
|
||||
public static int IsAllowWrite = Convert.ToInt32(AppSettings["IsAllowWrite"]);
|
||||
public static int IsWriteMonitorLog = Convert.ToInt32(AppSettings["IsWriteMonitorLog"]);
|
||||
public static int IsWriteLog4 = Convert.ToInt32(AppSettings["IsWriteLog4"]);
|
||||
|
||||
public static string ConnectionString = AppSettings["ConnectionString"];
|
||||
|
||||
|
||||
public static string LineID_Product = AppSettings["LineID_Product"];
|
||||
//所有上线工位的工位名称
|
||||
public static string OPCodes_LineSet = AppSettings["OPCodes_LineSet"];
|
||||
|
||||
public static string WebAPI_Url_Boms = AppSettings["WebAPI_Url_Boms"];
|
||||
|
||||
public static string WebAPI_Url_Quality = AppSettings["WebAPI_Url_Quality"];
|
||||
public static string ProgramPartial = AppSettings["ProgramPartial"];
|
||||
|
||||
public static int WebSvrPort = Convert.ToInt32(AppSettings["WebSvrPort"]);
|
||||
|
||||
|
||||
public static Color color_Faw = Color.FromArgb(0, 44, 101);//蓝色,大众:0,44,101
|
||||
public static Color color_Good = Color.FromArgb(132, 185, 235);//浅蓝,自定义
|
||||
public static Color color_Wait = Color.FromArgb(240, 230, 140);//淡黄,显示等待状态
|
||||
public static Color color_Bad = SystemColors.ActiveBorder;//灰色,显示操作过程
|
||||
public static Color color_Control = SystemColors.Control;//控件默认颜色
|
||||
public static Color color_Grey = Color.FromArgb(192, 192, 192);//灰色,Table底色
|
||||
|
||||
public static Color color_Green = Color.FromArgb(22, 161, 136);//绿色
|
||||
public static Color color_Yellow = Color.FromArgb(246, 227, 74);//黄色
|
||||
public static Color color_Red = Color.FromArgb(255, 0, 0);//红色
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static ConcurrentQueue<OpcData.CustomeEvetnArgs> taskSql = new ConcurrentQueue<OpcData.CustomeEvetnArgs>();
|
||||
/// <summary>
|
||||
/// 在线状态
|
||||
/// </summary>
|
||||
public static bool OnLine_Sql = false;
|
||||
/// <summary>
|
||||
/// PMC列表
|
||||
/// </summary>
|
||||
public static DataTable dt_pmc_Simplify = null;
|
||||
/// <summary>
|
||||
/// PLC数据
|
||||
/// </summary>
|
||||
public static DataTable dt_PLC_Data = null;
|
||||
/// <summary>
|
||||
/// PMC列表
|
||||
/// </summary>
|
||||
public static Hashtable ht_PLM_Old = new Hashtable();
|
||||
/// <summary>
|
||||
/// PMC列表
|
||||
/// </summary>
|
||||
public static Hashtable ht_PLM_Curr = new Hashtable();
|
||||
/// <summary>
|
||||
/// ht_OpName_PMCReadTagIDArray
|
||||
/// </summary>
|
||||
public static Hashtable ht_OpName_PMCReadTagIDArray = new Hashtable();
|
||||
/// <summary>
|
||||
/// 工位打开记录
|
||||
/// </summary>
|
||||
public static List<String> list_OpenForm = new List<String>();
|
||||
/// <summary>
|
||||
/// IP和工位号的对应关系
|
||||
/// </summary>
|
||||
public static Dictionary<String, List<String>> G_DC_IP_OP = null;
|
||||
/// <summary>
|
||||
/// 设备的在线状态
|
||||
/// </summary>
|
||||
public static Hashtable ht_IP_OnLine = new Hashtable();
|
||||
/// <summary>
|
||||
/// 任务类型信息
|
||||
/// </summary>
|
||||
public static Hashtable ht_TaskTypeInfo = new Hashtable();
|
||||
/// <summary>
|
||||
/// 工位的自动信号
|
||||
/// </summary>
|
||||
public static Hashtable ht_Signal__Station_Auto = new Hashtable();
|
||||
/// <summary>
|
||||
/// 工位的运行信号
|
||||
/// </summary>
|
||||
public static Hashtable ht_Signal__Station_Running = new Hashtable();
|
||||
/// <summary>
|
||||
/// 工位的手动信号
|
||||
/// </summary>
|
||||
public static Hashtable ht_Signal__Station_Manual = new Hashtable();
|
||||
/// <summary>
|
||||
/// 工位的报警信号
|
||||
/// </summary>
|
||||
public static Hashtable ht_Signal__Station_Alarm = new Hashtable();
|
||||
/// <summary>
|
||||
/// 工位的掉线信号
|
||||
/// </summary>
|
||||
public static Hashtable ht_Signal__Station_OffLine = new Hashtable();
|
||||
/// <summary>
|
||||
/// 主界面显示的当前上线型号
|
||||
/// </summary>
|
||||
public static string RunSort = "6DM-1";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 允许移动
|
||||
/// </summary>
|
||||
public static bool allowDrag = false;
|
||||
/// <summary>
|
||||
/// 鼠标状态
|
||||
/// </summary>
|
||||
private static bool isMouseDown = false;
|
||||
/// <summary>
|
||||
/// 记录鼠标指针的坐标
|
||||
/// </summary>
|
||||
private static Point mouseOffset;
|
||||
/// <summary>
|
||||
/// 工位内容
|
||||
/// </summary>
|
||||
public static Hashtable ht_Station_Content = null;
|
||||
/// <summary>
|
||||
/// 工位文本描述
|
||||
/// </summary>
|
||||
public static Hashtable ht_Station_Label = null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Agv的DB地址
|
||||
/// </summary>
|
||||
public static DataTable dt_OPNameInfo = null;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 监控数据的所有变化,从这里产生
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public override void OPCTagData_TagDataOnChangeMIS(object sender, OpcData.CustomeEvetnArgs e)
|
||||
{
|
||||
//ThreadPool.QueueUserWorkItem(new WaitCallback(MIS_Funtion), e);
|
||||
//// 设备状态日志
|
||||
//ThreadPool.QueueUserWorkItem(TagTypeCodeID_TagDataOnChange, e);
|
||||
|
||||
MesWorkForm.taskSql.Enqueue(e);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 定时触发,检测PLC在线状态,周期:3 s
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="eState"></param>
|
||||
public override void PlcStateEvent(object sender, OpcData.PlcStateEvetnArgs eState)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(new WaitCallback(MIS_Device), eState);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="location"></param>
|
||||
/// <param name="content"></param>
|
||||
public override void E_WriteLog(Enum_LogType t, string location, string content)
|
||||
{
|
||||
if (content .Contains("GetTagIDByTagTypeCodeID(),"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
WriteLog_Info(t.ToString(), $"<[<{location}>]>{content}");
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
new System.Threading.Mutex(true, $"WC_MES_{MesWorkForm.ProgramPartial}1", out bool bCanRun);
|
||||
if (!bCanRun)
|
||||
{
|
||||
MessageBox.Show("MES采集系统 已经在运行!不可重复启动!");
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
private string Hello_You_All_Never_Know(string[] args)
|
||||
{
|
||||
return Guid.NewGuid().ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 测试按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Button1_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
var tagTypeCodeIDList = DriverCache[CacheType.Cache_OpTagTypeCodeIDList];
|
||||
}
|
||||
/// <summary>
|
||||
/// 定义列
|
||||
/// </summary>
|
||||
/// <param name="dt_pmc"></param>
|
||||
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, "-101");
|
||||
|
||||
dt_pmc_Simplify.Rows.Add(
|
||||
TagID,
|
||||
TagName,
|
||||
TagValue,
|
||||
工位号 ,
|
||||
数据来源 ,
|
||||
IP ,
|
||||
TagTypeID ,
|
||||
TagLong ,
|
||||
DbName ,
|
||||
变量类型,
|
||||
变量地址 ,
|
||||
变量其它 ,
|
||||
列位置,
|
||||
变量类型代码,
|
||||
变量类型名称,
|
||||
是否启用,
|
||||
是否监控
|
||||
);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加到窗体
|
||||
/// </summary>
|
||||
/// <param name="stationName"></param>
|
||||
/// <param name="c"></param>
|
||||
private void SetMember(string stationName, Control c)
|
||||
{
|
||||
panel_Lyout.Controls.Add(c);
|
||||
if (c is Panel)
|
||||
{
|
||||
ht_Station_Content.Add(stationName, c);
|
||||
}
|
||||
if (c is Label)
|
||||
{
|
||||
ht_Station_Label.Add(stationName, c);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 写入信号
|
||||
/// </summary>
|
||||
/// <param name="tagTypeCodeID"></param>
|
||||
/// <param name="ststionName"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void WritePLC_IF(int tagTypeCodeID,string ststionName,object value)
|
||||
{
|
||||
if (IsAllowWrite == 1)
|
||||
{
|
||||
WritePLC(tagTypeCodeID, ststionName, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string CVT_ReadValue(object value)
|
||||
{
|
||||
var result = "";
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (value.ToString ().ToLower () == "true" | value.ToString().ToLower() == "1")
|
||||
{
|
||||
result = "1";
|
||||
}
|
||||
if (value.ToString().ToLower() == "false" | value.ToString().ToLower() == "0")
|
||||
{
|
||||
result = "0";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 写日志
|
||||
/// 2023.10.30.llx
|
||||
/// </summary>
|
||||
public static void WriteLog_Info(string type, string msg, Exception ex = null)
|
||||
{
|
||||
if (IsWriteLog4 == 1)
|
||||
{
|
||||
MW_Log.LoggerHelper.Info(type, msg, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void Loop()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
taskSql.TryDequeue(out OpcData.CustomeEvetnArgs e);
|
||||
if (e != null)
|
||||
{
|
||||
MIS_Funtion(e);
|
||||
TagTypeCodeID_TagDataOnChange(e);
|
||||
}
|
||||
if (taskSql.Count < 3)
|
||||
{
|
||||
Thread.Sleep(15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UseMisFuntion(Object e)
|
||||
{
|
||||
MIS_Funtion(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
SCADA/Core/From_Opera.cs
Normal file
25
SCADA/Core/From_Opera.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using ExternalDataSync;
|
||||
using MesWork;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum From_Opera
|
||||
{
|
||||
/// <summary>
|
||||
/// 增加
|
||||
/// </summary>
|
||||
Insert = 1,
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
Update = 2
|
||||
}
|
||||
54
SCADA/Core/FuncOperation.cs
Normal file
54
SCADA/Core/FuncOperation.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MesWork
|
||||
{
|
||||
/// <summary>
|
||||
/// 功能操作
|
||||
/// </summary>
|
||||
public class FuncOperation
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存布局
|
||||
/// </summary>
|
||||
public static void SaveLyout()
|
||||
{
|
||||
foreach (DictionaryEntry item in MesWorkForm.ht_Station_Content)
|
||||
{
|
||||
var stationName = item.Key.ToString();
|
||||
var control = (Panel)item.Value;
|
||||
var px = control.Location.X;
|
||||
var py = control.Location.Y;
|
||||
ExecuteDB.SaveLyout_P(stationName, px, py);
|
||||
}
|
||||
foreach (DictionaryEntry item in MesWorkForm.ht_Station_Label)
|
||||
{
|
||||
var stationName = item.Key.ToString();
|
||||
var control = (Label)item.Value;
|
||||
var px = control.Location.X;
|
||||
var py = control.Location.Y;
|
||||
ExecuteDB.SaveLyout_PT(stationName, px, py);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
130
SCADA/Core/MyPlcData.cs
Normal file
130
SCADA/Core/MyPlcData.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConverterBytesAndStruct
|
||||
{
|
||||
#region QC_DATA TS
|
||||
/// <summary>
|
||||
/// 质量数据,26个字节
|
||||
/// </summary>
|
||||
public class QC_DATA
|
||||
{
|
||||
/// <summary>
|
||||
/// 工作类型(1=拧紧,2=压装,4=测量,8=试漏)
|
||||
/// </summary>
|
||||
public short Work_Type;
|
||||
/// <summary>
|
||||
/// 工作的程序号
|
||||
/// </summary>
|
||||
public short Progarm_Code;
|
||||
/// <summary>
|
||||
/// 具体的位置号
|
||||
/// </summary>
|
||||
public short Counter_Number;
|
||||
/// <summary>
|
||||
/// 工位被屏蔽
|
||||
/// </summary>
|
||||
public bool Bypass;
|
||||
/// <summary>
|
||||
/// 工位未工作
|
||||
/// </summary>
|
||||
public bool No_op;
|
||||
/// <summary>
|
||||
/// 工位工作完成且合格
|
||||
/// </summary>
|
||||
public bool Accept;
|
||||
/// <summary>
|
||||
/// 工位工作完成但不合格
|
||||
/// </summary>
|
||||
public bool Reject;
|
||||
|
||||
public byte SPARE1;
|
||||
public short SPARE2;
|
||||
/// <summary>
|
||||
/// 质量数据1 (拧紧对应扭矩,压装对应压力,测量对应位移,试漏对应泄露率)
|
||||
/// </summary>
|
||||
public float QC_DATA1;
|
||||
/// <summary>
|
||||
/// 质量数据2 (拧紧对应转角,压装对应位移,测量无,试漏对应压力)
|
||||
/// </summary>
|
||||
public float QC_DATA2;
|
||||
/// <summary>
|
||||
/// 质量数据3
|
||||
/// </summary>
|
||||
public float QC_DATA3;
|
||||
/// <summary>
|
||||
/// 质量数据4
|
||||
/// </summary>
|
||||
public float QC_DATA4;
|
||||
|
||||
}
|
||||
public class QC_DATA_OutSide
|
||||
{
|
||||
/// <summary>
|
||||
/// 工作类型(1=拧紧,2=压装,4=测量,8=试漏)
|
||||
/// </summary>
|
||||
public short Work_Type;
|
||||
/// <summary>
|
||||
/// 工作的程序号
|
||||
/// </summary>
|
||||
public short Progarm_Code;
|
||||
/// <summary>
|
||||
/// 具体的位置号
|
||||
/// </summary>
|
||||
public short Counter_Number;
|
||||
|
||||
public short SPARE1;
|
||||
public short SPARE2;
|
||||
|
||||
/// <summary>
|
||||
/// 质量数据1 (拧紧对应扭矩,压装对应压力,测量对应位移,试漏对应泄露率)
|
||||
/// </summary>
|
||||
public float QC_DATA1;
|
||||
/// <summary>
|
||||
/// 质量数据2 (拧紧对应转角,压装对应位移,测量无,试漏对应压力)
|
||||
/// </summary>
|
||||
public float QC_DATA2;
|
||||
/// <summary>
|
||||
/// 质量数据3
|
||||
/// </summary>
|
||||
public float QC_DATA3;
|
||||
/// <summary>
|
||||
/// 质量数据4
|
||||
/// </summary>
|
||||
public float QC_DATA4;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 时间戳 22
|
||||
/// </summary>
|
||||
public class TS
|
||||
{
|
||||
public byte Max_Len;
|
||||
public byte Act_Len;
|
||||
public char Month_B1;
|
||||
public char Month_B0;
|
||||
public char Slash1;
|
||||
public char Day_B1;
|
||||
public char Day_B0;
|
||||
public char Slash2;
|
||||
public char Fixed_dgt1;
|
||||
public char Fixed_dgt2;
|
||||
public char Year_B1;
|
||||
public char Year_B0;
|
||||
public char Null1;
|
||||
public char Hour_B1;
|
||||
public char Hour_B0;
|
||||
public char Colon1;
|
||||
public char Min_B1;
|
||||
public char Min_B0;
|
||||
public char Colon2;
|
||||
public char Sec_B1;
|
||||
public char Sec_B0;
|
||||
public char Null2;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
517
SCADA/Core/OExcel.cs
Normal file
517
SCADA/Core/OExcel.cs
Normal file
@@ -0,0 +1,517 @@
|
||||
using NPOI.HPSF;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NPOITest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Execl工具辅助类
|
||||
/// </summary>
|
||||
public class ExeclHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 读取Execl数据到DataTable中
|
||||
/// </summary>
|
||||
/// <param name="filePath">指定Execl文件路径</param>
|
||||
/// <param name="isColumnName">设置第一行是否是列名</param>
|
||||
/// <returns>返回一个DataTable数据集</returns>
|
||||
public static DataTable ExcelToDataTable(string filePath, string sheetName, bool isColumnName)
|
||||
{
|
||||
DataTable dataTable = null;
|
||||
FileStream fs = null;
|
||||
DataColumn column = null;
|
||||
DataRow dataRow = null;
|
||||
IWorkbook workbook = null;
|
||||
ISheet sheet = null;
|
||||
IRow row = null;
|
||||
ICell cell = null;
|
||||
int startRow = 0;
|
||||
try
|
||||
{
|
||||
using (fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
// 2007版本
|
||||
if (filePath.IndexOf(".xlsx") > 0)
|
||||
workbook = new XSSFWorkbook(fs);
|
||||
// 2003版本
|
||||
else if (filePath.IndexOf(".xls") > 0)
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
if (workbook != null)
|
||||
{
|
||||
sheet = workbook.GetSheet(sheetName);//读取第一个sheet,当然也可以循环读取每个sheet
|
||||
dataTable = new DataTable();
|
||||
if (sheet != null)
|
||||
{
|
||||
int rowCount = sheet.LastRowNum;//总行数
|
||||
if (rowCount > 0)
|
||||
{
|
||||
IRow firstRow = sheet.GetRow(0);//第一行
|
||||
int cellCount = firstRow.LastCellNum;//列数
|
||||
|
||||
//构建datatable的列
|
||||
if (isColumnName)
|
||||
{
|
||||
startRow = 1;//如果第一行是列名,则从第二行开始读取
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
cell = firstRow.GetCell(i);
|
||||
if (cell != null)
|
||||
{
|
||||
if (cell.StringCellValue != null)
|
||||
{
|
||||
column = new DataColumn(cell.StringCellValue);
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
column = new DataColumn("column" + (i + 1));
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
//填充行
|
||||
for (int i = startRow; i <= rowCount; ++i)
|
||||
{
|
||||
row = sheet.GetRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
dataRow = dataTable.NewRow();
|
||||
for (int j = row.FirstCellNum; j < cellCount; ++j)
|
||||
{
|
||||
cell = row.GetCell(j);
|
||||
if (cell == null)
|
||||
{
|
||||
dataRow[j] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
//CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.Blank:
|
||||
dataRow[j] = "";
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
short format = cell.CellStyle.DataFormat;
|
||||
//对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
|
||||
if (format == 14 || format == 31 || format == 57 || format == 58)
|
||||
dataRow[j] = cell.DateCellValue;
|
||||
else
|
||||
dataRow[j] = cell.NumericCellValue;
|
||||
break;
|
||||
case CellType.String:
|
||||
dataRow[j] = cell.StringCellValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dataTable.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataTable;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static DataTable ExcelToDataTable(string filePath,int sheetIndex, bool isColumnName)
|
||||
{
|
||||
DataTable dataTable = null;
|
||||
FileStream fs = null;
|
||||
DataColumn column = null;
|
||||
DataRow dataRow = null;
|
||||
IWorkbook workbook = null;
|
||||
ISheet sheet = null;
|
||||
IRow row = null;
|
||||
ICell cell = null;
|
||||
int startRow = 0;
|
||||
try
|
||||
{
|
||||
using (fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
// 2007版本
|
||||
if (filePath.IndexOf(".xlsx") > 0)
|
||||
workbook = new XSSFWorkbook(fs);
|
||||
// 2003版本
|
||||
else if (filePath.IndexOf(".xls") > 0)
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
if (workbook != null)
|
||||
{
|
||||
sheet = workbook.GetSheetAt(sheetIndex);//读取第一个sheet,当然也可以循环读取每个sheet
|
||||
dataTable = new DataTable();
|
||||
if (sheet != null)
|
||||
{
|
||||
int rowCount = sheet.LastRowNum;//总行数
|
||||
if (rowCount > 0)
|
||||
{
|
||||
IRow firstRow = sheet.GetRow(0);//第一行
|
||||
int cellCount = firstRow.LastCellNum;//列数
|
||||
|
||||
//构建datatable的列
|
||||
if (isColumnName)
|
||||
{
|
||||
startRow = 1;//如果第一行是列名,则从第二行开始读取
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
cell = firstRow.GetCell(i);
|
||||
if (cell != null)
|
||||
{
|
||||
if (cell.StringCellValue != null)
|
||||
{
|
||||
column = new DataColumn(cell.StringCellValue);
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
column = new DataColumn("column" + (i + 1));
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
//填充行
|
||||
for (int i = startRow; i <= rowCount; ++i)
|
||||
{
|
||||
row = sheet.GetRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
dataRow = dataTable.NewRow();
|
||||
for (int j = row.FirstCellNum; j < cellCount; ++j)
|
||||
{
|
||||
cell = row.GetCell(j);
|
||||
if (cell == null)
|
||||
{
|
||||
dataRow[j] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
//CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.Blank:
|
||||
dataRow[j] = "";
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
short format = cell.CellStyle.DataFormat;
|
||||
//对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
|
||||
if (format == 14 || format == 31 || format == 57 || format == 58 || format == 22)
|
||||
dataRow[j] = cell.DateCellValue;
|
||||
else
|
||||
dataRow[j] = cell.NumericCellValue;
|
||||
break;
|
||||
case CellType.String:
|
||||
dataRow[j] = cell.StringCellValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dataTable.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataTable;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable导出到Execl文档
|
||||
/// </summary>
|
||||
/// <param name="dt">传入一个DataTable数据集</param>
|
||||
/// <returns>返回一个Bool类型的值,表示是否导出成功</returns>
|
||||
/// True表示导出成功,Flase表示导出失败
|
||||
public static bool DataTableToExcel(DataTable dt, string sheetName, string Outpath)
|
||||
{
|
||||
bool result = false;
|
||||
IWorkbook workbook = null;
|
||||
FileStream fs = null;
|
||||
IRow row = null;
|
||||
ISheet sheet = null;
|
||||
ICell cell = null;
|
||||
try
|
||||
{
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
workbook = new HSSFWorkbook();
|
||||
sheet = workbook.CreateSheet(sheetName);//创建一个名称为Sheet0的表
|
||||
int rowCount = dt.Rows.Count;//行数
|
||||
int columnCount = dt.Columns.Count;//列数
|
||||
|
||||
//设置列头
|
||||
row = sheet.CreateRow(0);//excel第一行设为列头
|
||||
for (int c = 0; c < columnCount; c++)
|
||||
{
|
||||
cell = row.CreateCell(c);
|
||||
cell.SetCellValue(dt.Columns[c].ColumnName);
|
||||
}
|
||||
|
||||
//设置每行每列的单元格,
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
{
|
||||
row = sheet.CreateRow(i + 1);
|
||||
for (int j = 0; j < columnCount; j++)
|
||||
{
|
||||
cell = row.CreateCell(j);//excel第二行开始写入数据
|
||||
cell.SetCellValue(dt.Rows[i][j].ToString());
|
||||
}
|
||||
}
|
||||
//向outPath输出数据
|
||||
using (fs = File.OpenWrite(Outpath))
|
||||
{
|
||||
workbook.Write(fs);//向打开的这个xls文件中写入数据
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取Execl数据到DataTable(DataSet)中
|
||||
/// </summary>
|
||||
/// <param name="filePath">指定Execl文件路径</param>
|
||||
/// <param name="isFirstLineColumnName">设置第一行是否是列名</param>
|
||||
/// <returns>返回一个DataTable数据集</returns>
|
||||
public static DataSet ExcelToDataSet(string filePath, bool isFirstLineColumnName)
|
||||
{
|
||||
DataSet dataSet = new DataSet();
|
||||
int startRow = 0;
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
IWorkbook workbook = null;
|
||||
// 如果是2007+的Excel版本
|
||||
if (filePath.IndexOf(".xlsx") > 0)
|
||||
{
|
||||
workbook = new XSSFWorkbook(fs);
|
||||
}
|
||||
// 如果是2003-的Excel版本
|
||||
else if (filePath.IndexOf(".xls") > 0)
|
||||
{
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
}
|
||||
if (workbook != null)
|
||||
{
|
||||
//循环读取Excel的每个sheet,每个sheet页都转换为一个DataTable,并放在DataSet中
|
||||
for (int p = 0; p < workbook.NumberOfSheets; p++)
|
||||
{
|
||||
ISheet sheet = workbook.GetSheetAt(p);
|
||||
DataTable dataTable = new DataTable();
|
||||
dataTable.TableName = sheet.SheetName;
|
||||
if (sheet != null)
|
||||
{
|
||||
int rowCount = sheet.LastRowNum;//获取总行数
|
||||
if (rowCount > 0)
|
||||
{
|
||||
IRow firstRow = sheet.GetRow(0);//获取第一行
|
||||
int cellCount = firstRow.LastCellNum;//获取总列数
|
||||
|
||||
//构建datatable的列
|
||||
if (isFirstLineColumnName)
|
||||
{
|
||||
startRow = 1;//如果第一行是列名,则从第二行开始读取
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
ICell cell = firstRow.GetCell(i);
|
||||
if (cell != null)
|
||||
{
|
||||
if (cell.StringCellValue != null)
|
||||
{
|
||||
DataColumn column = new DataColumn(cell.StringCellValue);
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
DataColumn column = new DataColumn("column" + (i + 1));
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
//填充行
|
||||
for (int i = startRow; i <= rowCount; ++i)
|
||||
{
|
||||
IRow row = sheet.GetRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
DataRow dataRow = dataTable.NewRow();
|
||||
for (int j = row.FirstCellNum; j < cellCount; ++j)
|
||||
{
|
||||
ICell cell = row.GetCell(j);
|
||||
if (cell == null)
|
||||
{
|
||||
dataRow[j] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
//CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.Blank:
|
||||
dataRow[j] = "";
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
short format = cell.CellStyle.DataFormat;
|
||||
//对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
|
||||
if (format == 14 || format == 31 || format == 57 || format == 58)
|
||||
dataRow[j] = cell.DateCellValue;
|
||||
else
|
||||
dataRow[j] = cell.NumericCellValue;
|
||||
break;
|
||||
case CellType.String:
|
||||
dataRow[j] = cell.StringCellValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dataTable.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
dataSet.Tables.Add(dataTable);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return dataSet;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable(DataSet)导出到Execl文档
|
||||
/// </summary>
|
||||
/// <param name="dataSet">传入一个DataSet</param>
|
||||
/// <param name="Outpath">导出路径(可以不加扩展名,不加默认为.xls)</param>
|
||||
/// <returns>返回一个Bool类型的值,表示是否导出成功</returns>
|
||||
/// True表示导出成功,Flase表示导出失败
|
||||
public static bool DataSetToExcel(DataSet dataSet, string Outpath)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
if (dataSet == null || dataSet.Tables == null || dataSet.Tables.Count == 0 || string.IsNullOrEmpty(Outpath))
|
||||
throw new Exception("输入的DataSet或路径异常");
|
||||
int sheetIndex = 0;
|
||||
//根据输出路径的扩展名判断workbook的实例类型
|
||||
IWorkbook workbook = null;
|
||||
string pathExtensionName = Outpath.Trim().Substring(Outpath.Length - 5);
|
||||
if (pathExtensionName.Contains(".xlsx"))
|
||||
{
|
||||
workbook = new XSSFWorkbook();
|
||||
}
|
||||
else if (pathExtensionName.Contains(".xls"))
|
||||
{
|
||||
workbook = new HSSFWorkbook();
|
||||
}
|
||||
else
|
||||
{
|
||||
Outpath = Outpath.Trim() + ".xls";
|
||||
workbook = new HSSFWorkbook();
|
||||
}
|
||||
//将DataSet导出为Excel
|
||||
foreach (DataTable dt in dataSet.Tables)
|
||||
{
|
||||
sheetIndex++;
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
ISheet sheet = workbook.CreateSheet(string.IsNullOrEmpty(dt.TableName) ? ("sheet" + sheetIndex) : dt.TableName);//创建一个名称为Sheet0的表
|
||||
int rowCount = dt.Rows.Count;//行数
|
||||
int columnCount = dt.Columns.Count;//列数
|
||||
|
||||
//设置列头
|
||||
IRow row = sheet.CreateRow(0);//excel第一行设为列头
|
||||
for (int c = 0; c < columnCount; c++)
|
||||
{
|
||||
ICell cell = row.CreateCell(c);
|
||||
cell.SetCellValue(dt.Columns[c].ColumnName);
|
||||
}
|
||||
|
||||
//设置每行每列的单元格,
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
{
|
||||
row = sheet.CreateRow(i + 1);
|
||||
for (int j = 0; j < columnCount; j++)
|
||||
{
|
||||
ICell cell = row.CreateCell(j);//excel第二行开始写入数据
|
||||
cell.SetCellValue(dt.Rows[i][j].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//向outPath输出数据
|
||||
using (FileStream fs = File.OpenWrite(Outpath))
|
||||
{
|
||||
workbook.Write(fs);//向打开的这个xls文件中写入数据
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
67
SCADA/Core/PLC_R.cs
Normal file
67
SCADA/Core/PLC_R.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using MesWork;
|
||||
using Newtonsoft.Json;
|
||||
using OpcBasic;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace DC_A95
|
||||
{
|
||||
public class PLC_R
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="opCode">工位号</param>
|
||||
/// <param name="partCode">上线缸体码</param>
|
||||
/// <param name="palletNo">托盘号</param>
|
||||
/// <returns></returns>
|
||||
public static bool Read_LineSet(string opCode, out string partCode, out int palletNo)
|
||||
{
|
||||
partCode = MesWorkForm.ReadPLC(120, opCode).ToString();
|
||||
palletNo = Convert.ToInt32(MesWorkForm.ReadPLC(80, opCode));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string GetString_CleanGarbled(string inputStr)
|
||||
{
|
||||
return inputStr.Replace("\0", "").Replace("\n", "").Replace("\r", "").Replace(" ", "");
|
||||
}
|
||||
|
||||
|
||||
public static ConcurrentDictionary<string, TagFormat> ReadPLC_OpName(string opName)
|
||||
{
|
||||
if (MesWorkForm.IsDemoMesServer == 1)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<
|
||||
ConcurrentDictionary<string, TagFormat>
|
||||
>(JsonConvert.SerializeObject(
|
||||
PlcLinkForm.ReadPLC_GroupData(opName)
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
PlcLinkForm.GetDbAndMaxLengthByOpName(opName, out string tagStartAdr, out ushort tagAdrListMaxLength);
|
||||
return JsonConvert.DeserializeObject<
|
||||
ConcurrentDictionary<string, TagFormat>
|
||||
>(JsonConvert.SerializeObject(PlcLinkForm.ReadQualityDataList(
|
||||
opName
|
||||
, tagStartAdr
|
||||
, tagAdrListMaxLength
|
||||
)
|
||||
));
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
65
SCADA/Core/PLC_W.cs
Normal file
65
SCADA/Core/PLC_W.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using MesWork;
|
||||
using System;
|
||||
|
||||
namespace DC_A95
|
||||
{
|
||||
public class PLC_W
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="opCode"></param>
|
||||
/// <param name="partCode"></param>
|
||||
/// <param name="palletNo"></param>
|
||||
/// <returns></returns>
|
||||
public static void Write_LineSetAlarm(string opCode, int errCode)
|
||||
{
|
||||
//112 发动机上线报警代码
|
||||
//34 发动机上线报警标志
|
||||
MesWorkForm.WritePLC_IF(112, opCode, errCode);
|
||||
MesWorkForm.WritePLC_IF(34, opCode,true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum Type_AlarmOnline
|
||||
{
|
||||
/// <summary>
|
||||
/// 0-无错误
|
||||
/// </summary>
|
||||
Err_Not = 0,
|
||||
/// <summary>
|
||||
/// 1-PLC逻辑错误,未申请上线
|
||||
/// </summary>
|
||||
Err_PLC_Logic = 1,
|
||||
/// <summary>
|
||||
/// 2-没有可用订单
|
||||
/// </summary>
|
||||
Err_NoOrder = 2,
|
||||
/// <summary>
|
||||
/// 3-扫描缸体码为空或格式错误
|
||||
/// </summary>
|
||||
Err_PartCode_Illegal = 3,
|
||||
/// <summary>
|
||||
/// 4-缸体机型与生产机型不匹配
|
||||
/// </summary>
|
||||
Err_Sort = 4,
|
||||
/// <summary>
|
||||
/// 5-AMS写入信息与RFID信息验证不一致
|
||||
/// </summary>
|
||||
Err_RW_Diff = 5,
|
||||
/// <summary>
|
||||
/// 255-未知错误
|
||||
/// </summary>
|
||||
Undefined = 255,
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
70
SCADA/Core/SqlOperation.cs
Normal file
70
SCADA/Core/SqlOperation.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using MesWork;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SlMesDbIterface
|
||||
{
|
||||
public class SqlOperation
|
||||
{
|
||||
public static bool ExecuteStoredProcedure(string name, SqlParameter[] sqlParameters, out string errorMessage)
|
||||
{
|
||||
return DataLinkMesWork.SQLCommon.ExecuteStoredProcedure(name, MesWorkForm.ConnectionString, ref sqlParameters, out errorMessage);
|
||||
}
|
||||
public static bool ExecuteStoredProcedure(string name, SqlParameter[] sqlParameters, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
return DataLinkMesWork.SQLCommon.ExecuteStoredProcedure(name, MesWorkForm.ConnectionString, ref sqlParameters, out dt, out errorMessage);
|
||||
}
|
||||
public static bool ExecuteStoredProcedure(string name, SqlParameter[] sqlParameters, out DataSet ds, out string errorMessage)
|
||||
{
|
||||
return DataLinkMesWork.SQLCommon.ExecuteStoredProcedure(name, MesWorkForm.ConnectionString, ref sqlParameters, out ds, out errorMessage);
|
||||
}
|
||||
public static bool ExecuteSql(string sql, out DataTable dt, out string errorMessage)
|
||||
{
|
||||
return DataLinkMesWork.SQLCommon.ExecuteSql(sql, MesWorkForm.ConnectionString, out dt, out errorMessage);
|
||||
}
|
||||
|
||||
public static bool ExecuteSql(string sql, out DataSet ds, out string errorMessage)
|
||||
{
|
||||
return DataLinkMesWork.SQLCommon.ExecuteDataset(sql, MesWorkForm.ConnectionString, out ds, out errorMessage);
|
||||
}
|
||||
|
||||
public static bool ExecuteSql(string sql, out string errorMessage)
|
||||
{
|
||||
return DataLinkMesWork.SQLCommon.ExecuteSql(sql, MesWorkForm.ConnectionString, out errorMessage);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过SqlBulkCopy复制table数据到数据库
|
||||
/// </summary>
|
||||
/// <param name="dataset"></param>
|
||||
public static bool SqlbulkcopyInsert(DataTable dt)
|
||||
{
|
||||
bool success = false;
|
||||
try
|
||||
{
|
||||
// SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(connectString, SqlBulkCopyOptions.KeepIdentity);//删除自增ID插入原始数据
|
||||
SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(MesWorkForm.ConnectionString, SqlBulkCopyOptions.UseInternalTransaction);//批量事务处理
|
||||
sqlbulkcopy.DestinationTableName = dt.TableName;//数据库中的表名
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
var columnName = dt.Columns[i].ColumnName.ToString();
|
||||
sqlbulkcopy.ColumnMappings.Add(columnName, columnName);
|
||||
}
|
||||
sqlbulkcopy.WriteToServer(dt);
|
||||
success = true;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
return success;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
466
SCADA/Core/TagTypeCodeID.cs
Normal file
466
SCADA/Core/TagTypeCodeID.cs
Normal file
@@ -0,0 +1,466 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
///1 X WorkStart 2 工件到位(PLC) 工件到位。托盘到达工位,并且托盘上有工件。
|
||||
///2 X RepairPartStatusPLC 3 RepairPartStatusPLC 备用
|
||||
///3 STRING RepairPathString 4 RepairPathString "工位返修字符串(121211112222111),前2位是西门子字符串格式,第一位是总长度,第二位是实际长度"
|
||||
///4 X EngineTypeGetOverMES 5 传递机型(MES) MES传递总成信息给PLC(上线工位)
|
||||
///5 X PartPalletGoOver 6 PartPalletGoOver 上线工位。0:正常工作;1:空托盘放行,PLC读取到此标志不走申请上线逻辑。
|
||||
///6 X MaterialVerifyOver 7 MaterialVerifyOver MES保存完质量数据,物料数据等与PLC信号交互完成后通知PLC,所以工步都完成,才可以放行工件,正常工作时工件放行的必要条件。
|
||||
///7 X FalseGo 8 FalseGo 按MES界面[不合格放行]按钮,MES发送此信号。操作者判断工件不合格,通知设备,按不合格方式放行工件,工件流转到返修下线工位后,返修下线。MES工作完成MES0.3=1,MES合格放行MES0.5=0,MES0.4=1
|
||||
///8 INT EngineTypeID 9 EngineTypeID MES发动机机型标志(必须PLC)
|
||||
///9 STRING EngineID 10 EngineID MES发动机编号(必须PLC)
|
||||
///10 STRING EngineType 11 机型(MES) MES发动机机型(必须PLC)
|
||||
///11 X PartPalletStatus 13 PartPalletStatus MES激发变量托盘到位离开(必须PLC)
|
||||
///12 X HeartBeatPLC 14 HeartBeatPLC 心跳处理:PLC收到MES心跳信号后,PLC延时5秒后,数值取反再写回PLC,写回PLC开始计时,如果5秒钟MES无反馈报通讯故障。
|
||||
///13 X HeartBeatMIS 15 HeartBeatMIS 间隔时间5S,心跳处理。收到PLC心跳信号后,MES按原值回写。PLC收到MES信号后延时5秒,取反写入,以此循环。
|
||||
///14 X TargetTimeRead 16 TargetTimeRead MES允许可读工位运行时间
|
||||
///15 Int MachineTargetTime 17 MachineTargetTime 目标运行时间
|
||||
///16 Int MachineActualTime 18 MachineActualTime 实际运行时间
|
||||
///17 X MesRead 19 允许保存(PLC) 质量数据可以读数据
|
||||
///18 X MesReadOver 20 保存完成(MES) MES保存完数据(必须MIS)
|
||||
///19 INT QualityMask 21 合格标志(PLC) 质量数据工位合格标志0:没有工作;1:合格 ;2 :不合格(必须PLC)
|
||||
///20 B PalletInfo 22 PalletInfo 0空托盘,1合格件,2不合格件
|
||||
///21 INT RepairStatusPLC 23 RepairStatusPLC 0正常件,1返修件
|
||||
///22 INT OrderNo 24 订单号(MES) 订单号(MES)
|
||||
///23 X StorageNo 25 库位号(MES) 库位号(MES)
|
||||
///24 X AllowPass 26 允许放行(MES) 允许放行
|
||||
///25 X PartLoadFinish 27 PartLoadFinish PartLoadFinish
|
||||
///26 X Reserved_7 28 Reserved_7 备用
|
||||
///27 X Reserved_8 29 Reserved_8 备用
|
||||
///28 X Reserved_9 30 Reserved_9 备用
|
||||
///29 X Reserved_10 31 Reserved_10 备用
|
||||
///30 X Reserved_11 32 Reserved_11 备用
|
||||
///31 X Reserved_12 33 Reserved_12 备用
|
||||
///32 X Reserved_13 34 Reserved_13 备用
|
||||
///33 X Reserved_14 35 Reserved_14 备用
|
||||
///34 Int PLCSPareint1 36 PLCSPareint1 备用
|
||||
///35 Int PLCSPareint2 37 PLCSPareint2 备用
|
||||
///36 Int PLCSPareint3 38 PLCSPareint3 备用
|
||||
///37 STRING PLCSarestring1 39 PLCSarestring1 备用
|
||||
///38 STRING PLCSarestring2 40 PLCSarestring2 备用
|
||||
///39 STRING MarkID 42 MarkID 机体打标号(MES)前2位是西门子字符串格式,第一位是总长度,第二位是实际长度
|
||||
///40 X PartLoad 43 PartLoad 上线工位,PLC向MES申请总成编号。收到该信号后,MES将机型标志(DBB22 ~23)、总成号(DBB24 ~63)、总成机型DBB64 ~103写入PLC。之后MES通过信号“传递机型(DBX0.1)”通知PLC。
|
||||
///41 X EngineTypeGetOverPLC 44 传递机型(PLC) PLC将机型标志(DBB50…51)、工件编号(DBB52…101)、产品型号(DBB102…187)、托盘编号(DBB188…189)准备完毕后,通知MES。
|
||||
///42 X PartLoadOK 48 PartLoadOK 备用
|
||||
///43 X Reserved_18 49 Reserved_18 备用
|
||||
///44 X PalletDown 50 PalletDown 暂时保留,项目未使用
|
||||
///45 X ConfirmOkGo 51 ConfirmOkGo 按MES界面[合格放行]按钮,MES发送此信号。操作者判断工件合格,通知设备,工件按合格方式放行工件。MES工作完成MES0.3=1,MES合格放行MES0.5=1,MES0.4=0
|
||||
///46 X ResetDevice 52 ResetDevice 针对手动工位,无HMI,需要复位设备在MES页面操作。
|
||||
///47 X UnloadCompleted 53 UnloadCompleted 暂时保留,项目未使用
|
||||
///48 X MachineTime_ReadOver 54 MachineTime_ReadOver 备用
|
||||
///49 X Reserved_19 58 Reserved_19 备用
|
||||
///50 X FixOK 59 FixOK 手动拧紧工位,单工步螺栓拧紧完成,通知PC读取数据。
|
||||
///51 X Reserved_21 61 Reserved_21 备用
|
||||
///52 X Reserved_22 62 Reserved_22 备用
|
||||
///53 X Reserved_23 63 Reserved_23 备用
|
||||
///54 X Reserved_24 64 Reserved_24 备用
|
||||
///55 X Reserved_25 65 Reserved_25 备用
|
||||
///56 X FixAllow 66 FixAllow "设备工作的必须信号,对于有物料验证的工位,MES验证完成给出此信号,对于无物料验证工位,MES直接给出此信号。"
|
||||
///57 X FixOver 67 FixOver 用于手动拧紧且有质量数据工位。通知设备当前工步拧紧螺钉工作结束。
|
||||
///58 X MatchingCompleted 68 MatchingCompleted 分线上总线,匹配成功是1;不成功是0。
|
||||
///59 X Match 69 Match 分线上总线,匹配成功是1;不成功是0。
|
||||
///60 X Reserved_2 70 Reserved_2 备用
|
||||
///61 X IsAutoGetEngineID 71 IsAutoGetEngineID 自动手动申请工件编号。0是自动方式;1:手动方式。暂时保留,生成流水号方式是在数据库中实现的
|
||||
///62 X RepairUplineMES 72 RepairUplineMES 上线清空MOBY(针对上线工位):通知PLC从新开始申请上线流程
|
||||
///63 INT EngineTypeID_MES 73 机型代码(MES) MES发动机机型标志(必须MES)
|
||||
///64 STRING EngineID_MES 74 工件编号(MES) MES发动机编号(必须MES)
|
||||
///65 STRING EngineType_MES 75 EngineType_MES MES发动机机型(必须MES)
|
||||
///66 X Reserved_20 76 Reserved_20 备用
|
||||
///67 INT ProcessCode 77 ProcessCode 手动拧紧工位:由MES通知PLC拧紧序号
|
||||
///68 B OnLineState 79 OnLineState 通过线体工位PC实现下达工位工作状态:工位有三种状态:在线、离线、屏蔽。在线:0正常状态,实现正常功能。1离线:设备脱离MES工作,进入不交互模式。
|
||||
///69 INT PartPalletCode 80 托盘号(MES) 托盘编号(B5A)
|
||||
///70 INT BoltCode 88 BoltCode 手动拧紧工位:指导PLC所用套筒
|
||||
///71 INT RepairStatus 93 RepairStatus "0正常件,1返修件。对于上线工位MES给出是正常上线还是返修上线,返修路径"
|
||||
///72 DInt Reserved_15 110 Reserved_15 备用
|
||||
///73 DInt Reserved_16 111 Reserved_16 备用
|
||||
///74 B Reserved_17 112 Reserved_17 备用
|
||||
///75 INT SPareint1 113 SPareint1 备用int1
|
||||
///76 INT SPareint2 114 SPareint2 备用int2
|
||||
///77 INT SPareint3 115 SPareint3 备用int3
|
||||
///78 STRING Sparestring1 116 Sparestring1 备用字符串1
|
||||
///79 STRING Sparestring2 117 Sparestring2 备用字符串2
|
||||
///80 X MachineStatusPutOn 1000 机床上电(PLC) 机床上电(必须PLC)
|
||||
///81 X MachineStatusWorkOn 1001 循环开始(PLC) 循环开始(必须PLC)
|
||||
///82 X MachineStatusAlarm 1002 设备报警(PLC) 机床故障(必须PLC)
|
||||
///83 X MachineStatusNoPart 1003 MachineStatusNoPart 上料无件(必须PLC)
|
||||
///84 X MachineStatusBlock 1004 MachineStatusBlock 下料堵塞(必须PLC)
|
||||
|
||||
|
||||
namespace MesWork
|
||||
{
|
||||
/// <summary>
|
||||
/// 这是变量类型代码的配置,几乎是不变的
|
||||
/// 请不要随意修改,为了保证变量版本同一,并且方便维护,请联系发行人修改!
|
||||
/// 请注意,此修改为全局修改!
|
||||
/// </summary>
|
||||
public enum EnumTagTypeCodeID
|
||||
{
|
||||
/// <summary>
|
||||
/// 工件到位(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// 解释:托盘到达工位,并且托盘上有工件。
|
||||
/// </summary>
|
||||
WorkStart = 2,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
RepairPartStatusPLC = 3,
|
||||
/// <summary>
|
||||
/// 工位返修字符串
|
||||
/// 变量类型:String
|
||||
/// 解释:工位返修字符串
|
||||
/// </summary>
|
||||
RepairPathString = 4,
|
||||
/// <summary>
|
||||
/// 传递机型(MES)
|
||||
/// 变量类型:Bool
|
||||
/// 解释:MES传递总成信息给PLC(上线工位)
|
||||
/// </summary>
|
||||
EngineTypeGetOverMES = 5,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PartPalletGoOver = 6,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
MaterialVerifyOver = 7,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
FalseGo = 8,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
EngineTypeID = 9,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
EngineID = 10,
|
||||
/// <summary>
|
||||
/// 机型(MES)
|
||||
/// 变量类型:String
|
||||
/// </summary>
|
||||
EngineType = 11,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PartPalletStatus = 13,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
HeartBeatPLC = 14,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
HeartBeatMIS = 15,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
TargetTimeRead = 16,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
MachineTargetTime = 17,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
MachineActualTime = 18,
|
||||
/// <summary>
|
||||
/// 允许保存(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
MesRead = 19,
|
||||
/// <summary>
|
||||
/// 保存完成(MES)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
MesReadOver = 20,
|
||||
/// <summary>
|
||||
/// 合格标志(PLC)
|
||||
/// 变量类型:Int
|
||||
/// </summary>
|
||||
QualityMask = 21,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PalletInfo = 22,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
RepairStatusPLC = 23,
|
||||
/// <summary>
|
||||
/// 订单号(MES)
|
||||
/// 变量类型:Int
|
||||
/// </summary>
|
||||
OrderNo = 24,
|
||||
/// <summary>
|
||||
/// 库位号(MES)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
StorageNo = 25,
|
||||
/// <summary>
|
||||
/// 允许放行(MES)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
AllowPass = 26,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PartLoadFinish = 27,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_7 = 28,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_8 = 29,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_9 = 30,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_10 = 31,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_11 = 32,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_12 = 33,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_13 = 34,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_14 = 35,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PLCSPareint1 = 36,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PLCSPareint2 = 37,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PLCSPareint3 = 38,
|
||||
/// <summary>
|
||||
/// 订单号(PLC)
|
||||
/// </summary>
|
||||
OrderFormPLC = 39,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PLCSarestring2 = 40,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
MarkID = 42,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PartLoad = 43,
|
||||
/// <summary>
|
||||
/// 传递机型(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
EngineTypeGetOverPLC = 44,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PartLoadOK = 48,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_18 = 49,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
PalletDown = 50,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
ConfirmOkGo = 51,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
ResetDevice = 52,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
UnloadCompleted = 53,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
MachineTime_ReadOver = 54,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_19 = 58,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
FixOK = 59,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_21 = 61,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_22 = 62,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_23 = 63,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_24 = 64,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_25 = 65,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
FixAllow = 66,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
FixOver = 67,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
MatchingCompleted = 68,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Match = 69,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_2 = 70,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
IsAutoGetEngineID = 71,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
RepairUplineMES = 72,
|
||||
/// <summary>
|
||||
/// 机型代码(MES)
|
||||
/// 变量类型:Int
|
||||
/// </summary>
|
||||
EngineTypeID_MES = 73,
|
||||
/// <summary>
|
||||
/// 工件编号(MES)
|
||||
/// 变量类型:String
|
||||
/// </summary>
|
||||
EngineID_MES = 74,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
EngineType_MES = 75,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_20 = 76,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
ProcessCode = 77,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
OnLineState = 79,
|
||||
/// <summary>
|
||||
/// 托盘号(MES)
|
||||
/// 变量类型:Int
|
||||
/// </summary>
|
||||
PartPalletCode = 80,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
BoltCode = 88,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
RepairStatus = 93,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_15 = 110,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_16 = 111,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Reserved_17 = 112,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
SPareint1 = 113,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
SPareint2 = 114,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
SPareint3 = 115,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Sparestring1 = 116,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Sparestring2 = 117,
|
||||
/// <summary>
|
||||
/// 机床上电(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
MachineStatusPutOn = 1000,
|
||||
/// <summary>
|
||||
/// 循环开始(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
MachineStatusWorkOn = 1001,
|
||||
/// <summary>
|
||||
/// 设备报警(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
MachineStatusAlarm = 1002,
|
||||
/// <summary>
|
||||
/// 上料无件(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
MachineStatusNoPart = 1003,
|
||||
/// <summary>
|
||||
/// 下料堵塞(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
MachineStatusBlock = 1004,
|
||||
/// <summary>
|
||||
/// 下料堵塞(PLC)
|
||||
/// 变量类型:Bool
|
||||
/// </summary>
|
||||
havePart70 = 10003,
|
||||
}
|
||||
}
|
||||
170
SCADA/Core/Tools.cs
Normal file
170
SCADA/Core/Tools.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
using MesWork;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace ConverterBytesAndStruct
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据解析、数据转换
|
||||
/// </summary>
|
||||
public class Tools
|
||||
{
|
||||
#region 内部转换
|
||||
/// <summary>
|
||||
/// 从源数据提取字符数组
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="num"></param>
|
||||
/// <returns></returns>
|
||||
public static char[] convertNumber(byte[] bytes, int start, int num)
|
||||
{
|
||||
// TODO 长度判断
|
||||
char[] res = new char[num];
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
res[i] = (char)bytes[start + i];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从源数据提取字节数组
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="num"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] slice(byte[] bytes, int start, int num)
|
||||
{
|
||||
// TODO 长度判断
|
||||
byte[] res = new byte[num];
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
res[i] = bytes[start + i];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从源数据提取结构体
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <returns></returns>
|
||||
public static TS convetTS(byte[] bytes, int start)
|
||||
{
|
||||
// TODO 长度判断
|
||||
TS ts = null;
|
||||
|
||||
ts = new TS();
|
||||
ts.Max_Len = bytes[start + 0];
|
||||
ts.Act_Len = bytes[start + 1];
|
||||
ts.Month_B1 = (char)bytes[start + 2];
|
||||
ts.Month_B0 = (char)bytes[start + 3];
|
||||
ts.Slash1 = (char)bytes[start + 4];
|
||||
ts.Day_B1 = (char)bytes[start + 5];
|
||||
ts.Day_B0 = (char)bytes[start + 6];
|
||||
ts.Slash2 = (char)bytes[start + 7];
|
||||
ts.Fixed_dgt1 = (char)bytes[start + 8];
|
||||
ts.Fixed_dgt2 = (char)bytes[start + 9];
|
||||
ts.Year_B1 = (char)bytes[start + 10];
|
||||
ts.Year_B0 = (char)bytes[start + 11];
|
||||
ts.Null1 = (char)bytes[start + 12];
|
||||
ts.Hour_B1 = (char)bytes[start + 13];
|
||||
ts.Hour_B0 = (char)bytes[start + 14];
|
||||
ts.Colon1 = (char)bytes[start + 15];
|
||||
ts.Min_B1 = (char)bytes[start + 16];
|
||||
ts.Min_B0 = (char)bytes[start + 17];
|
||||
ts.Colon2 = (char)bytes[start + 18];
|
||||
ts.Sec_B1 = (char)bytes[start + 19];
|
||||
ts.Sec_B0 = (char)bytes[start + 20];
|
||||
ts.Null2 = (char)bytes[start + 21];
|
||||
|
||||
return ts;
|
||||
}
|
||||
/// <summary>
|
||||
/// 结构体转时间
|
||||
/// </summary>
|
||||
/// <param name="ts"></param>
|
||||
/// <returns></returns>
|
||||
public static System.DateTime Convet_ToDateTime(TS ts)
|
||||
{
|
||||
System.DateTime dt = System.DateTime.Parse($"1970-01-01 01:01:01.001");
|
||||
try
|
||||
{
|
||||
var yyyy = $"20{ts.Year_B1}{ts.Year_B0}";
|
||||
var MM = $"{ts.Month_B1}{ts.Month_B0}";
|
||||
var dd = $"{ts.Day_B1}{ts.Day_B0}";
|
||||
|
||||
var HH = $"{ts.Hour_B1}{ts.Hour_B0}";
|
||||
var mm = $"{ts.Min_B1}{ts.Min_B0}";
|
||||
var ss = $"{ts.Sec_B1}{ts.Sec_B0}";
|
||||
|
||||
var dtStr = $"{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}.000";
|
||||
dt = System.DateTime.Parse(dtStr);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
|
||||
return dt;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从源数据提取质量数据
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <returns></returns>
|
||||
public static QC_DATA convertQcdata(byte[] bytes, int start)
|
||||
{
|
||||
QC_DATA data = null;
|
||||
data = new QC_DATA();
|
||||
data.Work_Type = S7.Net.Types.Int.FromByteArray(new byte[] { bytes[start + 0], bytes[start + 1] });
|
||||
data.Progarm_Code = S7.Net.Types.Int.FromByteArray(new byte[] { bytes[start + 2], bytes[start + 3] });
|
||||
data.Counter_Number = S7.Net.Types.Int.FromByteArray(new byte[] { bytes[start + 4], bytes[start + 5] });
|
||||
|
||||
var byte1 = bytes[start + 6];
|
||||
data.Bypass = S7.Net.Types.Bit.FromByte(byte1, 0);
|
||||
data.No_op = S7.Net.Types.Bit.FromByte(byte1, 1);
|
||||
data.Accept = S7.Net.Types.Bit.FromByte(byte1, 2);
|
||||
data.Reject = S7.Net.Types.Bit.FromByte(byte1, 3);
|
||||
//data.Spare14 = S7.Net.Types.Bit.FromByte(byte1, 4);
|
||||
//data.Spare15 = S7.Net.Types.Bit.FromByte(byte1, 5);
|
||||
//data.Repair_Off = S7.Net.Types.Bit.FromByte(byte1, 6);
|
||||
//data.Repair_On = S7.Net.Types.Bit.FromByte(byte1, 7);
|
||||
|
||||
data.SPARE1 = S7.Net.Types.Byte.FromByteArray(new byte[] { bytes[start + 7] });
|
||||
data.SPARE2 = S7.Net.Types.Int.FromByteArray(new byte[] { bytes[start + 8], bytes[start + 9] });
|
||||
|
||||
data.QC_DATA1 = S7.Net.Types.Real.FromByteArray(slice(bytes, start + 10, 4));
|
||||
data.QC_DATA2 = S7.Net.Types.Real.FromByteArray(slice(bytes, start + 14, 4));
|
||||
data.QC_DATA3 = S7.Net.Types.Real.FromByteArray(slice(bytes, start + 18, 4));
|
||||
data.QC_DATA4 = S7.Net.Types.Real.FromByteArray(slice(bytes, start + 22, 4));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝 bytes1 内容 到 bytes 从start开始,长度由 bytes1决定
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="bytes1"></param>
|
||||
/// <param name="start"></param>
|
||||
public static byte[] copy(byte[] bytes, int start, byte[] bytes1)
|
||||
{
|
||||
for (int i = 0; i < bytes1.Length; i++)
|
||||
{
|
||||
bytes[start + i] = bytes1[i];
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user