SettingControl.cs
5.4 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using CodeLibrary;
using ConfigHelper;
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine
{
public partial class SettingControl : UserControl
{
public SettingControl()
{
InitializeComponent();
RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
//chbAutoRun.Enabled = false;
chbAutoRun.Checked = Setting_Init.App_AutoRun;
this.chbAutoRun.CheckedChanged += new System.EventHandler(this.chbAutoRun_CheckedChanged);
//chbAutoRun.Enabled = true;
}
private void RobotManage_LoadFinishEvent(bool state, string msg)
{
if (!state)
return;
}
private void SettingControl_Load(object sender, EventArgs e)
{
cb_leftmode.Items.AddRange(InOutModeItem.Items);
cb_leftmode.SelectedIndex = (int)((InOutModeE)Setting_Init.Device_LeftInoutMode);
cb_rightmode.Items.AddRange(InOutModeItem.Items);
cb_rightmode.SelectedIndex = (int)((InOutModeE)Setting_Init.Device_RightInoutMode);
//Config.PropertyBind(Setting_Init.Device_Humiture_Port.Key, cb_tempsensorport, "SelectedItem", "SelectedIndexChanged");
}
public static void AutoRun(string strName, bool value)
{
try
{
//创建启动对象
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
//设置运行文件
startInfo.FileName = System.Windows.Forms.Application.StartupPath + "\\AuToRunManager.exe";
//设置启动参数
startInfo.Arguments = String.Join(" ", new string[2] { strName, value.ToString() });
//设置启动动作,确保以管理员身份运行
startInfo.Verb = "runas";
//如果不是管理员,则启动UAC
System.Diagnostics.Process.Start(startInfo);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void chbAutoRun_CheckedChanged(object sender, EventArgs e)
{
if (chbAutoRun.Checked)
{
Setting_Init.App_AutoRun = true;
AutoRun(Application.ExecutablePath, true);
}
else
{
Setting_Init.App_AutoRun = false;
AutoRun(Application.ExecutablePath, false);
}
}
public class InOutModeItem
{
public InOutModeE inOutModeItem = InOutModeE.Both;
public string Name = "";
static List<InOutModeItem> items = new List<InOutModeItem>();
public static InOutModeItem[] Items { get => items.ToArray(); }
public override string ToString()
{
return Name;
}
static InOutModeItem()
{
items.Add(new InOutModeItem { inOutModeItem = InOutModeE.Both, Name = "双向" });
items.Add(new InOutModeItem { inOutModeItem = InOutModeE.OnlyIN, Name = "仅入库" });
items.Add(new InOutModeItem { inOutModeItem = InOutModeE.OnlyOUT, Name = "仅出库" });
items.Add(new InOutModeItem { inOutModeItem = InOutModeE.Disable, Name = "禁用" });
}
}
private void button1_Click(object sender, EventArgs e)
{
Setting_Init.Device_LeftInoutMode = ((InOutModeItem)cb_leftmode.SelectedItem).inOutModeItem;
Setting_Init.Device_RightInoutMode = ((InOutModeItem)cb_rightmode.SelectedItem).inOutModeItem;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!Visible)
return;
lbl_hmdstate.Text = "当前配置端口:" + Setting_Init.Device_Humiture_Port;
lbl_hmdstate.Text = "\r\n当前状态:";
for (int i = 0; i < RobotManage.humitureControllers.Count; i++)
{
lbl_hmdstate.Text += "\r\n\t端口:" + RobotManage.humitureControllers[i].serialPort;
if (!RobotManage.humitureControllers[i].IsRun)
{
lbl_hmdstate.Text += ", 未成功连接";
}
var t = RobotManage.humitureControllers[i].LastData;
lbl_hmdstate.Text += ", 温度" + $":{t.Temperate}℃, " + "湿度" + $":{t.Humidity}%, " + "氮气" + $":{100 - t.OxygenV - 1}%";
}
lblWeight.Text = "称重实时值:";
lblWeight.Text += "\r\n\t端口:" + RobotManage.Config.WeightSensorPort;
if (BSQController.queryData(RobotManage.Config.WeightSensorPort, out double weight))
lblWeight.Text += ", 重量:" + weight.ToString("f1") + "KG";
}
private void button2_Click(object sender, EventArgs e)
{
if(BSQController.ZeroCalibration(RobotManage.Config.WeightSensorPort))
{
MessageBox.Show("称重传感器零校准完成!");
}
}
}
}