Form1.cs
4.7 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
using DeviceLibrary;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutoScanAndLabel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
btn_run.Enabled = false;
btn_stop.Enabled = false;
listView1.View = View.Details;
ColumnHeader msgcol = new ColumnHeader();
msgcol.Text = "信息";
msgcol.Width = 600;
ColumnHeader timecol = new ColumnHeader();
timecol.Text = "时间";
timecol.Width = 150;
listView1.Columns.Add(timecol);
listView1.Columns.Add(msgcol);
LogUtil.info("开始初始化");
//MainControl mc = new MainControl();
//AddForm("控制", mc);
IOControl ioc = new IOControl();
AddForm("IO调试", ioc);
AxisControl ac = new AxisControl();
AddForm("伺服调试", ac);
RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
RobotManage.Init();
}
private void AddForm(string text, UserControl form)
{
//text = text.PadLeft(10, ' ');
TabPage lineTabPage = new TabPage(text);
// lineTabPage.AutoScroll = true;
//lineTabPage.Tag = robot;
Panel linePan = new Panel();
linePan.Dock = DockStyle.Fill;
linePan.AutoScroll = true;
lineTabPage.Controls.Add(linePan);
//form.FormBorderStyle = FormBorderStyle.None;
//form.TopLevel = false;
linePan.Controls.Add(form);
form.Dock = DockStyle.Fill;
linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Show();
//tabPageList.Add(lineTabPage);
tabControl1.Controls.Add(lineTabPage);
}
private void 启用调试模式ToolStripMenuItem_Click(object sender, EventArgs e)
{
RobotManage.IsDebug = RobotManage.IsDebug ? false : true;
(sender as ToolStripMenuItem).Text = !RobotManage.IsDebug ? "启用调试模式" : "停用调试模式";
RobotManage.Init();
}
public delegate void setmsgdelegate(List<Msg> msgs);
private void MainMachine_ProcessMsgEvent(List<Msg> msgs)
{
var d = new setmsgdelegate(SetMsg);
this.Invoke(d, msgs);
}
private void RobotManage_LoadFinishEvent(bool state, string msg)
{
if (state)
{
btn_run.Enabled = true;
btn_stop.Enabled = true;
RobotManage.mainMachine.ProcessMsgEvent += MainMachine_ProcessMsgEvent;
}
var m = new Msg();
m.datetime = DateTime.Now;
m.msgtxt = msg;
m.msgLevel = state ? MsgLevel.info : MsgLevel.warning;
SetMsg(new List<Msg> { m });
}
void SetMsg(List<Msg> msgs)
{
listView1.Items.Clear();
foreach (Msg msg in msgs)
{
ListViewItem lvi = new ListViewItem(new string[] { msg.datetime.ToString(), msg.msgtxt });
if (msg.msgLevel==MsgLevel.info)
lvi.ForeColor = Color.DarkGreen;
else
lvi.ForeColor = Color.Red;
listView1.Items.Add(lvi);
}
}
bool userpause = false;
private void btn_run_Click(object sender, EventArgs e)
{
if (!RobotManage.isRunning)
{
RobotManage.Start();
userpause = false;
(sender as Button).Text = "暂停运行";
}
else if (!userpause)
{
userpause = true;
RobotManage.UserPause(userpause);
(sender as Button).Text = "恢复运行";
}
else if (userpause)
{
userpause = false;
RobotManage.UserPause(userpause);
(sender as Button).Text = "暂停运行";
}
}
private void btn_stop_Click(object sender, EventArgs e)
{
btn_run.Text = "启动";
RobotManage.Stop();
}
}
}