添加新控制点

This commit is contained in:
gongxh
2022-05-13 09:08:42 +08:00
parent 08c7d6baef
commit f3652923f4
5 changed files with 701 additions and 108 deletions

Binary file not shown.

View File

@@ -0,0 +1,536 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CleanMachineHMI.Utils
{
public class ByteTransformBase
{
public DataFormat DataFormat
{
get;
set;
}
public bool IsStringReverseByteWord
{
get;
set;
}
//
// 摘要:
// 实例化一个默认的对象
// Instantiate a default object
public ByteTransformBase()
{
DataFormat = DataFormat.DCBA;
}
//
// 摘要:
// 使用指定的数据解析来实例化对象
// Instantiate the object using the specified data parsing
//
// 参数:
// dataFormat:
// 数据规则
public ByteTransformBase(DataFormat dataFormat)
{
DataFormat = dataFormat;
}
public virtual bool TransBool(byte[] buffer, int index)
{
return (buffer[index] & 1) == 1;
}
public virtual byte TransByte(byte[] buffer, int index)
{
return buffer[index];
}
public virtual byte[] TransByte(byte[] buffer, int index, int length)
{
byte[] array = new byte[length];
Array.Copy(buffer, index, array, 0, length);
return array;
}
public virtual short TransInt16(byte[] buffer, int index)
{
return BitConverter.ToInt16(buffer, index);
}
public virtual short[] TransInt16(byte[] buffer, int index, int length)
{
short[] array = new short[length];
for (int i = 0; i < length; i++)
{
array[i] = TransInt16(buffer, index + 2 * i);
}
return array;
}
public virtual ushort TransUInt16(byte[] buffer, int index)
{
return BitConverter.ToUInt16(buffer, index);
}
public virtual ushort[] TransUInt16(byte[] buffer, int index, int length)
{
ushort[] array = new ushort[length];
for (int i = 0; i < length; i++)
{
array[i] = TransUInt16(buffer, index + 2 * i);
}
return array;
}
public virtual int TransInt32(byte[] buffer, int index)
{
return BitConverter.ToInt32(ByteTransDataFormat4(buffer, index), 0);
}
public virtual int[] TransInt32(byte[] buffer, int index, int length)
{
int[] array = new int[length];
for (int i = 0; i < length; i++)
{
array[i] = TransInt32(buffer, index + 4 * i);
}
return array;
}
public virtual uint TransUInt32(byte[] buffer, int index)
{
return BitConverter.ToUInt32(ByteTransDataFormat4(buffer, index), 0);
}
public virtual uint[] TransUInt32(byte[] buffer, int index, int length)
{
uint[] array = new uint[length];
for (int i = 0; i < length; i++)
{
array[i] = TransUInt32(buffer, index + 4 * i);
}
return array;
}
public virtual long TransInt64(byte[] buffer, int index)
{
return BitConverter.ToInt64(ByteTransDataFormat8(buffer, index), 0);
}
public virtual long[] TransInt64(byte[] buffer, int index, int length)
{
long[] array = new long[length];
for (int i = 0; i < length; i++)
{
array[i] = TransInt64(buffer, index + 8 * i);
}
return array;
}
public virtual ulong TransUInt64(byte[] buffer, int index)
{
return BitConverter.ToUInt64(ByteTransDataFormat8(buffer, index), 0);
}
public virtual ulong[] TransUInt64(byte[] buffer, int index, int length)
{
ulong[] array = new ulong[length];
for (int i = 0; i < length; i++)
{
array[i] = TransUInt64(buffer, index + 8 * i);
}
return array;
}
public virtual float TransSingle(byte[] buffer, int index)
{
return BitConverter.ToSingle(ByteTransDataFormat4(buffer, index), 0);
}
public virtual float[] TransSingle(byte[] buffer, int index, int length)
{
float[] array = new float[length];
for (int i = 0; i < length; i++)
{
array[i] = TransSingle(buffer, index + 4 * i);
}
return array;
}
public virtual double TransDouble(byte[] buffer, int index)
{
return BitConverter.ToDouble(ByteTransDataFormat8(buffer, index), 0);
}
public virtual double[] TransDouble(byte[] buffer, int index, int length)
{
double[] array = new double[length];
for (int i = 0; i < length; i++)
{
array[i] = TransDouble(buffer, index + 8 * i);
}
return array;
}
public virtual string TransString(byte[] buffer, Encoding encoding)
{
return encoding.GetString(buffer);
}
public virtual byte[] TransByte(byte value)
{
return new byte[1]
{
value
};
}
public virtual byte[] TransByte(short value)
{
return TransByte(new short[1]
{
value
});
}
public virtual byte[] TransByte(short[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 2];
for (int i = 0; i < values.Length; i++)
{
BitConverter.GetBytes(values[i]).CopyTo(array, 2 * i);
}
return array;
}
public virtual byte[] TransByte(ushort value)
{
return TransByte(new ushort[1]
{
value
});
}
public virtual byte[] TransByte(ushort[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 2];
for (int i = 0; i < values.Length; i++)
{
BitConverter.GetBytes(values[i]).CopyTo(array, 2 * i);
}
return array;
}
public virtual byte[] TransByte(int value)
{
return TransByte(new int[1]
{
value
});
}
public virtual byte[] TransByte(int[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 4];
for (int i = 0; i < values.Length; i++)
{
ByteTransDataFormat4(BitConverter.GetBytes(values[i])).CopyTo(array, 4 * i);
}
return array;
}
public virtual byte[] TransByte(uint value)
{
return TransByte(new uint[1]
{
value
});
}
public virtual byte[] TransByte(uint[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 4];
for (int i = 0; i < values.Length; i++)
{
ByteTransDataFormat4(BitConverter.GetBytes(values[i])).CopyTo(array, 4 * i);
}
return array;
}
public virtual byte[] TransByte(long value)
{
return TransByte(new long[1]
{
value
});
}
public virtual byte[] TransByte(long[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 8];
for (int i = 0; i < values.Length; i++)
{
ByteTransDataFormat8(BitConverter.GetBytes(values[i])).CopyTo(array, 8 * i);
}
return array;
}
public virtual byte[] TransByte(ulong value)
{
return TransByte(new ulong[1]
{
value
});
}
public virtual byte[] TransByte(ulong[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 8];
for (int i = 0; i < values.Length; i++)
{
ByteTransDataFormat8(BitConverter.GetBytes(values[i])).CopyTo(array, 8 * i);
}
return array;
}
public virtual byte[] TransByte(float value)
{
return TransByte(new float[1]
{
value
});
}
public virtual byte[] TransByte(float[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 4];
for (int i = 0; i < values.Length; i++)
{
ByteTransDataFormat4(BitConverter.GetBytes(values[i])).CopyTo(array, 4 * i);
}
return array;
}
public virtual byte[] TransByte(double value)
{
return TransByte(new double[1]
{
value
});
}
public virtual byte[] TransByte(double[] values)
{
if (values == null)
{
return null;
}
byte[] array = new byte[values.Length * 8];
for (int i = 0; i < values.Length; i++)
{
ByteTransDataFormat8(BitConverter.GetBytes(values[i])).CopyTo(array, 8 * i);
}
return array;
}
//
// 摘要:
// 反转多字节的数据信息
//
// 参数:
// value:
// 数据字节
//
// index:
// 起始索引,默认值为0
//
// 返回结果:
// 实际字节信息
protected byte[] ByteTransDataFormat4(byte[] value, int index = 0)
{
byte[] array = new byte[4];
switch (DataFormat)
{
case DataFormat.ABCD:
array[0] = value[index + 3];
array[1] = value[index + 2];
array[2] = value[index + 1];
array[3] = value[index];
break;
case DataFormat.BADC:
array[0] = value[index + 2];
array[1] = value[index + 3];
array[2] = value[index];
array[3] = value[index + 1];
break;
case DataFormat.CDAB:
array[0] = value[index + 1];
array[1] = value[index];
array[2] = value[index + 3];
array[3] = value[index + 2];
break;
case DataFormat.DCBA:
array[0] = value[index];
array[1] = value[index + 1];
array[2] = value[index + 2];
array[3] = value[index + 3];
break;
}
return array;
}
//
// 摘要:
// 反转多字节的数据信息
//
// 参数:
// value:
// 数据字节
//
// index:
// 起始索引,默认值为0
//
// 返回结果:
// 实际字节信息
protected byte[] ByteTransDataFormat8(byte[] value, int index = 0)
{
byte[] array = new byte[8];
switch (DataFormat)
{
case DataFormat.ABCD:
array[0] = value[index + 7];
array[1] = value[index + 6];
array[2] = value[index + 5];
array[3] = value[index + 4];
array[4] = value[index + 3];
array[5] = value[index + 2];
array[6] = value[index + 1];
array[7] = value[index];
break;
case DataFormat.BADC:
array[0] = value[index + 6];
array[1] = value[index + 7];
array[2] = value[index + 4];
array[3] = value[index + 5];
array[4] = value[index + 2];
array[5] = value[index + 3];
array[6] = value[index];
array[7] = value[index + 1];
break;
case DataFormat.CDAB:
array[0] = value[index + 1];
array[1] = value[index];
array[2] = value[index + 3];
array[3] = value[index + 2];
array[4] = value[index + 5];
array[5] = value[index + 4];
array[6] = value[index + 7];
array[7] = value[index + 6];
break;
case DataFormat.DCBA:
array[0] = value[index];
array[1] = value[index + 1];
array[2] = value[index + 2];
array[3] = value[index + 3];
array[4] = value[index + 4];
array[5] = value[index + 5];
array[6] = value[index + 6];
array[7] = value[index + 7];
break;
}
return array;
}
public override string ToString()
{
return $"ByteTransformBase[{DataFormat}]";
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CleanMachineHMI.Utils
{
public enum DataFormat
{
//
// 摘要:
// 按照顺序排序
ABCD,
//
// 摘要:
// 按照单字反转
BADC,
//
// 摘要:
// 按照双字反转
CDAB,
//
// 摘要:
// 按照倒序排序
DCBA
}
}

View File

@@ -189,7 +189,7 @@ namespace CleanMachineHMI
// thEvent.Set(); // thEvent.Set();
// ShowWarningMsg(); // ShowWarningMsg();
int sleeptime = 100 - ts.Milliseconds; int sleeptime = 100 - ts.Milliseconds;
if (sleeptime<0) if (sleeptime < 0)
{ {
sleeptime = 0; sleeptime = 0;
} }
@@ -407,9 +407,11 @@ namespace CleanMachineHMI
////高位 short 的字节数组。 ////高位 short 的字节数组。
//byte[] tmpByt_2 = BitConverter.GetBytes(readBytArr_D[plcItemDeviationAddress + 1]); //byte[] tmpByt_2 = BitConverter.GetBytes(readBytArr_D[plcItemDeviationAddress + 1]);
////组合为int32的字节数组。 ////组合为int32的字节数组。
//byte[] tmpByt_3 = new byte[] { tmpByt_1[0], tmpByt_1[1], tmpByt_2[0], tmpByt_2[1] }; // byte[] tmpByt_3 = new byte[] { tmpByt_1[0], tmpByt_1[1], tmpByt_2[0], tmpByt_2[1] };
////readBytArr_D[plcItemDeviationAddress + 1] << 16 + ////readBytArr_D[plcItemDeviationAddress + 1] << 16 +
//item.PlcItemValue = BitConverter.ToUInt32(tmpByt_3, 0).ToString(); //value = BitConverter.ToInt32(tmpByt_3, 0).ToString();
#endregion #endregion
#region 方法二 :Short数组转换为int数据 20201014 孙亚龙 #region 方法二 :Short数组转换为int数据 20201014 孙亚龙
@@ -952,8 +954,17 @@ namespace CleanMachineHMI
} }
else else
{ {
if (item.PlcItemDataLength == 2)
{
return int.Parse(item.PlcItemValue);
}
else
{
return short.Parse(item.PlcItemValue); return short.Parse(item.PlcItemValue);
} }
}
} }
else else
@@ -1009,9 +1020,17 @@ namespace CleanMachineHMI
retObj = 0; retObj = 0;
} }
else else
{
if (item_D.PlcItemDataLength == 2)
{
retObj = int.Parse(item_D.PlcItemValue);
}
else
{ {
retObj = short.Parse(item_D.PlcItemValue); retObj = short.Parse(item_D.PlcItemValue);
} }
}
break; break;
case PlcItemTypeDesc.X: case PlcItemTypeDesc.X:
PlcItem item_X = PlcItemMd_X_List.Find(x => x.PlcItemCode == plcItemCode); PlcItem item_X = PlcItemMd_X_List.Find(x => x.PlcItemCode == plcItemCode);

View File

@@ -569,113 +569,123 @@ namespace CleanMachineHMI
} }
} }
string sqlParam = $@"SELECT * FROM SYS_PARAMETER";
DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0];
if (dtParam != null && dtParam.Rows.Count > 0)
{
int sysRuningTimeLen = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'SysRuningTimeLen'")[0]["PARAMETER_VALUE"]);
int scrapRate = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'ScrapRate'")[0]["PARAMETER_VALUE"]);
int maintainItemTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainItemTime'")[0]["PARAMETER_VALUE"]);
int maintainAlarmTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainAlarmTime'")[0]["PARAMETER_VALUE"]);
int maintainQuitTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainQuitTime'")[0]["PARAMETER_VALUE"]);
int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]);
string maintainRelieveCode = dtParam.Select("PARAMETER_CODE = 'MaintainRelieveCode'")[0]["PARAMETER_VALUE"].ToString();
if (maintainFlag == 0)
{
bool isRun = (bool)PlcOperationHelper.Instance.ReadPlcItem("CleanMacRunStatusNew", PlcItemTypeDesc.M);
if (isRun) int SysRunTime = (int)PlcOperationHelper.Instance.ReadPlcItem("SysRuningTime", PlcItemTypeDesc.D);
int Minutes = SysRunTime / 60;
BeginInvoke(new Action(() =>
{ {
if (timerRunNUm == 60) kryptonLabel1.Text = Minutes + " Minutes";
{ }));
sysRuningTimeLen++;
if (sysRuningTimeLen < maintainItemTime)
{ //string sqlParam = $@"SELECT * FROM SYS_PARAMETER";
//pictureBox1.Visible = false; //DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0];
BeginInvoke(new Action(() => { pictureBox1.Visible = false; })); //if (dtParam != null && dtParam.Rows.Count > 0)
}
else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime)
{
//pictureBox1.Visible = true;
BeginInvoke(new Action(() => { pictureBox1.Visible = true; }));
}
else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime)
{
//BeginInvoke(new Action(() =>
//{ //{
// pictureBox1.Visible = true; // int sysRuningTimeLen = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'SysRuningTimeLen'")[0]["PARAMETER_VALUE"]);
// if (!sysAlarmFrmShowFlag) // int scrapRate = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'ScrapRate'")[0]["PARAMETER_VALUE"]);
// int maintainItemTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainItemTime'")[0]["PARAMETER_VALUE"]);
// int maintainAlarmTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainAlarmTime'")[0]["PARAMETER_VALUE"]);
// int maintainQuitTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainQuitTime'")[0]["PARAMETER_VALUE"]);
// int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]);
// string maintainRelieveCode = dtParam.Select("PARAMETER_CODE = 'MaintainRelieveCode'")[0]["PARAMETER_VALUE"].ToString();
// if (maintainFlag == 0)
// { // {
// sysAlarmFrmShowFlag = true; // bool isRun = (bool)PlcOperationHelper.Instance.ReadPlcItem("CleanMacRunStatusNew", PlcItemTypeDesc.M);
// frmSysExitAlarm frm = new frmSysExitAlarm();
// //frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。"; // if (isRun)
// frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes."; // {
// frm.TopLevel = true;
// frm.ShowDialog(); // if (timerRunNUm == 60)
// {
// sysRuningTimeLen++;
// if (sysRuningTimeLen < maintainItemTime)
// {
// //pictureBox1.Visible = false;
// BeginInvoke(new Action(() => { pictureBox1.Visible = false; }));
// } // }
//})); // else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime)
}
else if (sysRuningTimeLen >= maintainQuitTime)
{
//BeginInvoke(new Action(() =>
//{
// pictureBox1.Visible = true;
// string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
// DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
// if (dt != null && dt.Rows.Count > 0)
// { // {
// if (!sysAlarmFrmShowFlag) // //pictureBox1.Visible = true;
// { // BeginInvoke(new Action(() => { pictureBox1.Visible = true; }));
// sysAlarmFrmShowFlag = true;
// frmSysExitAlarm frm = new frmSysExitAlarm();
// frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!";
// frm.TopLevel = true;
// frm.ShowDialog();
// } // }
// else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime)
// {
// //BeginInvoke(new Action(() =>
// //{
// // pictureBox1.Visible = true;
// // if (!sysAlarmFrmShowFlag)
// // {
// // sysAlarmFrmShowFlag = true;
// // frmSysExitAlarm frm = new frmSysExitAlarm();
// // //frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。";
// // frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes.";
// // frm.TopLevel = true;
// // frm.ShowDialog();
// // }
// //}));
// }
// else if (sysRuningTimeLen >= maintainQuitTime)
// {
// //BeginInvoke(new Action(() =>
// //{
// // pictureBox1.Visible = true;
// // string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
// // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
// // if (dt != null && dt.Rows.Count > 0)
// // {
// // if (!sysAlarmFrmShowFlag)
// // {
// // sysAlarmFrmShowFlag = true;
// // frmSysExitAlarm frm = new frmSysExitAlarm();
// // frm.showMsg = $"The machine maintenance time has exceeded: [{(maintainQuitTime - sysRuningTimeLen)}] minutes, please complete the current operation tray as soon as possible, and carry out equipment maintenance !!!!!!";
// // frm.TopLevel = true;
// // frm.ShowDialog();
// // }
// // }
// // else
// // {
// // string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'";
// // LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam);
// // PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M);
// // PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M);
// // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M);
// // PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M);
// // Environment.Exit(0);
// // }
// //}));
// }
// string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'";
// LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen);
// BeginInvoke(new Action(() =>
// {
// kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
// }));
// timerRunNUm = 1;
// } // }
// else // else
// { // {
// string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'"; // timerRunNUm++;
// LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam); // BeginInvoke(new Action(() =>
// PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M); // {
// PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M); // kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
// PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M); // }));
// PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M); // }
// Environment.Exit(0);
// } // }
//}));
}
string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'";
LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen);
BeginInvoke(new Action(() =>
{
kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
}));
timerRunNUm = 1;
}
else
{
timerRunNUm++;
BeginInvoke(new Action(() =>
{
kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
}));
}
}
} // }
else // else
{ // {
BeginInvoke(new Action(() => // BeginInvoke(new Action(() =>
{ // {
pictureBox1.Visible = true; // pictureBox1.Visible = true;
})); // }));
} // }
} //}
#region 定期清理历史业务数据 -- 数据保存2个月 #region 定期清理历史业务数据 -- 数据保存2个月