You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Util/ControlsImprot.cs

376 lines
11 KiB
C#

using Mesnac.Action.ChemicalWeighing.RgvPlc;
using Mesnac.Controls.ChemicalWeighing;
using Mesnac.Controls.Default;
using Mesnac.Controls.Feeding;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.Util
{
public class ControlsImprot
{
/// <summary>
/// 控件导入
/// </summary>
/// <typeparam name="T">控件类型</typeparam>
/// <param name="obj">控件实体类</param>
/// <param name="McControls">前端控件集合</param>
public static void ControlImport<T>(object obj, List<Control> McControls) where T : class
{
PropertyInfo[] sourcePropertyInfoList = obj.GetType().GetProperties();
foreach (PropertyInfo sourceProperty in sourcePropertyInfoList)
{
string name = sourceProperty.Name;
var pro = McControls.FirstOrDefault(x => x.Name == name) as T;
sourceProperty.SetValue(obj, pro);
}
}
#region 图像控件交互
/// <summary>
/// 看门狗
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetStateButton(StateButton obj, bool set)
{
if (set == true)
{
obj.Status = StateButton.Statuses.sssRun;
}
else
{
obj.Status = StateButton.Statuses.sssStop;
}
}
/// <summary>
/// 停止状态
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetSystemStateShow(SystemStateShow obj, bool set)
{
if (set == true)
{
obj.Status = SystemStateShow.Statuses.sssRun;
}
else
{
obj.Status = SystemStateShow.Statuses.sssStop;
}
}
/// <summary>
/// 指示灯
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
/// <param name="alarm"></param>
public static void SetSwitchLight(SwitchLight obj, bool set, bool alarm)
{
obj.BackColor = Color.Gray;
if (set == true && alarm == false)
{
obj.Status = SwitchLight.Statuses.ylMove;
}
else if (alarm == true)
{
obj.Status = SwitchLight.Statuses.ylAlarm;
}
else
{
obj.Status = SwitchLight.Statuses.ylNormal;
}
}
public static void SetSwitchLight(SwitchLight obj, bool set)
{
obj.BackColor = Color.Gray;
if (set == true)
{
obj.Status = SwitchLight.Statuses.ylMove;
}
else
{
obj.Status = SwitchLight.Statuses.ylNormal;
}
}
/// <summary>
/// 阀门
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
/// <param name="alarm"></param>
public static void SetLjSwith(LjSwith obj, bool set, bool alarm)
{
if (set == true && alarm == false)
{
obj.Set = true;
obj.Alarm = false;
}
else if (alarm == true)
{
obj.Set = false;
obj.Alarm = true;
}
else
{
obj.Set = false;
obj.Alarm = false;
}
}
/// <summary>
/// 螺旋给料器R
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetRSCREWBIG(RSCREWBIG obj, bool set)
{
if (set == true)
{
obj.Status = RSCREWBIG.Statuses.ylMove;
}
else
{
obj.Status = RSCREWBIG.Statuses.ylNormal;
}
}
/// <summary>
/// 螺旋给料器L
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetLSCREWBIG(LSCREWBIG obj, bool set)
{
if (set == true)
{
obj.Status = LSCREWBIG.Statuses.ylMove;
}
else
{
obj.Status = LSCREWBIG.Statuses.ylNormal;
}
}
/// <summary>
/// 脚座阀
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetJzf(Jzf obj, bool set)
{
if (set == true)
{
obj.Status = Jzf.Statuses.TurnOn;
}
else
{
obj.Status = Jzf.Statuses.TurnOff;
}
}
/// <summary>
/// 文本标签
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetMCLabel(MCLabel obj, object set)
{
obj.Text = Convert.ToString(set);
}
public static void SetMCLabel(MCLabel obj, object set, Color color)
{
obj.Text = Convert.ToString(set);
obj.ForeColor = color;
}
/// <summary>
/// 文本标签布尔转换
/// </summary>
/// <param name="obj"></param>
/// <param name="state"></param>
/// <param name="flag">1为自动手动、2为启动停止</param>
public static void SetMCLabel(MCLabel obj, bool state, int flag)
{
if (flag == 1)
{
obj.Text = state ? "自动" : "手动";
}
else if (flag == 2)
{
obj.Text = state ? "启动" : "停止";
}
else if (flag == 3)
{
obj.Text = state ? "启用" : "停用";
}
obj.ForeColor = state ? Color.Green : Color.Yellow;
}
/// <summary>
/// 三通
/// </summary>
/// <param name="obj"></param>
/// <param name="alarmr"></param>
/// <param name="setr"></param>
/// <param name="alarml"></param>
/// <param name="setl"></param>
public static void SetThreeWayValve(ThreeWayValve obj, bool alarmr, bool setr, bool alarml, bool setl, int kind)
{
obj.ControlKind = kind;
obj.ZLTValue = setr;
obj.ZLDValue = setl;
obj.ALMTValue = alarmr;
obj.ALMDValue = alarml;
}
/// <summary>
/// 风扇电机
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetFan(Fan obj, bool set, bool alarm)
{
if (alarm == true)
{
obj.Status = Fan.Statuses.zsAlarm;
}
else if (set == true)
{
obj.Status = Fan.Statuses.zsTurnOn;
}
else
{
obj.Status = Fan.Statuses.zsTurnOff;
}
}
public static void SetFan(Fan obj, bool set)
{
if (set == true)
{
obj.Status = Fan.Statuses.zsTurnOn;
}
else
{
obj.Status = Fan.Statuses.zsTurnOff;
}
}
/// <summary>
/// 称量柜
/// </summary>
/// <param name="obj"></param>
/// <param name="set"></param>
public static void SetControlCabinet(ControlCabinet obj, bool set, bool alarm)
{
if (alarm == true)
{
obj.Status = ControlCabinet.Statuses.Alarm;
}
else if (set == true)
{
obj.Status = ControlCabinet.Statuses.TurnOn;
}
else
{
obj.Status = ControlCabinet.Statuses.TurnOff;
}
}
public static void SetControlCabinet(ControlCabinet obj, bool set)
{
if (set == true)
{
obj.Status = ControlCabinet.Statuses.TurnOn;
}
else
{
obj.Status = ControlCabinet.Statuses.TurnOff;
}
}
/// <summary>
/// 胡工报警灯
/// </summary>
/// <param name="lanternAlarm"></param>
/// <param name="rGV"></param>
public static void SetHslLanternAlarm(HslLanternAlarm lanternAlarm, RGVEntity rGV)
{
lanternAlarm.IsAlarm = false;
if (rGV.Error)
{
lanternAlarm.NormalColor = Color.Red;
}
else
{
if (rGV.RequestFeed)
{
lanternAlarm.NormalColor = Color.Green;
}
else
{
lanternAlarm.NormalColor = Color.DarkGray;
}
}
}
/// <summary>
/// 绿色胡工小灯
/// </summary>
/// <param name="lanternSimple"></param>
/// <param name="su"></param>
public static void SetHslLanternSimple(HslLanternSimple lanternSimple, bool su)
{
if (su == true)
{
lanternSimple.LanternBackground = Color.LimeGreen;
}
else
{
lanternSimple.LanternBackground = Color.DarkGray;
}
}
/// <summary>
/// 紫色胡工小灯
/// </summary>
/// <param name="lanternSimple"></param>
/// <param name="su"></param>
public static void SetHslLanternSimpleRequest(HslLanternSimple lanternSimple, bool su)
{
if (su == true)
{
lanternSimple.LanternBackground = Color.SlateBlue;
}
else
{
lanternSimple.LanternBackground = Color.DarkGray;
}
}
/// <summary>
/// 胡工料罐
/// </summary>
/// <param name="hslBottle"></param>
/// <param name="value">零到一的值</param>
public static void SetHslBottle(HslBottle hslBottle, float value)
{
hslBottle.ForeColor = Color.White;
hslBottle.Value = value;
}
#endregion
}
}