forked from sudheshk/TISensorToEventHub_WindowsForm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
166 lines (123 loc) · 5.04 KB
/
Copy pathMainForm.cs
File metadata and controls
166 lines (123 loc) · 5.04 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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 SendDataToEHLibrary;
using System.Diagnostics;
//using System.Timers;
//using System.Timers;
namespace TISensorToEH
{
public partial class MainForm : Form
{
Main cs = new Main();
Timer timer ;
int NumberOfBodyTagsShown = 0;
string DisplayText = "";
int TotalMessagesSent = 0;
public MainForm()
{
InitializeComponent();
txtStatus.Text = "Please ensure sensor is connected through bluetooth!";
txtStatus.ForeColor = Color.Red;
var appSettings = System.Configuration.ConfigurationSettings.AppSettings;
txtSBNamespace.Text = appSettings["SBNameSpace"];
txtEHName.Text = appSettings["EHName"];
txtAccessPolicyName.Text = appSettings["AccessPolicyName"];
txtAccessPolicyKey.Text = appSettings["AccessPolicyKey"];
txtSensorName.Text = appSettings["SensorName"];
timer = new Timer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 1000;
//aTimer = new Timer();
//fire();
//Utility.DeletePBIData();
}
private async void button1_Click(object sender, EventArgs e)
{
txtStatus.ForeColor = Color.Blue;
this.Cursor = Cursors.WaitCursor;
txtStatus.Text = "trying to read sensor data ....";
SensorValues.Humidity = "30";
try
{
//string sens = await cs.GetSensorData();
SendDataToEventhub.deviceName = txtSensorName.Text;
SendDataToEventhub.serviceNamespace = txtSBNamespace.Text;
SendDataToEventhub.sharedAccessPolicyName = txtAccessPolicyName.Text;
SendDataToEventhub.sharedAccessKey = txtAccessPolicyKey.Text;
SendDataToEventhub.hubName = txtEHName.Text;
await cs.InitializeSensor();
button1.BackColor = Color.Green;
this.Cursor = Cursors.Default;
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
//MessageBox.Show("Not able to read the bluetooth sensor. Please ensure bluetooth sensor is paired properly and try again.", "Bluetooth Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//return;
//System.Windows.Forms.Application.Exit();
txtStatus.ForeColor = Color.Red;
button1.BackColor = Color.Blue;
this.Cursor = Cursors.Default;
txtStatus.Text = "Not able to read the bluetooth sensor. Please ensure bluetooth sensor is paired properly and try again.";
return;
}
timer.Enabled = true;
timer.Start();
//timer.Enabled = true;
//timer.Start();
}
async void timer_Tick(object sender, EventArgs e)
{
txtStatus.Text = SendDataToEventhub.status;
try
{
//string sens = await cs.GetSensorData();
//await cs.InitializeSensor();
//button1.BackColor = Color.Green;
//this.Cursor = Cursors.Default;
//txtStatus.Text = await cs.GetSensorid();
await cs.GetSensorDataNew ();
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
//MessageBox.Show("Not able to read the bluetooth sensor. Please ensure bluetooth sensor is paired properly and try again.", "Bluetooth Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//return;
//System.Windows.Forms.Application.Exit();
txtStatus.ForeColor = Color.Red;
button1.BackColor = Color.Blue;
this.Cursor = Cursors.Default;
txtStatus.Text = "Not able to read the bluetooth sensor. Please ensure bluetooth sensor is paired properly and try again."+ex.ToString();
timer.Enabled = false;
timer.Stop();
return;
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private async void rbStart_CheckedChanged(object sender, EventArgs e)
{
if (((RadioButton)sender).Checked == true)
{
timer.Enabled = true;
timer.Start();
}
}
private void rbStop_CheckedChanged(object sender, EventArgs e)
{
if (((RadioButton)sender).Checked == true)
timer.Stop();
}
}
}