private async Task VibrateDevice(string macAddress) { IAxLE device = null; try { Console.WriteLine($"VIBRATE_DEVICE: ConnectDevice()"); for (var retry = 0; ; retry++) { try { device = await _axLEManager.ConnectDevice(macAddress); break; } catch (OpenMovement.AxLE.Comms.Exceptions.CommandFailedException e) { Console.WriteLine($"VIBRATE_DEVICE: GATT error, retry {retry}"); Crashes.TrackError(e); if (retry > 10) { throw; } } catch (OpenMovement.AxLE.Comms.Exceptions.ConnectException e) { Console.WriteLine($"VIBRATE_DEVICE: ConnectException error, retry {retry}"); Crashes.TrackError(e); if (retry > 10) { throw; } } } // try auth with known password Console.WriteLine($"VIBRATE_DEVICE: Authenticate()"); bool authSuccess = await device.Authenticate("YOUR_AUTH_CODE"); // if fails, reset device if (authSuccess) { // buzz device Console.WriteLine($"FLASH AND BUZZ START:{ DateTime.Now }"); //await device.LEDFlash(); await device.VibrateDevice(); Console.WriteLine($"FLASH AND BUZZ END:{ DateTime.Now }"); } } catch (BlockSyncFailedException e) { // move read head to active block Console.WriteLine("BlockSyncFailedException:" + e.ToString()); Crashes.TrackError(e); } catch (DeviceNotInRangeException e) { // display not in range Console.WriteLine("DeviceNotInRangeException:" + e.ToString()); Crashes.TrackError(e); } catch (CommandFailedException e) { // display not in range Console.WriteLine("Command Failed Exception:" + e.ToString()); Crashes.TrackError(e); } catch (Exception e) { Console.WriteLine("Exception:" + e.ToString()); Crashes.TrackError(e); } finally { if (device != null) { await _axLEManager.DisconnectDevice(device); } } }
async Task <bool> MainTasks() { try { if (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.X) { Console.WriteLine("Exiting..."); return(true); } Console.WriteLine("...resuming..."); } if (devices.Count == 0) { Console.WriteLine($"...scanning ({(int)(DateTime.Now - this.started).TotalSeconds} s, {totalFound} reports, {uniqueFound} addresses, {axleDevicesFound} AxLE devices)..."); Thread.Sleep(3000); return(false); } var address = devices.Dequeue(); Console.WriteLine("-------------------------"); Console.WriteLine($"AxLE FOUND: {address.FormatMacAddress()}"); Regex filter = null; if (filterString != null && filterString.Length > 0) { filter = new Regex(filterString, RegexOptions.IgnoreCase); } if (filter != null && filter.Match(address).Length <= 0) { Console.WriteLine($"DEVICE: Ignoring as not matched filter: {address}"); } else { Console.WriteLine($"DEVICE: Connecting... {address.FormatMacAddress()}"); IAxLE device; try { device = await _axLEManager.ConnectDevice(address); } catch (Exception e) { Console.WriteLine("ERROR: Problem connecting to device" + address.FormatMacAddress() + ": " + e.Message); devices.Enqueue(address); // retry later return(false); } Console.WriteLine($"Serial: {address} <{address.FormatMacAddress()}>"); var pass = address.Substring(address.Length - 6); Console.WriteLine("Attempting Auth..."); if (!await device.Authenticate(pass)) { Console.WriteLine("AUTH FAILED!! Device must be wiped to continue proceed? (Y/N)"); if (Console.ReadKey().Key == ConsoleKey.Y) { Console.WriteLine("Resetting device..."); await device.ResetPassword(); Thread.Sleep(500); Console.WriteLine("Device reset. Authenticating..."); await device.Authenticate(pass); } else { Console.WriteLine("Skipping device..."); return(false); } } Console.WriteLine($"Auth Success!!"); Console.WriteLine("*** Flashing and buzzing device ***"); for (; ;) { await device.LEDFlash(); await device.VibrateDevice(); if (Console.KeyAvailable || autoImage) { Console.Write("Found. P=Print, I=Image+Time, N=Skip (P/I/N) >"); var key = autoImage ? ConsoleKey.I : Console.ReadKey().Key; if (key == ConsoleKey.N) { Console.WriteLine("Skipping..."); break; } else if (key == ConsoleKey.P) { Console.WriteLine("Printing..."); // Print MAC address var macAddress = address.FormatMacAddress(); string labelArgs = "" + LabelArgs; labelArgs = labelArgs.Replace("{address}", macAddress); labelArgs = labelArgs.Replace("{addressPlain}", macAddress.Replace(":", "")); labelArgs = labelArgs.Replace("{tapeWidth}", LabelTapeWidth); Console.WriteLine("MAC: " + address); RedirectedProcess.Execute(LabelExecutable, labelArgs); break; } else if (key == ConsoleKey.I) { Console.WriteLine($"Setting time..."); await device.WriteRealTime(DateTime.Now); if (imageFile != null) { Bitmap bitmap = GetBitmap(); var data = GetBitmapData(bitmap); await device.WriteBitmap(data, 0); await device.DisplayIcon(0, imageStart, imageHeight > 0?imageHeight : (int)bitmap.Width); // Image width is height on screen Console.WriteLine($"...done."); } if (autoExit) { return(true); } break; } } } } } catch (Exception e) { Console.WriteLine("ERROR: " + e.Message); } return(false); }