添加新控制点
This commit is contained in:
Binary file not shown.
536
CleanMachineHMI/Utils/ByteTransformBase.cs
Normal file
536
CleanMachineHMI/Utils/ByteTransformBase.cs
Normal 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}]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
CleanMachineHMI/Utils/DataFormat.cs
Normal file
28
CleanMachineHMI/Utils/DataFormat.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -175,7 +175,7 @@ namespace CleanMachineHMI
|
|||||||
|
|
||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
|
|
||||||
TimeSpan ts = stopWatch.Elapsed;
|
TimeSpan ts = stopWatch.Elapsed;
|
||||||
LogHelper.WriteLog($"读取PLC时间:{ts.Milliseconds}", LogTypeEum.Run);
|
LogHelper.WriteLog($"读取PLC时间:{ts.Milliseconds}", LogTypeEum.Run);
|
||||||
if (haschange)
|
if (haschange)
|
||||||
{
|
{
|
||||||
@@ -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,14 +407,16 @@ 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 孙亚龙
|
||||||
//相较而言 使用位移的算法效率更高一些。
|
//相较而言 使用位移的算法效率更高一些。
|
||||||
value = ((readBytArr_D[plcItemDeviationAddress + 1] << 16) + readBytArr_D[plcItemDeviationAddress]).ToString();
|
value = ((readBytArr_D[plcItemDeviationAddress + 1] << 16) + readBytArr_D[plcItemDeviationAddress]).ToString();
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -952,7 +954,16 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return short.Parse(item.PlcItemValue);
|
if (item.PlcItemDataLength == 2)
|
||||||
|
{
|
||||||
|
return int.Parse(item.PlcItemValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return short.Parse(item.PlcItemValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1010,7 +1021,15 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retObj = short.Parse(item_D.PlcItemValue);
|
if (item_D.PlcItemDataLength == 2)
|
||||||
|
{
|
||||||
|
retObj = int.Parse(item_D.PlcItemValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retObj = short.Parse(item_D.PlcItemValue);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PlcItemTypeDesc.X:
|
case PlcItemTypeDesc.X:
|
||||||
|
|||||||
@@ -569,113 +569,123 @@ namespace CleanMachineHMI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string sqlParam = $@"SELECT * FROM SYS_PARAMETER";
|
|
||||||
DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0];
|
int SysRunTime = (int)PlcOperationHelper.Instance.ReadPlcItem("SysRuningTime", PlcItemTypeDesc.D);
|
||||||
if (dtParam != null && dtParam.Rows.Count > 0)
|
int Minutes = SysRunTime / 60;
|
||||||
|
BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
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)
|
kryptonLabel1.Text = Minutes + " Minutes";
|
||||||
{
|
}));
|
||||||
|
|
||||||
if (timerRunNUm == 60)
|
|
||||||
{
|
//string sqlParam = $@"SELECT * FROM SYS_PARAMETER";
|
||||||
sysRuningTimeLen++;
|
//DataTable dtParam = LeadDbHelperSQLite.Query(sqlParam).Tables[0];
|
||||||
if (sysRuningTimeLen < maintainItemTime)
|
//if (dtParam != null && dtParam.Rows.Count > 0)
|
||||||
{
|
//{
|
||||||
//pictureBox1.Visible = false;
|
// int sysRuningTimeLen = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'SysRuningTimeLen'")[0]["PARAMETER_VALUE"]);
|
||||||
BeginInvoke(new Action(() => { pictureBox1.Visible = false; }));
|
// int scrapRate = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'ScrapRate'")[0]["PARAMETER_VALUE"]);
|
||||||
}
|
// int maintainItemTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainItemTime'")[0]["PARAMETER_VALUE"]);
|
||||||
else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime)
|
// int maintainAlarmTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainAlarmTime'")[0]["PARAMETER_VALUE"]);
|
||||||
{
|
// int maintainQuitTime = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainQuitTime'")[0]["PARAMETER_VALUE"]);
|
||||||
//pictureBox1.Visible = true;
|
// int maintainFlag = Convert.ToInt32(dtParam.Select("PARAMETER_CODE = 'MaintainFlag'")[0]["PARAMETER_VALUE"]);
|
||||||
BeginInvoke(new Action(() => { pictureBox1.Visible = true; }));
|
// string maintainRelieveCode = dtParam.Select("PARAMETER_CODE = 'MaintainRelieveCode'")[0]["PARAMETER_VALUE"].ToString();
|
||||||
}
|
// if (maintainFlag == 0)
|
||||||
else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime)
|
// {
|
||||||
{
|
// bool isRun = (bool)PlcOperationHelper.Instance.ReadPlcItem("CleanMacRunStatusNew", PlcItemTypeDesc.M);
|
||||||
//BeginInvoke(new Action(() =>
|
|
||||||
//{
|
// if (isRun)
|
||||||
// pictureBox1.Visible = true;
|
// {
|
||||||
// if (!sysAlarmFrmShowFlag)
|
|
||||||
// {
|
// if (timerRunNUm == 60)
|
||||||
// sysAlarmFrmShowFlag = true;
|
// {
|
||||||
// frmSysExitAlarm frm = new frmSysExitAlarm();
|
// sysRuningTimeLen++;
|
||||||
// //frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。";
|
// if (sysRuningTimeLen < maintainItemTime)
|
||||||
// frm.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes.";
|
// {
|
||||||
// frm.TopLevel = true;
|
// //pictureBox1.Visible = false;
|
||||||
// frm.ShowDialog();
|
// BeginInvoke(new Action(() => { pictureBox1.Visible = false; }));
|
||||||
// }
|
// }
|
||||||
//}));
|
// else if (sysRuningTimeLen >= maintainItemTime && sysRuningTimeLen < maintainAlarmTime)
|
||||||
}
|
// {
|
||||||
else if (sysRuningTimeLen >= maintainQuitTime)
|
// //pictureBox1.Visible = true;
|
||||||
{
|
// BeginInvoke(new Action(() => { pictureBox1.Visible = true; }));
|
||||||
//BeginInvoke(new Action(() =>
|
// }
|
||||||
//{
|
// else if (sysRuningTimeLen >= maintainAlarmTime && sysRuningTimeLen < maintainQuitTime)
|
||||||
// pictureBox1.Visible = true;
|
// {
|
||||||
// string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
|
// //BeginInvoke(new Action(() =>
|
||||||
// DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
|
// //{
|
||||||
// if (dt != null && dt.Rows.Count > 0)
|
// // pictureBox1.Visible = true;
|
||||||
// {
|
// // if (!sysAlarmFrmShowFlag)
|
||||||
// if (!sysAlarmFrmShowFlag)
|
// // {
|
||||||
// {
|
// // sysAlarmFrmShowFlag = true;
|
||||||
// sysAlarmFrmShowFlag = true;
|
// // frmSysExitAlarm frm = new frmSysExitAlarm();
|
||||||
// frmSysExitAlarm frm = new frmSysExitAlarm();
|
// // //frm.showMsg = "机器即将于" + (maintainQuitTime - sysRuningTimeLen) + "分钟后退出。";
|
||||||
// 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.showMsg = $"The machine will exit in {(maintainQuitTime - sysRuningTimeLen)} minutes.";
|
||||||
// frm.TopLevel = true;
|
// // frm.TopLevel = true;
|
||||||
// frm.ShowDialog();
|
// // frm.ShowDialog();
|
||||||
// }
|
// // }
|
||||||
// }
|
// //}));
|
||||||
// else
|
// }
|
||||||
// {
|
// else if (sysRuningTimeLen >= maintainQuitTime)
|
||||||
// string sqlUpdateParam = $@"update SYS_PARAMETER set PARAMETER_VALUE = '1' WHERE PARAMETER_CODE = 'MaintainFlag'";
|
// {
|
||||||
// LeadDbHelperSQLite.ExecuteSql(sqlUpdateParam);
|
// //BeginInvoke(new Action(() =>
|
||||||
// PlcOperationHelper.Instance.WritePlcItem("StopSys", "True", PlcItemTypeDesc.M);
|
// //{
|
||||||
// PlcOperationHelper.Instance.WritePlcItem("StopSys", "False", PlcItemTypeDesc.M);
|
// // pictureBox1.Visible = true;
|
||||||
// PlcOperationHelper.Instance.WritePlcItem("ResetSys", "True", PlcItemTypeDesc.M);
|
// // string sql = "SELECT 1 FROM CM_WORKING_PALLET WHERE WORKING_STATUS = 0";
|
||||||
// PlcOperationHelper.Instance.WritePlcItem("ResetSys", "False", PlcItemTypeDesc.M);
|
// // DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
|
||||||
// Environment.Exit(0);
|
// // if (dt != null && dt.Rows.Count > 0)
|
||||||
// }
|
// // {
|
||||||
//}));
|
// // if (!sysAlarmFrmShowFlag)
|
||||||
}
|
// // {
|
||||||
string sqlUpdateRunTimeLen = $@"UPDATE SYS_PARAMETER set PARAMETER_VALUE = '{sysRuningTimeLen}' WHERE PARAMETER_CODE = 'SysRuningTimeLen'";
|
// // sysAlarmFrmShowFlag = true;
|
||||||
LeadDbHelperSQLite.ExecuteSql(sqlUpdateRunTimeLen);
|
// // frmSysExitAlarm frm = new frmSysExitAlarm();
|
||||||
BeginInvoke(new Action(() =>
|
// // 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;
|
||||||
kryptonLabel1.Text = sysRuningTimeLen + " Minutes";
|
// // frm.ShowDialog();
|
||||||
}));
|
// // }
|
||||||
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个月
|
||||||
|
|||||||
Reference in New Issue
Block a user