修改项目结构
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CleanMachineHMI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
public class CircleButton : Button//继承按钮类 重新生成解决方案就能看见我啦
|
||||
{
|
||||
protected override void OnPaint(PaintEventArgs e)//重新设置控件的形状
|
||||
{
|
||||
base.OnPaint(e);//递归 每次重新都发生此方法,保证其形状为自定义形状
|
||||
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
|
||||
path.AddEllipse(2, 2, this.Width - 6, this.Height - 6);
|
||||
Graphics g = e.Graphics;
|
||||
g.DrawEllipse(new Pen(Color.White, 0), 2, 2, Width - 6, Height - 6);
|
||||
Region = new Region(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using CleanMachineHMI.Domain.Models.ViewModels;
|
||||
using CleanMachineHMI.forms;
|
||||
using CleanMachineHMI.frmChild;
|
||||
using CleanMachineHMI.Utils;
|
||||
using ComponentFactory.Krypton.Toolkit;
|
||||
using Krypton.Toolkit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CleanMachineHMI
|
||||
{
|
||||
/// <summary>
|
||||
/// 方向
|
||||
/// </summary>
|
||||
public enum Orientation
|
||||
{
|
||||
/// <summary>
|
||||
/// 水平方向(从左到右)
|
||||
/// </summary>
|
||||
Horizontal_LR,
|
||||
/// <summary>
|
||||
/// 水平方向(从右到左)
|
||||
/// </summary>
|
||||
Horizontal_RL,
|
||||
/// <summary>
|
||||
/// 垂直方向(从上到上)
|
||||
/// </summary>
|
||||
Vertical_BT,
|
||||
/// <summary>
|
||||
/// 垂直方向(从上到下)
|
||||
/// </summary>
|
||||
Vertical_TB
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标状态
|
||||
/// </summary>
|
||||
public enum MouseStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 鼠标进入
|
||||
/// </summary>
|
||||
Enter,
|
||||
/// <summary>
|
||||
/// 鼠标离开
|
||||
/// </summary>
|
||||
Leave,
|
||||
/// <summary>
|
||||
/// 鼠标按下
|
||||
/// </summary>
|
||||
Down,
|
||||
/// <summary>
|
||||
/// 鼠标按下释放
|
||||
/// </summary>
|
||||
Up
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 滚动条方向
|
||||
/// </summary>
|
||||
public enum OrientationScrollBar
|
||||
{
|
||||
/// <summary>
|
||||
/// 水平方向
|
||||
/// </summary>
|
||||
Horizontal,
|
||||
/// <summary>
|
||||
/// 垂直方向
|
||||
/// </summary>
|
||||
Vertical
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CleanMachineHMI
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件数据
|
||||
/// </summary>
|
||||
public class LEventArgs:EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件数据
|
||||
/// </summary>
|
||||
/// <param name="value">值</param>
|
||||
public LEventArgs(object value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public object Value { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 滚动条事件数据
|
||||
/// </summary>
|
||||
public class LScrollEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 滚动条事件数据
|
||||
/// </summary>
|
||||
/// <param name="sliderPosition">滑块距顶部(垂直)/左侧(横向)位置</param>
|
||||
/// <param name="showPosition">显示位置(正数)</param>
|
||||
public LScrollEventArgs(float sliderPosition, float showPosition)
|
||||
{
|
||||
SliderPosition = sliderPosition;
|
||||
ShowPosition = showPosition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 滑块距顶部(垂直)/左侧(横向)位置
|
||||
/// </summary>
|
||||
public float SliderPosition { get; set; }
|
||||
/// <summary>
|
||||
/// 显示位置(正数)
|
||||
/// </summary>
|
||||
public float ShowPosition { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
* 作者:Leslie Xin
|
||||
* 邮箱:lesliexin@outlook.com
|
||||
* 网站:www.lesliexin.com
|
||||
*
|
||||
* 版权所有,使用本代码需附上本段注释。
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using LEase;
|
||||
|
||||
namespace CleanMachineHMI
|
||||
{
|
||||
|
||||
[ToolboxItem(true)]
|
||||
/// <summary>
|
||||
/// 开关按钮
|
||||
/// </summary>
|
||||
[DefaultEvent("LSwitched")]
|
||||
public class LSwitchButton:Control
|
||||
{
|
||||
/// <summary>
|
||||
/// 开关按钮
|
||||
/// </summary>
|
||||
public LSwitchButton()
|
||||
{
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
CreateControl();
|
||||
|
||||
tTimer = new System.Windows.Forms.Timer();
|
||||
tTimer.Interval = 10;
|
||||
tTimer.Tick += TTimer_Tick;
|
||||
|
||||
}
|
||||
|
||||
#region Event
|
||||
/// <summary>
|
||||
/// 委托
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public delegate void LSwitchedEventHandler(object sender, LEventArgs e);
|
||||
/// <summary>
|
||||
/// 开关状态发生改变时引发的事件
|
||||
/// </summary>
|
||||
public event LSwitchedEventHandler LSwitched;
|
||||
#endregion
|
||||
|
||||
#region Property
|
||||
|
||||
private Color _CloseColor = Color.FromArgb(224, 224, 224);//浅灰
|
||||
/// <summary>
|
||||
/// “关”时背景色<para>默认:浅灰</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("“关”时背景色\r\n默认:浅灰")]
|
||||
public Color L_CloseColor
|
||||
{
|
||||
get { return _CloseColor; }
|
||||
set
|
||||
{
|
||||
_CloseColor = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color _OpenColor = Color.FromArgb(128, 255, 128);//浅绿
|
||||
/// <summary>
|
||||
/// “开”时背景色<para>默认:浅绿</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("“开”时背景色\r\n默认:浅绿")]
|
||||
public Color L_OpenColor
|
||||
{
|
||||
get { return _OpenColor; }
|
||||
set
|
||||
{
|
||||
_OpenColor = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private Color _DotColor = Color.White;
|
||||
/// <summary>
|
||||
/// 圆点颜色<para>默认:白色</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("圆点颜色\r\n默认:白色")]
|
||||
public Color L_DotColor
|
||||
{
|
||||
get { return _DotColor; }
|
||||
set
|
||||
{
|
||||
_DotColor = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private int _DotHight = 20;
|
||||
/// <summary>
|
||||
/// 圆点高度(直径)<para>默认:20</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("圆点高度(直径)\r\n默认:20")]
|
||||
public int L_DotHight
|
||||
{
|
||||
get { return _DotHight; }
|
||||
set
|
||||
{
|
||||
_DotHight = value < 0 ? 0 : value;
|
||||
Size =new Size(Width,Math.Max(_DotHight, _BarHight));
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private int _BarHight = 24;
|
||||
/// <summary>
|
||||
/// 背景条高度<para>默认:24</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("背景条高度\r\n默认:24")]
|
||||
public int L_BarHight
|
||||
{
|
||||
get { return _BarHight; }
|
||||
set
|
||||
{
|
||||
_BarHight = value < 0 ? 0 : value;
|
||||
Size = new Size(Width, Math.Max(_DotHight, _BarHight));
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _IsOpen = false;
|
||||
/// <summary>
|
||||
/// 开关状态是否是“开”<para>默认:false</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("开关状态是否是“开”\r\n默认:false")]
|
||||
public bool L_IsOpen
|
||||
{
|
||||
get { return _IsOpen; }
|
||||
set
|
||||
{
|
||||
_IsOpen = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private int _Margin = 2;
|
||||
/// <summary>
|
||||
/// 圆点距左右两侧距离<para>默认:2</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("圆点距左右两侧距离\r\n默认:2")]
|
||||
public int L_Margin
|
||||
{
|
||||
get { return _Margin; }
|
||||
set
|
||||
{
|
||||
_Margin = value < 0 ? 0 : value; ;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动画效果<para>默认:Quartic</para>
|
||||
/// </summary>
|
||||
[Category("DemoUI"), Description("动画效果\r\n默认:Quartic")]
|
||||
public LEaseType L_AnimateType { get; set; } = LEaseType.Quartic;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
Timer tTimer;
|
||||
float fNowLocationBar, fNowLocationDot;
|
||||
/// <summary>
|
||||
/// 动画效果时长,毫秒
|
||||
/// </summary>
|
||||
int iDuration = 200;
|
||||
int iNow;
|
||||
bool bInAnimate = false;
|
||||
float fRangeBar,fRangeDot;
|
||||
#endregion
|
||||
|
||||
private void TTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
bool b = (_IsOpen?(iNow>=0):(iNow<=iDuration));
|
||||
if (b)
|
||||
{
|
||||
double d = 0;
|
||||
switch (L_AnimateType)
|
||||
{
|
||||
case LEaseType.Back:
|
||||
d = AnimateBase.Back(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Bounce:
|
||||
d = AnimateBase.Bounce(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Circle:
|
||||
d = AnimateBase.Circle(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Cubic:
|
||||
d = AnimateBase.Cubic(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Elastic:
|
||||
d = AnimateBase.Elastic(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Exponential:
|
||||
d = AnimateBase.Exponential(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Quadratic:
|
||||
d = AnimateBase.Quadratic(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Quartic:
|
||||
d = AnimateBase.Quartic(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Quintic:
|
||||
d = AnimateBase.Quintic(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
case LEaseType.Sine:
|
||||
d = AnimateBase.Sine(Convert.ToDouble(iNow) / iDuration, _IsOpen ? LEaseMode.EaseIn : LEaseMode.EaseOut);
|
||||
break;
|
||||
}
|
||||
|
||||
fNowLocationBar = Convert.ToSingle(d * fRangeBar);
|
||||
fNowLocationDot = Convert.ToSingle(d * fRangeDot)+_Margin;
|
||||
iNow = _IsOpen ? (iNow-tTimer.Interval) : (iNow+tTimer.Interval);
|
||||
Invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
tTimer.Stop();
|
||||
bInAnimate = false;
|
||||
LSwitched?.Invoke(this, new LEventArgs(_IsOpen));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
|
||||
{
|
||||
//为达到较好的视觉效果,宽度至少要是高度的两倍
|
||||
int iHeight = Math.Max(_DotHight,_BarHight);
|
||||
int iWidth = Math.Max(iHeight * 2, width);
|
||||
iHeight++;
|
||||
fRangeBar = iWidth - _BarHight;
|
||||
fRangeDot = iWidth - _DotHight- _Margin * 2;
|
||||
base.SetBoundsCore(x, y, iWidth, iHeight, specified);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||
|
||||
Pen penBarBack = new Pen(_CloseColor, _BarHight);
|
||||
Pen penBarFore = new Pen(_OpenColor, _BarHight);
|
||||
penBarBack.StartCap = LineCap.Round;
|
||||
penBarBack.EndCap = LineCap.Round;
|
||||
penBarFore.StartCap = LineCap.Round;
|
||||
penBarFore.EndCap = LineCap.Round;
|
||||
|
||||
float fCapHalfWidth = _BarHight / 2.0f;
|
||||
float fLeftTop = Convert.ToSingle(Height - _DotHight) / 2.0f;
|
||||
|
||||
if (!bInAnimate)
|
||||
{
|
||||
fNowLocationBar = _IsOpen ? 0: fRangeBar;
|
||||
fNowLocationDot = _IsOpen ? _Margin : (fRangeDot + _Margin);
|
||||
}
|
||||
|
||||
//画背景
|
||||
e.Graphics.DrawLine(penBarBack, fCapHalfWidth, Height / 2f, Width - fCapHalfWidth, Height / 2f);
|
||||
//画前景
|
||||
e.Graphics.DrawLine(penBarFore, fCapHalfWidth, Height / 2f, Width - fCapHalfWidth - fNowLocationBar, Height / 2f);
|
||||
//画圆点
|
||||
e.Graphics.FillEllipse(new SolidBrush(_DotColor),Width-_DotHight- fNowLocationDot, fLeftTop, _DotHight, _DotHight);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
if (!bInAnimate)
|
||||
{
|
||||
bInAnimate = true;
|
||||
_IsOpen = !_IsOpen;
|
||||
iNow = _IsOpen ? iDuration : 0;
|
||||
tTimer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace CleanMachineHMI
|
||||
set { this._isConn = value; }
|
||||
}
|
||||
private static IModbusMaster master;
|
||||
private static SerialPort port;
|
||||
private static System.Net.Sockets.TcpClient port;
|
||||
|
||||
public bool PlcInit()
|
||||
{
|
||||
@@ -72,7 +72,8 @@ namespace CleanMachineHMI
|
||||
StopBits stopbis = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'StopBits'")[0]["PARAMETER_VALUE"]) == 0 ? StopBits.None : (Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'StopBits'")[0]["PARAMETER_VALUE"]) == 1 ? StopBits.One : StopBits.Two);
|
||||
Parity paritymsg = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ParityMsg'")[0]["PARAMETER_VALUE"]) == 0 ? Parity.None : (Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ParityMsg'")[0]["PARAMETER_VALUE"]) == 1 ? Parity.Odd : Parity.Even);
|
||||
int modbusPattern = Convert.ToInt32(GlobalHelper.ParameterList.Select(" PARAMETER_CODE = 'ModbusPattern'")[0]["PARAMETER_VALUE"]);
|
||||
port = new SerialPort(portname, baudrate, paritymsg, databits, stopbis);
|
||||
// port = new SerialPort(portname, baudrate, paritymsg, databits, stopbis);
|
||||
port = new System.Net.Sockets.TcpClient();
|
||||
if (modbusPattern == 0)
|
||||
{
|
||||
master = ModbusSerialMaster.CreateRtu(port);
|
||||
@@ -81,7 +82,9 @@ namespace CleanMachineHMI
|
||||
{
|
||||
master = ModbusSerialMaster.CreateAscii(port);
|
||||
}
|
||||
port.Open();
|
||||
port.Connect("127.0.0.1", 5002);
|
||||
// port.Open();
|
||||
this._isConn = true;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -93,7 +96,7 @@ namespace CleanMachineHMI
|
||||
}
|
||||
public void ClosePlcConn()
|
||||
{
|
||||
if (port.IsOpen)
|
||||
if (port.Connected)
|
||||
{
|
||||
port.Close();
|
||||
master = null;
|
||||
@@ -702,7 +705,7 @@ namespace CleanMachineHMI
|
||||
{
|
||||
return false;
|
||||
}
|
||||
master.WriteSingleCoilAsync(1, Convert.ToUInt16(item_M.PlcItemModbusAddress), bool.Parse(writeValue));
|
||||
master.WriteSingleCoil(1, Convert.ToUInt16(item_M.PlcItemModbusAddress), bool.Parse(writeValue));
|
||||
return true;
|
||||
case PlcItemTypeDesc.Y:
|
||||
BasPlcItemMd item_Y = GlobalHelper.PlcItemMd_Y_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||
@@ -710,7 +713,7 @@ namespace CleanMachineHMI
|
||||
{
|
||||
return false;
|
||||
}
|
||||
master.WriteSingleCoilAsync(1, Convert.ToUInt16(item_Y.PlcItemModbusAddress), bool.Parse(writeValue));
|
||||
master.WriteSingleCoil(1, Convert.ToUInt16(item_Y.PlcItemModbusAddress), bool.Parse(writeValue));
|
||||
return true;
|
||||
case PlcItemTypeDesc.D:
|
||||
BasPlcItemMd item_D = GlobalHelper.PlcItemMd_D_List.Find(x => x.PlcItemCode == plcItemCode);
|
||||
@@ -718,7 +721,7 @@ namespace CleanMachineHMI
|
||||
{
|
||||
return false;
|
||||
}
|
||||
master.WriteSingleRegisterAsync(1, Convert.ToUInt16(item_D.PlcItemModbusAddress), ushort.Parse(writeValue));
|
||||
master.WriteSingleRegister(1, Convert.ToUInt16(item_D.PlcItemModbusAddress), ushort.Parse(writeValue));
|
||||
return true;
|
||||
case PlcItemTypeDesc.X:
|
||||
return false;
|
||||
@@ -792,18 +795,18 @@ namespace CleanMachineHMI
|
||||
WritePlcItem("PlcHeartbeatWriteData", wcsToPlcHeartDataNew.ToString(), PlcItemTypeDesc.D);
|
||||
}
|
||||
|
||||
if (DateTime.Now > HeartbeatTime.AddSeconds(5))//心跳超时
|
||||
{
|
||||
isConn = false;
|
||||
//报警处理。
|
||||
frmMainNew.Show_Plc_Alarm("PLC heartbeat data is abnormal, PLC loses connection!");
|
||||
if (ReConnNum % 5 == 0)
|
||||
{
|
||||
ClosePlcConn();
|
||||
PlcInit();
|
||||
}
|
||||
ReConnNum++;
|
||||
}
|
||||
//if (DateTime.Now > HeartbeatTime.AddSeconds(5))//心跳超时
|
||||
//{
|
||||
// isConn = false;
|
||||
// //报警处理。
|
||||
// frmMainNew.Show_Plc_Alarm("PLC heartbeat data is abnormal, PLC loses connection!");
|
||||
// if (ReConnNum % 5 == 0)
|
||||
// {
|
||||
// ClosePlcConn();
|
||||
// PlcInit();
|
||||
// }
|
||||
// ReConnNum++;
|
||||
//}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using CleanMachineHMI.Domain.Enums;
|
||||
using ComponentFactory.Krypton.Navigator;
|
||||
using ComponentFactory.Krypton.Toolkit;
|
||||
using Krypton.Navigator;
|
||||
using Krypton.Toolkit;
|
||||
using LeadDataBaseUtility;
|
||||
using NX_LogUtility;
|
||||
using System;
|
||||
|
||||
Reference in New Issue
Block a user