2025-09-17 20:04:00 +08:00
|
|
|
using JinYuan.CommunicationLib;
|
|
|
|
|
using JinYuan.CommunicationLib.Base;
|
|
|
|
|
using JinYuan.CommunicationLib.Enum;
|
|
|
|
|
using JinYuan.DAL;
|
|
|
|
|
using JinYuan.Helper;
|
|
|
|
|
using JinYuan.MES;
|
|
|
|
|
using JinYuan.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace JinYuan.VirtualDataLibrary
|
|
|
|
|
{
|
|
|
|
|
public class CommonMethods
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 本地数据库
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static ISugarHepler db = new SQLSugarService();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 远程服务段数据库
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static ISugarHepler dbServer = new SQLSugarService();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MES接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IMes hbgMes = new MesDataProcess();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static ProductModelParam parRange = new ProductModelParam();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 全局钩子
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static ScanerHook listener = new ScanerHook();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建个全局焊接功率队列数据存储
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<Queue<double>> QWeldingPowerData = new List<Queue<double>>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建个全局入壳推力队列数据存储
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<Queue<double>> QPlanenessData = new List<Queue<double>>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建全局的登录对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static SysAdmin currentAdmin = null;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 登录是否成功
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsLoginOk = false;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建一个设备对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Device plcDevice;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ModbusTCP通信对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
//public static OmronFinsTCP plc = new OmronFinsTCP();
|
|
|
|
|
|
|
|
|
|
//创建一个全局的配置对象
|
|
|
|
|
public static SysConfig sysConfig = new SysConfig();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建全局的登录对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<NgCodeEntity> listNgCodeEntity = new List<NgCodeEntity>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int InvadTime;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 智能电表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<ElectricEnergy> listElectricEnergy = new List<ElectricEnergy>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///是否开启刷新
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool isRefreshTimerWeeding = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// SQL语句
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static DBSQL dBSQL { get; } = new DBSQL();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MES配置文件类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static MesConfig mesConfig = new MesConfig();
|
2025-09-18 11:11:38 +08:00
|
|
|
public static short[] MESGradingSet = new short[] { 0,0,0,0,0,0};
|
2025-09-17 20:04:00 +08:00
|
|
|
|
|
|
|
|
///创建一个全局的连接状态
|
|
|
|
|
public static bool connectState = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 滴答次数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int tickCount = 0;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// QIEHUAN
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int tickHomeCount = 0;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 报警信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string SlideAlarmText = "当前无报警";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 退出
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsExit = false;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否登出账户
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool LoginOut = false;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否上传MES
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsUpMes { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否运行
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsRun { get; set; } = false;
|
|
|
|
|
/// <summary>
|
|
|
|
|
///第一次读取
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsFirst = false;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 焊接功率波形图显示条数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int ChatLineCount = 3;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 员工号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string strWorker { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否开启智能电表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsStartZNDB { get; set; } = false;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 白夜班
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string strClass { get; set; } = "白班";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 时间变更
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string ChangeClassTime { get; set; } = "20:30:00";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设备状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<bool> Statues { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务器链接状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool EMCStatues { get; set; }
|
|
|
|
|
|
|
|
|
|
#region 小时产能
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上个时间点的总数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int LastTotalNum { get; set; } = 0;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上个时间点良品数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int LastOkNum { get; set; } = 0;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上一次重置计数的时间
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string LastResetTime { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上一次的小时
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int LastHour { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<Group> ListOmronGroups { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 12小时产能
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<Chart12HourData> Lst_Prod12HourData = new List<Chart12HourData>();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不良选项(检测项不良)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<ChartDataType> Lst_DefectTypeQty = new List<ChartDataType>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC报警前10项
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<ChartDataType> Lst_AlarmTop10_Qty = new List<ChartDataType>();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 参数项设置
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<ParamList> paramlists { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 线程控制
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static ManualResetEvent ResetEventRecv = new ManualResetEvent(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 计数项
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产总数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int TotalQty = 0;
|
|
|
|
|
|
|
|
|
|
public static int ProOKQty = 0;
|
|
|
|
|
|
|
|
|
|
public static int Ppm = 0;
|
|
|
|
|
|
|
|
|
|
public static double JiaDL = 0.0;
|
|
|
|
|
|
|
|
|
|
public static List<float> AntiDustAirSpeed = new List<float>();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC开机/运行时间
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<int> PlcOpenAndRunTime = new List<int>();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC开机/运行时间地址
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<string> PlcOpenAndRunTimeAdress = new List<string> { "D50", "D52", "D54", "D56", "D58", "D60" };
|
|
|
|
|
public static int ProdDRFIDNgQty = 0;//低托杯
|
|
|
|
|
public static int ProdDXNgQty = 0;//卷心码
|
|
|
|
|
public static int ProdGRFIDNgQty = 0;//高托杯
|
|
|
|
|
public static int ProdYLZNgQty = 0;//压力
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private static PlcReadWriteBase _PlcLink;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC客户端
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static PlcReadWriteBase PlcLink
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_PlcLink == null)
|
|
|
|
|
{
|
|
|
|
|
_PlcLink = PlcNewClass.GetPLC(CommonMethods.plcDevice.IPAddress, CommonMethods.plcDevice.Port, (PLCType)Enum.Parse(typeof(PLCType), (string)CommonMethods.plcDevice.PLCType, false));
|
|
|
|
|
}
|
|
|
|
|
return _PlcLink;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 首次连接PLC
|
|
|
|
|
public static bool ConnectPLC()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.plcDevice != null)
|
|
|
|
|
{
|
|
|
|
|
//判断是否为第一次连接
|
|
|
|
|
if (!CommonMethods.plcDevice.IsFirstConnect)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(CommonMethods.plcDevice.ReConnectTime);
|
|
|
|
|
CommonMethods.PlcLink.Disconnect();
|
|
|
|
|
}
|
|
|
|
|
string msg = "";
|
|
|
|
|
var result = CommonMethods.PlcLink.Connect(ref msg);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
CommonMethods.plcDevice.IsConnected = true;
|
|
|
|
|
CommonMethods.AddLog(false, CommonMethods.plcDevice.IsFirstConnect ? $"PLC初次连接成功:{msg}" : $"PLC重新连接成功:{msg}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CommonMethods.plcDevice.IsConnected = false;
|
|
|
|
|
CommonMethods.AddLog(true, CommonMethods.plcDevice.IsFirstConnect ? "PLC初次连接失败" : "PLC重新连接失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果是第一次连接,将标志位复位
|
|
|
|
|
if (CommonMethods.plcDevice.IsFirstConnect)
|
|
|
|
|
{
|
|
|
|
|
CommonMethods.plcDevice.IsFirstConnect = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
new MsgshowTip("与PLC链接断开,请检查通讯线路!").ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-18 11:11:38 +08:00
|
|
|
#endregion
|
|
|
|
|
#region 写入分档
|
|
|
|
|
public static bool WriteGrading()
|
|
|
|
|
{
|
|
|
|
|
var res = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (plcDevice != null && plcDevice.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
DateTime Date = DateTime.Now;
|
|
|
|
|
#region 档位写入
|
|
|
|
|
// short[] MESGradingSet = new short[] { 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
//1
|
|
|
|
|
MESGradingSet[0] = (short)21; // 21 22 23 24 25 26
|
|
|
|
|
//2
|
|
|
|
|
if (mesConfig.Grading2.Trim().Equals(mesConfig.Grading1.Trim()))
|
|
|
|
|
MESGradingSet[1] = MESGradingSet[0];
|
|
|
|
|
else
|
|
|
|
|
MESGradingSet[1] = (short)(MESGradingSet[0] + 1);
|
|
|
|
|
//3
|
|
|
|
|
if (mesConfig.Grading3.Trim().Equals(CommonMethods.mesConfig.Grading1.Trim()))
|
|
|
|
|
MESGradingSet[2] = MESGradingSet[0];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading3.Trim().Equals(CommonMethods.mesConfig.Grading2.Trim()))
|
|
|
|
|
MESGradingSet[2] = MESGradingSet[1];
|
|
|
|
|
else
|
|
|
|
|
MESGradingSet[2] = (short)(MESGradingSet[1] + 1);
|
|
|
|
|
}
|
|
|
|
|
//4
|
|
|
|
|
if (CommonMethods.mesConfig.Grading4.Trim().Equals(CommonMethods.mesConfig.Grading1.Trim()))
|
|
|
|
|
MESGradingSet[3] = MESGradingSet[0];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading4.Trim().Equals(CommonMethods.mesConfig.Grading2.Trim()))
|
|
|
|
|
MESGradingSet[3] = MESGradingSet[1];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading4.Trim().Equals(CommonMethods.mesConfig.Grading3.Trim()))
|
|
|
|
|
MESGradingSet[3] = MESGradingSet[2];
|
|
|
|
|
else
|
|
|
|
|
MESGradingSet[3] = (short)(MESGradingSet[2] + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//5
|
|
|
|
|
if (CommonMethods.mesConfig.Grading5.Trim().Equals(CommonMethods.mesConfig.Grading1.Trim()))
|
|
|
|
|
MESGradingSet[4] = MESGradingSet[0];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading5.Trim().Equals(CommonMethods.mesConfig.Grading2.Trim()))
|
|
|
|
|
MESGradingSet[4] = MESGradingSet[1];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading5.Trim().Equals(CommonMethods.mesConfig.Grading3.Trim()))
|
|
|
|
|
MESGradingSet[4] = MESGradingSet[2];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading5.Trim().Equals(CommonMethods.mesConfig.Grading4.Trim()))
|
|
|
|
|
MESGradingSet[4] = MESGradingSet[3];
|
|
|
|
|
else
|
|
|
|
|
MESGradingSet[4] = (short)(MESGradingSet[3] + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//6
|
|
|
|
|
if (CommonMethods.mesConfig.Grading6.Trim().Equals(CommonMethods.mesConfig.Grading1.Trim()))
|
|
|
|
|
MESGradingSet[5] = MESGradingSet[0];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading6.Trim().Equals(CommonMethods.mesConfig.Grading2.Trim()))
|
|
|
|
|
MESGradingSet[5] = MESGradingSet[1];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading6.Trim().Equals(CommonMethods.mesConfig.Grading3.Trim()))
|
|
|
|
|
MESGradingSet[5] = MESGradingSet[2];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading6.Trim().Equals(CommonMethods.mesConfig.Grading4.Trim()))
|
|
|
|
|
MESGradingSet[5] = MESGradingSet[3];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CommonMethods.mesConfig.Grading6.Trim().Equals(CommonMethods.mesConfig.Grading5.Trim()))
|
|
|
|
|
MESGradingSet[5] = MESGradingSet[4];
|
|
|
|
|
else
|
|
|
|
|
MESGradingSet[5] = (short)(MESGradingSet[4] + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
var isWrite1 = PlcLink.WriteValue("D2600", MESGradingSet[0], Data_Type.Short);
|
|
|
|
|
var isWrite2 = PlcLink.WriteValue("D2601", MESGradingSet[1], Data_Type.Short);
|
|
|
|
|
var isWrite3 = PlcLink.WriteValue("D2602", MESGradingSet[2], Data_Type.Short);
|
|
|
|
|
var isWrite4 = PlcLink.WriteValue("D2603", MESGradingSet[3], Data_Type.Short);
|
|
|
|
|
var isWrite5 = PlcLink.WriteValue("D2604", MESGradingSet[4], Data_Type.Short);
|
|
|
|
|
var isWrite6 = PlcLink.WriteValue("D2605", MESGradingSet[5], Data_Type.Short);
|
|
|
|
|
if (isWrite1.IsSuccess && isWrite2.IsSuccess && isWrite3.IsSuccess && isWrite4.IsSuccess && isWrite5.IsSuccess && isWrite6.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
AddDataMonitorLog(0, $"OK分档档位写入PLC成功![2600~2605]{string.Join(",", MESGradingSet)}");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
AddLog(true, ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-17 20:04:00 +08:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 写入PLC信息
|
|
|
|
|
//public static OperateResult CommonWrite(string varName, string varValue)
|
|
|
|
|
//{
|
|
|
|
|
// //先通过变量名称找到对象
|
|
|
|
|
// var variable = plcDevice.VarList.Find(c => c.VarName == varName);
|
|
|
|
|
|
|
|
|
|
// if (variable != null)
|
|
|
|
|
// {
|
|
|
|
|
// DataConvertLib.DataType dataType = (DataConvertLib.DataType)Enum.Parse(typeof(DataConvertLib.DataType), variable.DataType, true);
|
|
|
|
|
|
|
|
|
|
// var result = MigrationLib.SetMigrationValue(varValue, dataType, variable.Scale.ToString(), variable.Offset.ToString());
|
|
|
|
|
|
|
|
|
|
// if (result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// switch (dataType)
|
|
|
|
|
// {
|
|
|
|
|
// case DataConvertLib.DataType.Bool:
|
|
|
|
|
// return plc.WriteBool(variable.VarAddress, result.Content == "1" || result.Content.ToUpper() == "TRUE");
|
|
|
|
|
// case DataConvertLib.DataType.Byte:
|
|
|
|
|
// return plc.WriteByte(variable.VarAddress, Convert.ToByte(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.Short:
|
|
|
|
|
// return plc.WriteShort(variable.VarAddress, Convert.ToInt16(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.UShort:
|
|
|
|
|
// return plc.WriteUShort(variable.VarAddress, Convert.ToUInt16(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.Int:
|
|
|
|
|
// return plc.WriteInt(variable.VarAddress, Convert.ToInt32(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.UInt:
|
|
|
|
|
// return plc.WriteUInt(variable.VarAddress, Convert.ToUInt32(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.Float:
|
|
|
|
|
// return plc.WriteFloat(variable.VarAddress, Convert.ToSingle(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.Double:
|
|
|
|
|
// return plc.WriteDouble(variable.VarAddress, Convert.ToDouble(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.Long:
|
|
|
|
|
// return plc.WriteLong(variable.VarAddress, Convert.ToInt64(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.ULong:
|
|
|
|
|
// return plc.WriteULong(variable.VarAddress, Convert.ToUInt64(result.Content));
|
|
|
|
|
// case DataConvertLib.DataType.String:
|
|
|
|
|
// return plc.WriteByteArray(variable.VarAddress, ByteArrayLib.GetByteArrayFromString(result.Content, Encoding.ASCII));
|
|
|
|
|
// default:
|
|
|
|
|
// return OperateResult.CreateFailResult("暂不支持此数据类型");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// return OperateResult.CreateFailResult("数据转换出错:" + ex.Message);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// return OperateResult.CreateFailResult(result.Message);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// return OperateResult.CreateFailResult("请检查变量名称是否存在");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 配置信息
|
|
|
|
|
public static string devPath = Application.StartupPath + "\\Config\\Device.ini";
|
|
|
|
|
public static string groupPath = Application.StartupPath + "\\Config\\Group.xlsx";
|
|
|
|
|
public static string variablePath = Application.StartupPath + "\\Config\\Variable.xlsx";
|
|
|
|
|
public static string settingPath = Application.StartupPath + "\\Config\\settings.json";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 错误日志路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string strErrorLogspath = System.Windows.Forms.Application.StartupPath + "\\Logs\\ErrorLogs";
|
|
|
|
|
|
|
|
|
|
public static string strSystemLogspath = System.Windows.Forms.Application.StartupPath + "\\Logs\\SystemLogs";
|
|
|
|
|
public static string strAlarmLogspath = System.Windows.Forms.Application.StartupPath + "\\Logs\\AlarmLogs";
|
|
|
|
|
|
|
|
|
|
public static string strsqlLogspath = "";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string strDeletepath = "";
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 能耗保存路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string strWattrMeterpath = System.Windows.Forms.Application.StartupPath + "\\智能电表数据";
|
|
|
|
|
|
|
|
|
|
/// 风速仪保存路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
///
|
|
|
|
|
public static string strAnemographpath = System.Windows.Forms.Application.StartupPath + "\\风速仪数据";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MES路径日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string strMesLogspath = System.Windows.Forms.Application.StartupPath + "\\Logs\\MesLogs";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC读取寄存器配置文件路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string ConfigPath = Path.Combine(System.Windows.Forms.Application.StartupPath, "ini\\PlcConfig.ini");
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 系统程序配置文件路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string iniFilePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "ini\\Configure.ini");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 读取配置文件
|
|
|
|
|
/// <summary>
|
|
|
|
|
///读取配置文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void GetSysConfig()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sysConfig.AutoStart = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "开机自动启动", "false"));
|
|
|
|
|
sysConfig.AutoLogin = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "启动自动登录", "false"));
|
|
|
|
|
sysConfig.AutoLock = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "无操作自动锁屏", "false"));
|
|
|
|
|
sysConfig.LockPeriod = Convert.ToInt32(IniConfigHelper.ReadIniData("配置信息", "锁屏间隔时间", "false"));
|
|
|
|
|
|
|
|
|
|
sysConfig.AutoQieHuanM = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "无操作自动切换监控界面", "false"));
|
|
|
|
|
sysConfig.QieHuanMPeriod = Convert.ToInt32(IniConfigHelper.ReadIniData("配置信息", "切换监控界面间隔时间", "false"));
|
|
|
|
|
|
|
|
|
|
sysConfig.ShowSeriesCount = Convert.ToInt32(IniConfigHelper.ReadIniData("配置信息", "曲线显示数量", "false"));
|
|
|
|
|
sysConfig.SwipeCardMode = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "开启刷卡模式", "false"));
|
|
|
|
|
sysConfig.MesModeSwitching = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "MES/非MES模式切换", "false"));
|
|
|
|
|
sysConfig.GetMesParam = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "获取MES参数", "false"));
|
|
|
|
|
sysConfig.OKSwitching = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "强制OK/正常NG模式切换", "false"));
|
|
|
|
|
sysConfig.SaveThreadTime = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "线程耗时日志保存", "false"));
|
2025-09-18 11:11:38 +08:00
|
|
|
sysConfig.SaveThreadTime = Convert.ToBoolean(IniConfigHelper.ReadIniData("配置信息", "线程耗时日志保存", "false"));
|
|
|
|
|
mesConfig.Grading1 = IniConfigHelper.ReadIniData("MES配置", "Grading1", "false");
|
|
|
|
|
mesConfig.Grading2 = IniConfigHelper.ReadIniData("MES配置", "Grading2", "false");
|
|
|
|
|
mesConfig.Grading3 = IniConfigHelper.ReadIniData("MES配置", "Grading3", "false");
|
|
|
|
|
mesConfig.Grading4 = IniConfigHelper.ReadIniData("MES配置", "Grading4", "false");
|
|
|
|
|
mesConfig.Grading5 = IniConfigHelper.ReadIniData("MES配置", "Grading5", "false");
|
|
|
|
|
mesConfig.Grading6 = IniConfigHelper.ReadIniData("MES配置", "Grading6", "false");
|
2025-09-17 20:04:00 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
sysConfig = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 保存配置文件
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存启动自动登录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveAutoStart(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "开机自动启动", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存开机自动启动
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveAutoLogin(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "启动自动登录", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存无操作自动锁屏
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveAutoLock(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "无操作自动锁屏", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存锁屏间隔时间
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveLockPeriod(int value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "锁屏间隔时间", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存无操作自动切换监控界面
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveAutoQieHuanM(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "无操作自动切换监控界面", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存切换监控界面间隔时间
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveQieHuanMPeriod(int value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "切换监控界面间隔时间", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存曲线显示数量
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveShowSeriesCount(int value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "曲线显示数量", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开启刷卡模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveSwipeCardMode(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "开启刷卡模式", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MES/非MES模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveOpenMesModel(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "MES/非MES模式切换", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 强制OK/正常NG模式切换
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveOpenOKModel(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "强制OK/正常NG模式切换", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取MES参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveGetMesParam(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "获取MES参数", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存线程耗时操作
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveSaveThreadTime(bool value)
|
|
|
|
|
{
|
|
|
|
|
return IniConfigHelper.WriteIniData("配置信息", "线程耗时日志保存", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 委托信息
|
|
|
|
|
//创建委托
|
|
|
|
|
// 数据监视委托
|
|
|
|
|
public static Action<int, string> AddDataMonitorDelegate;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 系统日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Action<bool, string> AddLogDelegate;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Action<bool, string> AddOPLogDelegate;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 报警日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Action<SysLog> AddAlarmDelegate;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示报警信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Action<string> ShowAlarmDelegate;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 参数更新
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Action ChangeParamDelegate;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示上料信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Action<List<AGearEntity>> ShowFeedingDelegate;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示下料数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Action<List<BGearEntity>> ShowBlankingDelegate;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数据监视委托
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
public static void AddDataMonitorLog(int type, string info)
|
|
|
|
|
{
|
|
|
|
|
//调用委托
|
|
|
|
|
if (AddDataMonitorDelegate != null)
|
|
|
|
|
{
|
|
|
|
|
AddDataMonitorDelegate(type, info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入系统日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isError">是否为错误信息</param>
|
|
|
|
|
/// <param name="info">日志信息</param>
|
|
|
|
|
public static void AddLog(bool isError, string info)
|
|
|
|
|
{
|
|
|
|
|
//调用委托
|
|
|
|
|
if (AddLogDelegate != null)
|
|
|
|
|
{
|
|
|
|
|
AddLogDelegate(isError, info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入操作日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isError"></param>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
public static void AddOPLog(bool isError, string info)
|
|
|
|
|
{
|
|
|
|
|
//调用委托
|
|
|
|
|
if (AddLogDelegate != null)
|
|
|
|
|
{
|
|
|
|
|
AddOPLogDelegate(isError, info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddAlarmLog(SysLog sysLog)
|
|
|
|
|
{
|
|
|
|
|
//调用委托
|
|
|
|
|
if (AddAlarmDelegate != null)
|
|
|
|
|
{
|
|
|
|
|
AddAlarmDelegate(sysLog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示报警日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
public static void ShowAlarmLog(string info)
|
|
|
|
|
{
|
|
|
|
|
//调用委托
|
|
|
|
|
if (ShowAlarmDelegate != null)
|
|
|
|
|
{
|
|
|
|
|
ShowAlarmDelegate(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ChangeParamData()
|
|
|
|
|
{
|
|
|
|
|
//调用委托
|
|
|
|
|
if (ChangeParamDelegate != null)
|
|
|
|
|
{
|
|
|
|
|
ChangeParamDelegate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|