/***********************************************************************************************************/ /***********************************************************************************************************/ /***********************************************************************************************************/ //Event functions #region HOH event functions private void buttonConnect_Click(object sender, EventArgs e) { if (!connectedHOH) { if (NW.Connect()) { //NW.InputChanged += InputDetectedEvent; buttonConnect.Text = "Disconnect"; Debug.WriteLine("HOH Connected"); connectedHOH = true; textBoxLog.Text = ""; btnProtocolStart.Enabled = true; /*TxtBoxUpdater = new MRNetworkTxtBoxUpdater(NW, textBoxLog); * LogUpdater = new Thread(() => TxtBoxUpdater.Run()); * LogUpdater.Start();*/ //NW.ExecuteAndWait("00", "done"); NW.Send("00"); //NW.ExecuteAndWait("00", "untested"); Debug.WriteLine("status" + NW.GetStatusMsg()); } else { //NW.InputChanged -= InputDetectedEvent; // MessageBox.Show("Connect fail"); var result = MessageBox.Show ("Failed to find the device at " + deviceIP + ":" + devicePORT, "Connection fail!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.Retry) { buttonConnect_Click(sender, e); } else { connectedHOH = false; //btnProtocolStart.Enabled = false; } } } else { NW.Send("r"); NW.Send("x"); //resets hand buttonfullyopen_Click(sender, e); if (NW.Disconnect()) { buttonConnect.Text = "Connect"; //necessário para impedir duplicação de recebimentos na callback //NW.InputChanged -= InputDetectedEvent; connectedHOH = false; btnProtocolStart.Enabled = false; //TxtBoxUpdater.Stop(); } } }