Equipment.cs
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyControlLib
{
public partial class Equipment : UserControl
{
public Equipment()
{
InitializeComponent();
timer1.Enabled = true;
}
public int _DisplayValue;
/// <summary>
/// 显示的值
/// </summary>
public int displayValue
{
get
{
return _DisplayValue;
}
set
{
if (value >= 0 && value <= Int16.MaxValue)
{
if (_DisplayValue != value)
{
_DisplayValue = value;
Lampdisplay(_DisplayValue);
}
}
}
}
/// <summary>
/// 显示函数
/// </summary>
/// <param name="value"></param>
public void Lampdisplay(int value)
{
bool[] display = int2bools(value).Reverse().ToArray();
//绿灯 运行+空闲
picGreen.Visible = (display[0] || display[1] );
//蓝灯 通讯正常+计划保养
picBlue.Visible = (display[2] || display[3]);
//红灯 设备异常
picRed.Visible = (display[4]);
//黄灯 调机+警告
picYellow.Visible = (display[5] || display[6]);
}
/// <summary>
/// 16进制int转bool数组
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
private bool[] int2bools(int s)
{
char[] strs = Convert.ToString(s, 2).PadLeft(16, '0').ToCharArray();
bool[] re = new bool[16];
for (int i = 0; i < re.Length; i++)
{
re[i] = strs[i] == '1';
}
return re;
}
private string _DisplayText;
public string DisplayText
{
get { return _DisplayText; }
set
{
if (_DisplayText != value)
{
_DisplayText = value;
textBox1.Text = _DisplayText;
}
}
}
private void textBox1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Lampdisplay(displayValue);
}
}
}