Status.cs
3.6 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AGV_UI
{
public partial class Status : UserControl
{
public Status(string name, List<string> infos)
{
InitializeComponent();
AGVName = name;
missionShow = new Dictionary<string, Control>();
if (infos != null && infos.Count > 0)
{
foreach (var item in infos)
{
missionShow.Add(item, new Label() { Name = item,
Font = new Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))),
AutoSize = true
});
}
flowPanelMissionState.Controls.AddRange(missionShow.Values.ToArray());
}
}
public Status()
{
}
public void Init()
{
foreach (string item in missionShow.Keys)
{
ShowInfo(item, "");
}
SetTitle();
}
public int MaxBattery { get; set; } = 90;
public int MinBattery { get; set; } = 20;
public string AGVName { get; private set; }
#region 私有字段
private Dictionary<string, Control> missionShow;
#endregion
void SetTitle()
{
this.Invoke(new Action(() =>
{
lblName.Text = AGVName;
}
));
}
/// <summary>
/// 设置电量
/// </summary>
/// <param name="curBattery"></param>
/// <param name="isInCharge"></param>
public void SetBattery(int curBattery, bool isInCharge = false)
{
object[] objs = Manager.SetBattery(curBattery, isInCharge, MinBattery, MaxBattery);
try
{
this.Invoke(new Action(() =>
{
lblBattery.Text = objs[0] as string;
lblBattery.Image = objs[1] as Image;
}
));
}
catch { }
}
/// <summary>
/// 设置连接状态
/// </summary>
/// <param name="state"></param>
public void SetConnectState(bool state = false)
{
Image image = Manager.SetConnState(state);
this.Invoke(new Action(() =>
{
picBxConn.Image = image;
}
));
}
public void ShowInfo(string key, string info)
{
this.Invoke(new Action(() =>
{
if (missionShow.ContainsKey(key))
missionShow[key].Text = string.Format("{0}:{1}",key, info);
}
));
}
/// <summary>
/// 设置当前任务名称
/// </summary>
/// <param name="taskName"></param>
public void SetCurTask(string taskName)
{
this.Invoke(new Action(() =>
{
lblTask.Text = taskName;
}
));
}
/// <summary>
/// 设置agv当前状态
/// </summary>
/// <param name="curState"></param>
public void SetCurState(string curState)
{
object[] objs = Manager.SetAGVState(curState);
this.Invoke(new Action(() =>
{
lblAGVState.Text = objs[0] as string;
lblAGVState.Image = objs[1] as Image;
}
));
}
}
}