in Hands-on lab/lab-files/starter-project/SmartMeterSimulator/MainForm.cs [109:137]
private void btnConnect_Click(object sender, EventArgs e)
{
//Connect all of the activated devices and initiate an event loop
// for each connected device to transmit data on regular interval
stopQueue = false;
foreach (Button button in pDevices.Controls)
{
if (button.Tag == null)
continue;
//Get the sensor object from the button container
Sensor sensor = (Sensor)button.Tag;
//Select devices which have been installed and activated
if (sensor.State == DeviceState.Registered || button.BackColor == Color.Cyan)
{
//Connect the device, puts into Ready State
sensor.ConnectDevice();
//add hover event for tool tip for device info
button.MouseHover += Device_Hover;
//Add Sensor to loop
if (!stopQueue)
queue.QueueTask(() => DoWork(sensor));
}
}
}