You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

706 lines
27 KiB

using Module.Plc.ModbusTcp.Tool;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.AxHost;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace MorClient.UserFrmFrame
{
public partial class FrmScrubbingArmUp : Form
{
static int state = 1;
public static bool isShowState = true;
public FrmScrubbingArmUp()
{
InitializeComponent();
}
public void SetState(int a)
{
state = a;
}
#region 实时展示状态值
private delegate void PrintCSStateValueCallBack(); //委托事件
private PrintCSStateValueCallBack ShowCSStateValue;
public static bool IsPrintReadValue = true;
/// <summary>
/// 开始显示实时值线程
/// </summary>
private void StartPrintParamRealValue()
{
if (isShowState)
{
while (IsPrintReadValue)
{
if (this.IsHandleCreated)
{
this.BeginInvoke(ShowCSStateValue, null);
}
System.Threading.Thread.Sleep(100);
}
}
}
/// <summary>
/// 展示参数实时值
/// </summary>
private void PrintParamRealValue()
{
//try
//{
if (MorClient.PublicPara.PlcTool != null)
{
loadingData();
}
//}
//catch (Exception ex)
//{
// ex.ToString();
//}
}
/// <summary>
/// 展示实时数据
/// </summary>
public void loadingData()
{
switch (state)
{
case 1:
uiLabel31.BackColor = Common.commonClass_scr1_scrubUpDown.F_Sor ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel33.BackColor = Common.commonClass_scr1_scrubUpDown.F_Spl ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel36.Text = Common.commonClass_scr1_scrubUpDown.F_ActualPosition.ToString("N2");
uiButton18.FillColor = Common.commonClass_scr1_scrubUpDown.F_Svon ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton10.FillColor = Common.commonClass_scr1_scrubUpDown.F__Reserve3 ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton1.FillColor = Common.commonClass_scr1_scrubUpDown.F__Reserve4 ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
break;
case 2:
uiLabel31.BackColor = Common.commonClass_scr2_scrubUpDown.F_Sor ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel33.BackColor = Common.commonClass_scr2_scrubUpDown.F_Spl ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel36.Text = Common.commonClass_scr2_scrubUpDown.F_ActualPosition.ToString("N2");
uiButton18.FillColor = Common.commonClass_scr2_scrubUpDown.F_Svon ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton10.FillColor = Common.commonClass_scr2_scrubUpDown.F_Home_Ok ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton1.FillColor = Common.commonClass_scr2_scrubUpDown.F_Op_M ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
break;
case 3:
uiLabel31.BackColor = Common.commonClass_scr3_scrubUpDown.F_Sor ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel33.BackColor = Common.commonClass_scr3_scrubUpDown.F_Spl ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel36.Text = Common.commonClass_scr3_scrubUpDown.F_ActualPosition.ToString("N2");
uiButton18.FillColor = Common.commonClass_scr3_scrubUpDown.F_Svon ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton10.FillColor = Common.commonClass_scr3_scrubUpDown.F_Home_Ok ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton1.FillColor = Common.commonClass_scr3_scrubUpDown.F_Op_M ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
break;
case 4:
uiLabel31.BackColor = Common.commonClass_scr4_scrubUpDown.F_Sor ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel33.BackColor = Common.commonClass_scr4_scrubUpDown.F_Spl ? Color.FromArgb(146, 208, 80) : Color.FromArgb(191, 191, 191);
uiLabel36.Text = Common.commonClass_scr4_scrubUpDown.F_ActualPosition.ToString("N2");
uiButton18.FillColor = Common.commonClass_scr4_scrubUpDown.F_Svon ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton10.FillColor = Common.commonClass_scr4_scrubUpDown.F_Home_Ok ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
uiButton1.FillColor = Common.commonClass_scr4_scrubUpDown.F_Op_M ? Color.FromArgb(146, 208, 80) : Color.FromArgb(32, 56, 100);
break;
}
}
#endregion 实时展示状态值
#region 按钮点击
#region 上升
/// <summary>
/// JOG上升按下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void uiButton19_MouseDown(object sender, MouseEventArgs e)
{
uiButton19.FillColor = Color.FromArgb(146, 208, 80);
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.MouseDownHighOrder("1202");
break;
case 2:
MorClient.PublicPara.PlcTool.MouseDownHighOrder("1802");
break;
case 3:
MorClient.PublicPara.PlcTool.MouseDownHighOrder("2402");
break;
case 4:
MorClient.PublicPara.PlcTool.MouseDownHighOrder("3002");
break;
}
}
/// <summary>
/// JOG下降抬起
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void uiButton19_MouseUp(object sender, MouseEventArgs e)
{
uiButton19.FillColor = Color.FromArgb(32, 56, 100);
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.MouseUpHighOrder("1202");
break;
case 2:
MorClient.PublicPara.PlcTool.MouseUpHighOrder("1802");
break;
case 3:
MorClient.PublicPara.PlcTool.MouseUpHighOrder("2402");
break;
case 4:
MorClient.PublicPara.PlcTool.MouseUpHighOrder("3002");
break;
}
}
#endregion
/// <summary>
/// JOG下降按下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void uiButton9_MouseDown(object sender, MouseEventArgs e)
{
uiButton9.FillColor = Color.FromArgb(146, 208, 80);
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.MouseDownLowOrder("1202");
break;
case 2:
MorClient.PublicPara.PlcTool.MouseDownLowOrder("1802");
break;
case 3:
MorClient.PublicPara.PlcTool.MouseDownLowOrder("2402");
break;
case 4:
MorClient.PublicPara.PlcTool.MouseDownLowOrder("3002");
break;
}
}
/// <summary>
/// JOG下降抬起
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void uiButton9_MouseUp(object sender, MouseEventArgs e)
{
uiButton9.FillColor = Color.FromArgb(32, 56, 100);
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.MouseUpLowOrder("1202");
break;
case 2:
MorClient.PublicPara.PlcTool.MouseUpLowOrder("1802");
break;
case 3:
MorClient.PublicPara.PlcTool.MouseUpLowOrder("2402");
break;
case 4:
MorClient.PublicPara.PlcTool.MouseUpLowOrder("3002");
break;
}
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void uiButton2_Click(object sender, EventArgs e)
{
//UnitHandact.IsPrintReadValue = true;
//isShowState = false;
//IsPrintReadValue = false;
//DisStateFrm(unitHandactObj);
this.Close();
}
public void DisStateFrm(FrmScrubbingArmUp frmDisplay)
{
// 取消关闭事件,以便隐藏而不是销毁窗体
frmDisplay.FormClosing += (s, d) => d.Cancel = true;
// 不在任务栏中显示 Form
frmDisplay.ShowInTaskbar = false;
// 隐藏 Form
frmDisplay.Hide();
}
#endregion 按钮点击
#region 文本框输入
private void uiTextBox4_TextChanged(object sender, EventArgs e)
{
if (uiTextBox4.Text != null)
{
if (uiTextBox4.Text.Length > 0)
{
if (!float.TryParse(uiTextBox4.Text, out float fVlue))
{
uiTextBox4.Text = null;
}
}
}
}
private void uiTextBox7_TextChanged(object sender, EventArgs e)
{
if (uiTextBox7.Text != null)
{
if (uiTextBox7.Text.Length > 0)
{
if (!float.TryParse(uiTextBox7.Text, out float fVlue))
{
if (uiTextBox7.Text != "-")
uiTextBox7.Text = null;
}
}
}
}
private void uiTextBox8_TextChanged(object sender, EventArgs e)
{
if (uiTextBox8.Text != null)
{
if (uiTextBox8.Text.Length > 0)
{
if (!float.TryParse(uiTextBox8.Text, out float fVlue))
{
uiTextBox8.Text = null;
}
}
}
}
private void uiTextBox9_TextChanged(object sender, EventArgs e)
{
if (uiTextBox9.Text != null)
{
if (uiTextBox9.Text.Length > 0)
{
if (!float.TryParse(uiTextBox9.Text, out float fVlue))
{
if (uiTextBox9.Text != "-")
uiTextBox9.Text = null;
}
}
}
}
private void uiTextBox10_TextChanged(object sender, EventArgs e)
{
if (uiTextBox10.Text != null)
{
if (uiTextBox10.Text.Length > 0)
{
if (!float.TryParse(uiTextBox10.Text, out float fVlue))
{
uiTextBox10.Text = null;
}
}
}
}
#endregion 文本框输入
/// <summary>
/// 加载数据
/// </summary>
private void FrmScrubbingArmUpLoadInfo()
{
switch (state)
{
case 1:
uiTextBox4.Text = Common.commonClass_scr1_scrubUpDown.F_Velocity_M4.ToString("F2");
uiTextBox7.Text = Common.commonClass_scr1_scrubUpDown.F_Home_Offset.ToString("F2");
uiTextBox8.Text = Common.commonClass_scr1_scrubUpDown.F_Home_Hspeed.ToString("F2");
uiTextBox9.Text = Common.commonClass_scr1_scrubUpDown.F_Position_M0.ToString("F2");
uiTextBox10.Text = Common.commonClass_scr1_scrubUpDown.F_Velocity_M0.ToString("F2");
break;
case 2:
uiTextBox4.Text = Common.commonClass_scr2_scrubUpDown.F_Velocity_M4.ToString("F2");
uiTextBox7.Text = Common.commonClass_scr2_scrubUpDown.F_Home_Offset.ToString("F2");
uiTextBox8.Text = Common.commonClass_scr2_scrubUpDown.F_Home_Hspeed.ToString("F2");
uiTextBox9.Text = Common.commonClass_scr2_scrubUpDown.F_Position_M0.ToString("F2");
uiTextBox10.Text = Common.commonClass_scr2_scrubUpDown.F_Velocity_M0.ToString("F2");
break;
case 3:
uiTextBox4.Text = Common.commonClass_scr3_scrubUpDown.F_Velocity_M4.ToString("F2");
uiTextBox7.Text = Common.commonClass_scr3_scrubUpDown.F_Home_Offset.ToString("F2");
uiTextBox8.Text = Common.commonClass_scr3_scrubUpDown.F_Home_Hspeed.ToString("F2");
uiTextBox9.Text = Common.commonClass_scr3_scrubUpDown.F_Position_M0.ToString("F2");
uiTextBox10.Text = Common.commonClass_scr3_scrubUpDown.F_Velocity_M0.ToString("F2");
break;
case 4:
uiTextBox4.Text = Common.commonClass_scr4_scrubUpDown.F_Velocity_M4.ToString("F2");
uiTextBox7.Text = Common.commonClass_scr4_scrubUpDown.F_Home_Offset.ToString("F2");
uiTextBox8.Text = Common.commonClass_scr4_scrubUpDown.F_Home_Hspeed.ToString("F2");
uiTextBox9.Text = Common.commonClass_scr4_scrubUpDown.F_Position_M0.ToString("F2");
uiTextBox10.Text = Common.commonClass_scr4_scrubUpDown.F_Velocity_M0.ToString("F2");
break;
}
}
#region 光标离开 文本内容写入PLC
private void uiTextBox4_Leave(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(uiTextBox4.Text))
{
string inputText = uiTextBox4.Text;
double inputNumber;
if (double.TryParse(inputText, out inputNumber))
{
// 格式化数字为两位小数
string formattedText = inputNumber.ToString("F2");
uiTextBox4.Text = formattedText;
}
if (uiTextBox4.Text.Length > 0)
{
if (!float.TryParse(uiTextBox4.Text, out float fVlue))
{
return;
}
if (fVlue == 0)
{
return;
}
}
}
else
{
return;
}
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1282", Convert.ToSingle(uiTextBox4.Text));
break;
case 2:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1882", Convert.ToSingle(uiTextBox4.Text));
break;
case 3:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("2482", Convert.ToSingle(uiTextBox4.Text));
break;
case 4:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("3082", Convert.ToSingle(uiTextBox4.Text));
break;
}
}
private void uiTextBox7_Leave(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(uiTextBox7.Text))
{
if (uiTextBox7.Text.Length > 0)
{
if (!float.TryParse(uiTextBox7.Text, out float fVlue))
{
return;
}
if (fVlue == 0)
{
return;
}
}
}
else
{
return;
}
string inputText = uiTextBox7.Text;
double inputNumber;
if (double.TryParse(inputText, out inputNumber))
{
// 格式化数字为两位小数
string formattedText = inputNumber.ToString("F2");
uiTextBox7.Text = formattedText;
}
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1234", Convert.ToSingle(uiTextBox7.Text));
break;
case 2:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1834", Convert.ToSingle(uiTextBox7.Text));
break;
case 3:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("2434", Convert.ToSingle(uiTextBox7.Text));
break;
case 4:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("3034", Convert.ToSingle(uiTextBox7.Text));
break;
}
}
private void uiTextBox8_Leave(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(uiTextBox8.Text))
{
if (uiTextBox8.Text.Length > 0)
{
if (!float.TryParse(uiTextBox8.Text, out float fVlue))
{
return;
}
if (fVlue == 0)
{
return;
}
}
}
else
{
return;
}
string inputText = uiTextBox8.Text;
double inputNumber;
if (double.TryParse(inputText, out inputNumber))
{
// 格式化数字为两位小数
string formattedText = inputNumber.ToString("F2");
uiTextBox8.Text = formattedText;
}
switch (state)
{
case 1:
//uiTextBox4.Text
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1230", Convert.ToSingle(uiTextBox8.Text));
break;
case 2:
//uiTextBox4.Text
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1830", Convert.ToSingle(uiTextBox8.Text));
break;
case 3:
//uiTextBox4.Text
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("2430", Convert.ToSingle(uiTextBox8.Text));
break;
case 4:
//uiTextBox4.Text
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("3030", Convert.ToSingle(uiTextBox8.Text));
break;
}
}
private void uiTextBox9_Leave(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(uiTextBox9.Text))
{
if (uiTextBox9.Text.Length > 0)
{
if (!float.TryParse(uiTextBox9.Text, out float fVlue))
{
return;
}
if (fVlue == 0)
{
return;
}
}
}
else
{
return;
}
string inputText = uiTextBox9.Text;
double inputNumber;
if (double.TryParse(inputText, out inputNumber))
{
// 格式化数字为两位小数
string formattedText = inputNumber.ToString("F2");
uiTextBox9.Text = formattedText;
}
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1254", Convert.ToSingle(uiTextBox9.Text));
break;
case 2:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1854", Convert.ToSingle(uiTextBox9.Text));
break;
case 3:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("2454", Convert.ToSingle(uiTextBox9.Text));
break;
case 4:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("3054", Convert.ToSingle(uiTextBox9.Text));
break;
}
}
private void uiTextBox10_Leave(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(uiTextBox10.Text))
{
if (uiTextBox10.Text.Length > 0)
{
if (!float.TryParse(uiTextBox10.Text, out float fVlue))
{
return;
}
if (fVlue < 0)
{
return;
}
}
}
else
{
return;
}
string inputText = uiTextBox10.Text;
double inputNumber;
if (double.TryParse(inputText, out inputNumber))
{
// 格式化数字为两位小数
string formattedText = inputNumber.ToString("F2");
uiTextBox10.Text = formattedText;
}
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1274", Convert.ToSingle(uiTextBox10.Text));
break;
case 2:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("1874", Convert.ToSingle(uiTextBox10.Text));
break;
case 3:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("2474", Convert.ToSingle(uiTextBox10.Text));
break;
case 4:
MorClient.PublicPara.PlcTool.CommonWriteRealStyle("3074", Convert.ToSingle(uiTextBox10.Text));
break;
}
}
#endregion 光标离开 文本内容写入PLC
private void uiButton18_MouseDown(object sender, MouseEventArgs e)
{
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("1200");
break;
case 2:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("1800");
break;
case 3:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("2400");
break;
case 4:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("3000");
break;
}
}
private void uiButton10_MouseDown(object sender, MouseEventArgs e)
{
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("1203");
break;
case 2:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("1803");
break;
case 3:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("2403");
break;
case 4:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("3003");
break;
}
}
private void uiButton1_MouseDown(object sender, MouseEventArgs e)
{
switch (state)
{
case 1:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("1294");
break;
case 2:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("1894");
break;
case 3:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("2494");
break;
case 4:
MorClient.PublicPara.PlcTool.ValveControlLowOrder("3094");
break;
}
}
private void uiButton18_MouseEnter(object sender, EventArgs e)
{
if (uiButton18.FillColor == Color.FromArgb(146, 208, 80))
{
uiButton18.FillColor = Color.FromArgb(146, 208, 80);
uiButton18.FillHoverColor = Color.FromArgb(146, 208, 80);
}
else if (uiButton18.FillColor == Color.FromArgb(32, 56, 100))
{
uiButton18.FillColor = Color.FromArgb(32, 56, 100);
uiButton18.FillHoverColor = Color.FromArgb(32, 56, 100);
}
}
private void uiButton10_MouseEnter(object sender, EventArgs e)
{
if (uiButton10.FillColor == Color.FromArgb(146, 208, 80))
{
uiButton10.FillColor = Color.FromArgb(146, 208, 80);
uiButton10.FillHoverColor = Color.FromArgb(146, 208, 80);
}
else if (uiButton10.FillColor == Color.FromArgb(32, 56, 100))
{
uiButton10.FillColor = Color.FromArgb(32, 56, 100);
uiButton10.FillHoverColor = Color.FromArgb(32, 56, 100);
}
}
private void uiButton1_MouseEnter(object sender, EventArgs e)
{
if (uiButton1.FillColor == Color.FromArgb(146, 208, 80))
{
uiButton1.FillColor = Color.FromArgb(146, 208, 80);
uiButton1.FillHoverColor = Color.FromArgb(146, 208, 80);
}
else if (uiButton1.FillColor == Color.FromArgb(32, 56, 100))
{
uiButton1.FillColor = Color.FromArgb(32, 56, 100);
uiButton1.FillHoverColor = Color.FromArgb(32, 56, 100);
}
}
private void FrmScrubbingArmUp_Load(object sender, EventArgs e)
{
//委托展示参数实时值
ShowCSStateValue = new PrintCSStateValueCallBack(PrintParamRealValue);
//开始显示实时值线程
System.Threading.Thread printRealValueThread = new System.Threading.Thread(StartPrintParamRealValue);
printRealValueThread.IsBackground = true;
printRealValueThread.Start();
System.Threading.Thread.Sleep(200);
FrmScrubbingArmUpLoadInfo();
}
}
}