From 8cf888788392ca9a46e9036e60ff28c14d1ca64e Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:47:48 +0100 Subject: [PATCH] HidStream fix --- app/USB/AsusHid.cs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/USB/AsusHid.cs b/app/USB/AsusHid.cs index 7aac7f6ca..506b4c4bf 100644 --- a/app/USB/AsusHid.cs +++ b/app/USB/AsusHid.cs @@ -1,6 +1,7 @@ using HidSharp; using HidSharp.Reports; using System.Diagnostics; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace GHelper.USB; public static class AsusHid @@ -89,18 +90,24 @@ public static void Write(List dataList, string log = "USB") var devices = FindDevices(AURA_ID); if (devices is null) return; - foreach (var device in devices) - using (var stream = device.Open()) - foreach (var data in dataList) - try - { - stream.Write(data); - Logger.WriteLine($"{log} {device.ProductID.ToString("X")}: {BitConverter.ToString(data)}"); - } - catch (Exception ex) - { - Logger.WriteLine($"Error writing {log} {device.ProductID.ToString("X")}: {ex.Message} {BitConverter.ToString(data)} "); - } + foreach (var device in devices) + try + { + using (var stream = device.Open()) + foreach (var data in dataList) + try + { + stream.Write(data); + Logger.WriteLine($"{log} {device.ProductID.ToString("X")}: {BitConverter.ToString(data)}"); + } + catch (Exception ex) + { + Logger.WriteLine($"Error writing {log} {device.ProductID.ToString("X")}: {ex.Message} {BitConverter.ToString(data)} "); + } + } catch (Exception ex) + { + Logger.WriteLine($"Error opening {log} {device.ProductID.ToString("X")}"); + } }