| 139 |
pfowler |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.ComponentModel;
|
|
|
4 |
using System.Data;
|
|
|
5 |
using System.Drawing;
|
|
|
6 |
using System.Linq;
|
|
|
7 |
using System.Text;
|
|
|
8 |
using System.Threading.Tasks;
|
|
|
9 |
using System.Windows.Forms;
|
|
|
10 |
|
|
|
11 |
namespace NITNavComm
|
|
|
12 |
{
|
|
|
13 |
public partial class MainForm : Form
|
|
|
14 |
{
|
|
|
15 |
|
|
|
16 |
private NITPanels panels = new NITPanels();
|
|
|
17 |
|
|
|
18 |
public MainForm() {
|
|
|
19 |
InitializeComponent();
|
|
|
20 |
|
|
|
21 |
Devices_Rescan();
|
|
|
22 |
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
private void Devices_Rescan() {
|
|
|
26 |
Log("Scanning for devices...");
|
|
|
27 |
|
|
|
28 |
panels.UsbScan();
|
|
|
29 |
|
|
|
30 |
this.deviceGrid.DataSource = panels.devices;
|
|
|
31 |
this.txtDevices.Text = panels.devices.Count.ToString();
|
|
|
32 |
|
|
|
33 |
if (panels.devices.Count > 0) {
|
|
|
34 |
this.cmDevTest.Enabled = true;
|
|
|
35 |
Log(panels.devices.Count.ToString() + " devices found during scan.");
|
|
|
36 |
} else {
|
|
|
37 |
Log("No devices found, check connections and rescan.");
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
private void cmdRescan_Click(object sender, EventArgs e) {
|
|
|
42 |
this.Devices_Rescan();
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
private void cmdDevRescan_Click(object sender, EventArgs e) {
|
|
|
46 |
this.Devices_Rescan();
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private void cmDevTest_Click(object sender, EventArgs e) {
|
|
|
50 |
NITDevice device = (NITDevice) this.deviceGrid.CurrentRow.DataBoundItem;
|
|
|
51 |
NITNavCommDevice navcomm = new NITNavCommDevice(device);
|
|
|
52 |
|
|
|
53 |
if (!navcomm.Open()) {
|
|
|
54 |
Log("Could not open device " + device.type + "(" + device.serial + ").");
|
|
|
55 |
return;
|
|
|
56 |
}
|
|
|
57 |
navcomm.Close();
|
|
|
58 |
|
|
|
59 |
NITCommNavForm form = new NITCommNavForm();
|
|
|
60 |
form.setDevice(navcomm);
|
|
|
61 |
form.Show(this);
|
|
|
62 |
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public void Log(string msg) {
|
|
|
66 |
txtLog.AppendText(msg + "\r\n");
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public void Log(byte[] buffer) {
|
|
|
70 |
StringBuilder sb = new StringBuilder();
|
|
|
71 |
foreach (byte data in buffer) {
|
|
|
72 |
sb.Append(data.ToString("X") + " ");
|
|
|
73 |
}
|
|
|
74 |
Log(sb.ToString());
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
private void quitToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
|
78 |
if (QuestionBox("Exit NIT Panels?", "Exiting will disable NIT Panels. Continue?")) {
|
|
|
79 |
Application.Exit();
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
public bool QuestionBox(string caption, string message) {
|
|
|
84 |
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
|
|
|
85 |
DialogResult result;
|
|
|
86 |
|
|
|
87 |
result = MessageBox.Show(message, caption, buttons);
|
|
|
88 |
|
|
|
89 |
if (result == System.Windows.Forms.DialogResult.Yes) {
|
|
|
90 |
return true;
|
|
|
91 |
}
|
|
|
92 |
return false;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
private void txtLog_VisibleChanged(object sender, EventArgs e) {
|
|
|
96 |
if (txtLog.Visible) {
|
|
|
97 |
txtLog.SelectionStart = txtLog.TextLength;
|
|
|
98 |
txtLog.ScrollToCaret();
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
}
|