public void ForceReconnect(BluetoothDisconnect btDisconnectEvent) { closeAll(); count1 = 0; count2 = 0; count3 = 0; count4 = 0; flag1 = 0; flag2 = 0; flag3 = 0; flag4 = 0; BtConnect(disconnectEvent); }
public void BtConnect(BluetoothDisconnect btDisconnectEvent) // CONNECT TO BLUETOOTH, START RECORDING IN STRING BUILDER { disconnectEvent = btDisconnectEvent; // TODO Verify this file exists string imuNames = MMarkInfo.ImuNamesFile; string[] btnames = File.ReadAllLines(imuNames); firstIMU = btnames[0]; secondIMU = btnames[1]; thirdIMU = btnames[2]; fourthIMU = btnames[3]; if (count1 == 0) { NU NU_1 = new NU(); NU_1.setflag += new NU.DataReadyEvent(DataAvailable); NU_1.initialise(firstIMU); if (NU_1.bluetoothConnection || NU_1.USBConnection) { ConnectedIMUS.Add(NU_1); // richTextBox1.AppendText("Device " + NU_1.name + " Connected Successfully\n\n", true); currentIMU = NU_1.name; NU_1.address = getNU(NU_1.name); NU_1.initReg(); flag1 = 0; } else { flag1 = 1; } System.Threading.Thread.Sleep(100); } if (count2 == 0) { NU NU_2 = new NU(); NU_2.setflag += new NU.DataReadyEvent(DataAvailable); NU_2.initialise(secondIMU); if (NU_2.bluetoothConnection || NU_2.USBConnection) { ConnectedIMUS.Add(NU_2); // richTextBox1.AppendText("Device " + NU_2.name + " Connected Successfully\n\n", true); currentIMU = NU_2.name; NU_2.address = getNU(NU_2.name); NU_2.initReg(); flag2 = 0; } else { // richTextBox1.AppendText("Device Not Found\n\n", true); flag2 = 1; } System.Threading.Thread.Sleep(100); } if (count3 == 0) { NU NU_3 = new NU(); NU_3.setflag += new NU.DataReadyEvent(DataAvailable); NU_3.initialise(thirdIMU); if (NU_3.bluetoothConnection || NU_3.USBConnection) { ConnectedIMUS.Add(NU_3); // richTextBox1.AppendText("Device " + NU_3.name + " Connected Successfully\n\n", true); currentIMU = NU_3.name; NU_3.address = getNU(NU_3.name); NU_3.initReg(); flag3 = 0; } else { // richTextBox1.AppendText("Device Not Found\n\n", true); flag3 = 1; } System.Threading.Thread.Sleep(100); } if (count4 == 0) { NU NU_4 = new NU(); NU_4.setflag += new NU.DataReadyEvent(DataAvailable); NU_4.initialise(fourthIMU); if (NU_4.bluetoothConnection || NU_4.USBConnection) { ConnectedIMUS.Add(NU_4); // richTextBox1.AppendText("Device " + NU_4.name + " Connected Successfully\n\n", true); currentIMU = NU_4.name; NU_4.address = getNU(NU_4.name); NU_4.initReg(); flag4 = 0; } else { // richTextBox1.AppendText("Device Not Found\n\n", true); flag4 = 1; } System.Threading.Thread.Sleep(100); } if (flag1 == 0) { count1++; } if (flag2 == 0) { count2++; } if (flag3 == 0) { count3++; } if (flag4 == 0) { count4++; } //button1.Focus(); }