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/Controls/Mesnac.Controls.ChemicalWei.../ThreeWayValve.cs

353 lines
12 KiB
C#

1 year ago
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace Mesnac.Controls.ChemicalWeighing
{
/// <summary>
/// 自定义3阀门
/// </summary>
public partial class ThreeWayValve : ChemicalWeighingControl
{
private object lockobj = new object();
1 year ago
public ThreeWayValve()
{
InitializeComponent();
InitControl();
}
private string[] sImages = new String[7];
private string[] sImagesL = new String[7];
private string[] sImagesR = new String[7];
private string[] sImagesCL = new String[7];
private string[] sImagesCR = new String[7];
private string[] sImagesFR = new String[7];
private string[] sImagesFL = new String[7];
1 year ago
private bool _zltValue;
private bool _zldValue;
private bool _almtValue;
private bool _almdValue;
private int _controlKind;
1 year ago
/// <summary>
/// 杨威
/// 20230629
/// 初始化控件
/// </summary>
private void InitControl()
{
_assembly = Assembly.GetExecutingAssembly();
//默认程序
sImages[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValve0.png";
//直通
sImages[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValve1.png";
//斜通
sImages[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValve2.png";
//直通报警通知
sImages[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveHError.png";
//斜通报警通知
sImages[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveVError.png";
//都报警
sImages[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveHVError.png";
//三个都通
1 year ago
sImages[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveAll.png";
sImagesL[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveL0.png";
//直通
sImagesL[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveL1.png";
//斜通
sImagesL[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveL2.png";
//直通报警通知
sImagesL[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveLHError.png";
//斜通报警通知
sImagesL[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveLVError.png";
//都报警
sImagesL[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveLHVError.png";
//三个都通
sImagesL[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveLAll.png";
sImagesR[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveR0.png";
//直通
sImagesR[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveR1.png";
//斜通
sImagesR[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveR2.png";
//直通报警通知
sImagesR[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveRHError.png";
//斜通报警通知
sImagesR[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveRVError.png";
//都报警
sImagesR[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveRHVError.png";
//三个都通
sImagesR[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveRAll.png";
1 year ago
sImagesCL[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCL0.png";
//直通
sImagesCL[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCL1.png";
//斜通
sImagesCL[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCL2.png";
//直通报警通知
sImagesCL[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCLHError.png";
//斜通报警通知
sImagesCL[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCLVError.png";
//都报警
sImagesCL[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCLHVError.png";
//三个都通
sImagesCL[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCLAll.png";
sImagesCR[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCR0.png";
//直通
sImagesCR[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCR1.png";
//斜通
sImagesCR[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCR2.png";
//直通报警通知
sImagesCR[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCRHError.png";
//斜通报警通知
sImagesCR[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCRVError.png";
//都报警
sImagesCR[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCRHVError.png";
//三个都通
sImagesCR[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveCRAll.png";
sImagesFR[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFR0.png";
//直通
sImagesFR[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFR1.png";
//斜通
sImagesFR[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFR2.png";
//直通报警通知
sImagesFR[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFRHError.png";
//斜通报警通知
sImagesFR[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFRVError.png";
//都报警
sImagesFR[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFRHVError.png";
//三个都通
sImagesFR[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFRAll.png";
sImagesFL[0] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFL0.png";
//直通
sImagesFL[1] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFL1.png";
//斜通
sImagesFL[2] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFL2.png";
//直通报警通知
sImagesFL[3] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFLHError.png";
//斜通报警通知
sImagesFL[4] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFLVError.png";
//都报警
sImagesFL[5] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFLHVError.png";
//三个都通
sImagesFL[6] = "Mesnac.Controls.ChemicalWeighing.Resources.ThreeWayValveFLAll.png";
1 year ago
}
1 year ago
private void ReloadStream()
{
1 year ago
int defaultIndex = 0;
//如果出现报警 就去判断是直还是斜
1 year ago
//直报警 斜报警
if (_almtValue && _almdValue)
{
defaultIndex = 5;
}
else
{
//如果直的报警
if (_almdValue && _almtValue == false)
1 year ago
{
defaultIndex = 3;
}
//如果斜的报警
if (_almtValue && _almdValue == false)
1 year ago
{
defaultIndex = 4;
}
}
//如果不是故障
if (_almtValue == false && _almdValue == false)
{
if (_zltValue && _zldValue == false)
1 year ago
{
defaultIndex = 2;
}
if (_zltValue == false && _zldValue)
{
defaultIndex = 1;
}
//如果都是假 就变成默认值 可能没有数据
if (_zltValue == false && _zldValue == false)
{
defaultIndex = 0;
}
//如果都是真 就是双通
if (_zltValue && _zldValue)
{
defaultIndex = 6;
}
}
switch (_controlKind)
{
case 0:
_imageStream = _assembly.GetManifestResourceStream(sImages[defaultIndex]);
break;
case 1:
_imageStream = _assembly.GetManifestResourceStream(sImagesL[defaultIndex]);
break;
case 2:
_imageStream = _assembly.GetManifestResourceStream(sImagesR[defaultIndex]);
break;
case 3:
_imageStream = _assembly.GetManifestResourceStream(sImagesCL[defaultIndex]);
break;
case 4:
_imageStream = _assembly.GetManifestResourceStream(sImagesCR[defaultIndex]);
break;
case 5:
_imageStream = _assembly.GetManifestResourceStream(sImagesFL[defaultIndex]);
break;
case 6:
_imageStream = _assembly.GetManifestResourceStream(sImagesFR[defaultIndex]);
break;
default:
_imageStream = _assembly.GetManifestResourceStream(sImages[defaultIndex]);
break;
}
1 year ago
}
1 year ago
private void Reload()
{
if (_imageStream != null)
1 year ago
{
Image img = Image.FromStream(_imageStream);
1 year ago
pictureBox1.Image = img;
pictureBox1.Refresh();
}
}
private void R()
{
lock (lockobj)
{
ReloadStream();
Reload();
}
1 year ago
}
/// <summary>
/// 斜通到位存储Plc的Name
/// </summary>
public string ZLTName { get; set; }
/// <summary>
/// 斜通到位数据
/// </summary>
public bool ZLTValue
{
get => _zltValue;
set
{
if (_zltValue != value)
{
_zltValue = value;
R();
}
1 year ago
}
}
/// <summary>
/// 直通到位Plc的Name
/// </summary>
public string ZLDName { get; set; }
/// <summary>
/// 直通到位Plc的Value
/// </summary>
public bool ZLDValue
{
get => _zldValue;
set
{
if (_zldValue != value)
{
_zldValue = value;
R();
}
1 year ago
}
}
/// <summary>
/// 协通报警
/// </summary>
public string ALMTName { get; set; }
1 year ago
/// <summary>
/// 协通报警Value
/// </summary>
public bool ALMTValue
{
get => _almtValue;
set
{
if (_almtValue != value)
{
_almtValue = value;
R();
}
1 year ago
}
}
/// <summary>
/// 直通报警
/// </summary>
public string ALMDName { get; set; }
/// <summary>
/// 直通报警Value
/// </summary>
public bool ALMDValue
{
get => _almdValue;
set
{
if (_almdValue != value)
{
_almdValue = value;
R();
}
1 year ago
}
}
/// <summary>
/// 控件种类 0向右斜通在下 1向上斜通在左 2向上斜通在右 3向左斜通在上 4向右斜通在上 5向下斜通在右
/// </summary>
public int ControlKind
{
get => _controlKind;
set
{
if (_controlKind != value)
{
_controlKind = value;
R();
}
}
}
1 year ago
}
}