FrmMain.cs
3.0 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
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;
using Asa;
namespace AIOBOX_Debug
{
public partial class FrmMain : Form
{
private InputDisplay input;
private OutputDisplay output;
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
input = new InputDisplay(pictureBox1);
input.SetCount(16);
output = new OutputDisplay(pictureBox2);
output.SetCount(16);
output.DO_Click += Output_DO_Click;
Common.box = new Asa.IOModule.AIOBOX();
Common.box.SetType(Asa.IOModule.Box_Type.DI, 16, Asa.IOModule.Box_Type.DO, 16);
Common.box.DI_Changed_Event += DI_Changed;
Common.box.DO_Changed_Event += DO_Changed;
Common.localIP = Common.box.GetLocalIP();
Common.localIndex = 0;
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
Common.box.Close();
}
private void DI_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
this.Invoke(new Action(() => { input.SetState(sta); }));
}
private void DO_Changed(Asa.IOModule.AIOBOX box, Asa.IOModule.Box_Sta[] sta)
{
this.Invoke(new Action(() => { output.SetState(sta); }));
}
private void Output_DO_Click(int index)
{
Asa.IOModule.Box_Sta sta = Common.box.ReadDO(index);
sta = Common.box.ReverseStatus(sta);
Common.box.WriteDO(index, sta);
}
private void BtnIP_Click(object sender, EventArgs e)
{
using (FrmIP frm = new FrmIP { Text = BtnIP.Text })
{
frm.ShowDialog();
}
}
private void BtnIO_Click(object sender, EventArgs e)
{
using (FrmIO frm = new FrmIO { Text = BtnIO.Text })
{
if (frm.ShowDialog() == DialogResult.OK)
{
}
}
}
private void BtnCon_Click(object sender, EventArgs e)
{
if (Common.box.IsConn)
{
Common.box.Close();
BtnCon.Text = "Connect";
input.IsRun = false;
output.IsRun = false;
}
else
{
Common.box.Connect();
if (Common.box.IsConn)
{
BtnCon.Text = "Disconnect";
input.IsRun = true;
output.IsRun = true;
}
else
{
MessageBox.Show("no");
}
}
}
}
}