From 66a96c62862fafdbe01ca6c8511abe81b0dedecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Bj=C3=B8rgo?= Date: Sun, 15 Dec 2024 16:14:55 +0100 Subject: [PATCH 1/4] ConfigureAwait(false) in main project --- .../FunctionalityTest.cs | 4 +++- src/HeboTech.ATLib/Parsing/AtChannel.cs | 14 +++++++------- src/HeboTech.ATLib/Parsing/AtReader.cs | 6 +++--- src/HeboTech.ATLib/Parsing/AtWriter.cs | 12 ++++++------ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs b/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs index 6732add..71b617b 100644 --- a/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs +++ b/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Threading.Tasks; using HeboTech.ATLib.Modems.Cinterion; +using HeboTech.ATLib.Modems.Adafruit; namespace HeboTech.ATLib.TestConsole { @@ -39,8 +40,9 @@ public static async Task RunAsync(System.IO.Stream stream, string pin) { using AtChannel atChannel = AtChannel.Create(stream); atChannel.EnableDebug(Log); + using IFona3G modem = new Fona3G(atChannel); //using IMC55i modem = new MC55i(atChannel); - using IDWM222 modem = new DWM222(atChannel); + //using IDWM222 modem = new DWM222(atChannel); atChannel.Open(); await atChannel.ClearAsync(); diff --git a/src/HeboTech.ATLib/Parsing/AtChannel.cs b/src/HeboTech.ATLib/Parsing/AtChannel.cs index 16102cc..92b1ff7 100644 --- a/src/HeboTech.ATLib/Parsing/AtChannel.cs +++ b/src/HeboTech.ATLib/Parsing/AtChannel.cs @@ -94,7 +94,7 @@ public async Task ClearAsync(CancellationToken cancellationToken = default) { for (int i = 0; i < atReader.AvailableItems(); i++) { - await atReader.ReadAsync(cancellationToken); + await atReader.ReadAsync(cancellationToken).ConfigureAwait(false); } } @@ -111,7 +111,7 @@ public virtual Task SendCommand(string command, TimeSpan? timeout = public virtual async Task SendSingleLineCommandAsync(string command, string responsePrefix, TimeSpan? timeout = null) { - AtResponse response = await SendFullCommandAsync(new AtCommand(AtCommandType.SINGELLINE, command, responsePrefix, null, timeout ?? DefaultCommandTimeout)); + AtResponse response = await SendFullCommandAsync(new AtCommand(AtCommandType.SINGELLINE, command, responsePrefix, null, timeout ?? DefaultCommandTimeout)).ConfigureAwait(false); if (response != null && response.Success && !response.Intermediates.Any()) { @@ -130,7 +130,7 @@ public virtual Task SendMultilineCommand(string command, string resp public virtual async Task SendSmsAsync(string command, string pdu, string responsePrefix, TimeSpan? timeout = null) { - AtResponse response = await SendFullCommandAsync(new AtCommand(AtCommandType.SINGELLINE, command, responsePrefix, pdu, timeout ?? DefaultCommandTimeout)); + AtResponse response = await SendFullCommandAsync(new AtCommand(AtCommandType.SINGELLINE, command, responsePrefix, pdu, timeout ?? DefaultCommandTimeout)).ConfigureAwait(false); if (response != null && response.Success && !response.Intermediates.Any()) { @@ -160,9 +160,9 @@ private async Task SendFullCommandAsync(AtCommand command, Cancellat if (debugEnabled) debugAction($"Out: {command.Command}"); - await atWriter.WriteLineAsync(command.Command); + await atWriter.WriteLineAsync(command.Command).ConfigureAwait(false); - if (!await waitingForCommandResponse.WaitAsync(command.Timeout, cancellationToken)) + if (!await waitingForCommandResponse.WaitAsync(command.Timeout, cancellationToken).ConfigureAwait(false)) throw new TimeoutException("Timed out while waiting for command response"); return currentResponse; @@ -181,7 +181,7 @@ private async Task ReaderLoopAsync(CancellationToken cancellationToken = default string line1; try { - line1 = await atReader.ReadAsync(cancellationToken); + line1 = await atReader.ReadAsync(cancellationToken).ConfigureAwait(false); if (debugEnabled) debugAction($"In (line1): {line1}"); } @@ -198,7 +198,7 @@ private async Task ReaderLoopAsync(CancellationToken cancellationToken = default string line2; try { - line2 = await atReader.ReadAsync(cancellationToken); + line2 = await atReader.ReadAsync(cancellationToken).ConfigureAwait(false); if (debugEnabled) debugAction($"In (line2): {line2}"); } diff --git a/src/HeboTech.ATLib/Parsing/AtReader.cs b/src/HeboTech.ATLib/Parsing/AtReader.cs index 948b70b..6682bf9 100644 --- a/src/HeboTech.ATLib/Parsing/AtReader.cs +++ b/src/HeboTech.ATLib/Parsing/AtReader.cs @@ -58,7 +58,7 @@ private async Task ReadPipeAsync(PipeReader reader, CancellationToken cancellati ReadResult result; try { - result = await reader.ReadAsync(cancellationToken); + result = await reader.ReadAsync(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -70,7 +70,7 @@ private async Task ReadPipeAsync(PipeReader reader, CancellationToken cancellati { try { - await channel.Writer.WriteAsync(line, cancellationToken); + await channel.Writer.WriteAsync(line, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -89,7 +89,7 @@ private async Task ReadPipeAsync(PipeReader reader, CancellationToken cancellati } // Mark the PipeReader as complete. - await reader.CompleteAsync(); + await reader.CompleteAsync().ConfigureAwait(false); } private static bool TryReadLine(ref ReadOnlySequence buffer, out string line) diff --git a/src/HeboTech.ATLib/Parsing/AtWriter.cs b/src/HeboTech.ATLib/Parsing/AtWriter.cs index 41348b0..693fc36 100644 --- a/src/HeboTech.ATLib/Parsing/AtWriter.cs +++ b/src/HeboTech.ATLib/Parsing/AtWriter.cs @@ -18,21 +18,21 @@ public AtWriter(Stream stream) public async Task WriteLineAsync(string command, CancellationToken cancellationToken = default) { - await WriteAsync(command, cancellationToken); - await WriteAsync("\r", cancellationToken); + await WriteAsync(command, cancellationToken).ConfigureAwait(false); + await WriteAsync("\r", cancellationToken).ConfigureAwait(false); } public async Task WriteSmsPduAndCtrlZAsync(string smsPdu, CancellationToken cancellationToken = default) { - await WriteAsync(smsPdu, cancellationToken); - await WriteAsync("\x1A", cancellationToken); + await WriteAsync(smsPdu, cancellationToken).ConfigureAwait(false); + await WriteAsync("\x1A", cancellationToken).ConfigureAwait(false); } protected async Task WriteAsync(string text, CancellationToken cancellationToken = default) { byte[] buffer = Encoding.UTF8.GetBytes(text); - await stream.WriteAsync(buffer, 0, buffer.Length, cancellationToken); - await stream.FlushAsync(cancellationToken); + await stream.WriteAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false); + await stream.FlushAsync(cancellationToken).ConfigureAwait(false); } public void Close() From c629e874593caf204e93c7e105ba3663691318a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Bj=C3=B8rgo?= Date: Sun, 15 Dec 2024 16:18:51 +0100 Subject: [PATCH 2/4] ConfigureAwait(false) in modem project --- src/HeboTech.ATLib.Modems/Adafruit/Fona3G.cs | 14 ++-- src/HeboTech.ATLib.Modems/Cinterion/MC55i.cs | 8 +- .../Generic/ModemBase.cs | 80 +++++++++---------- src/HeboTech.ATLib.Modems/SIMCOM/SIM5320.cs | 6 +- src/HeboTech.ATLib.Modems/Telit/ME910C1.cs | 8 +- 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/HeboTech.ATLib.Modems/Adafruit/Fona3G.cs b/src/HeboTech.ATLib.Modems/Adafruit/Fona3G.cs index f0d2b91..ed0e1c3 100644 --- a/src/HeboTech.ATLib.Modems/Adafruit/Fona3G.cs +++ b/src/HeboTech.ATLib.Modems/Adafruit/Fona3G.cs @@ -20,15 +20,15 @@ public Fona3G(IAtChannel channel) public override async Task SetRequiredSettingsBeforePinAsync() { - ModemResponse echo = await DisableEchoAsync(); - ModemResponse errorFormat = await SetErrorFormatAsync(1); + ModemResponse echo = await DisableEchoAsync().ConfigureAwait(false); + ModemResponse errorFormat = await SetErrorFormatAsync(1).ConfigureAwait(false); return echo.Success && errorFormat.Success; } public override async Task SetRequiredSettingsAfterPinAsync() { - ModemResponse currentCharacterSet = await SetCharacterSetAsync(CharacterSet.UCS2); - ModemResponse smsMessageFormat = await SetSmsMessageFormatAsync(SmsTextFormat.PDU); + ModemResponse currentCharacterSet = await SetCharacterSetAsync(CharacterSet.UCS2).ConfigureAwait(false); + ModemResponse smsMessageFormat = await SetSmsMessageFormatAsync(SmsTextFormat.PDU).ConfigureAwait(false); return currentCharacterSet.Success && smsMessageFormat.Success; } @@ -37,7 +37,7 @@ public override async Task SetRequiredSettingsAfterPinAsync() // switch (smsTextFormat) // { // case SmsTextFormat.PDU: - // AtResponse pduResponse = await channel.SendMultilineCommand($"AT+CMGR={index}", null); + // AtResponse pduResponse = await channel.SendMultilineCommand($"AT+CMGR={index}", null).ConfigureAwait(false); // if (pduResponse.Success) // { @@ -60,7 +60,7 @@ public override async Task SetRequiredSettingsAfterPinAsync() // } // break; // case SmsTextFormat.Text: - // AtResponse textResponse = await channel.SendMultilineCommand($"AT+CMGR={index}", null); + // AtResponse textResponse = await channel.SendMultilineCommand($"AT+CMGR={index}", null).ConfigureAwait(false); // if (textResponse.Success && textResponse.Intermediates.Count > 0) // { @@ -114,7 +114,7 @@ public override async Task SetRequiredSettingsAfterPinAsync() // _ => throw new Exception("Unknown SMS Text Format") // }; - // AtResponse response = await channel.SendMultilineCommand(command, null); + // AtResponse response = await channel.SendMultilineCommand(command, null).ConfigureAwait(false); // List smss = new List(); // if (response.Success) diff --git a/src/HeboTech.ATLib.Modems/Cinterion/MC55i.cs b/src/HeboTech.ATLib.Modems/Cinterion/MC55i.cs index 2cb39fb..9f74958 100644 --- a/src/HeboTech.ATLib.Modems/Cinterion/MC55i.cs +++ b/src/HeboTech.ATLib.Modems/Cinterion/MC55i.cs @@ -36,7 +36,7 @@ public override async Task>> SendSmsAsyn { string cmd1 = $"AT+CMGS={(pdu.Length - 2) / 2}"; // Subtract 2 (one octet) for SMSC. string cmd2 = pdu; - AtResponse response = await channel.SendSmsAsync(cmd1, cmd2, "+CMGS:", TimeSpan.FromSeconds(30)); + AtResponse response = await channel.SendSmsAsync(cmd1, cmd2, "+CMGS:", TimeSpan.FromSeconds(30)).ConfigureAwait(false); if (response.Success) { @@ -59,7 +59,7 @@ public override async Task>> SendSmsAsyn public override async Task> GetBatteryStatusAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT^SBC?", "^SBC:"); + AtResponse response = await channel.SendSingleLineCommandAsync("AT^SBC?", "^SBC:").ConfigureAwait(false); if (response.Success) { @@ -79,7 +79,7 @@ public override async Task> GetBatteryStatusAsync() public async Task> MC55i_GetBatteryStatusAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT^SBC?", "^SBC:"); + AtResponse response = await channel.SendSingleLineCommandAsync("AT^SBC?", "^SBC:").ConfigureAwait(false); if (response.Success) { @@ -109,7 +109,7 @@ public async Task> MC55i_GetBatteryStatusAsync /// Command status public override async Task SetNewSmsIndicationAsync(int mode, int mt, int bm, int ds, int bfr) { - AtResponse response = await channel.SendCommand($"AT+CNMI={mode},{mt},{bm},{ds}"); + AtResponse response = await channel.SendCommand($"AT+CNMI={mode},{mt},{bm},{ds}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); diff --git a/src/HeboTech.ATLib.Modems/Generic/ModemBase.cs b/src/HeboTech.ATLib.Modems/Generic/ModemBase.cs index 60f115c..5df2ca8 100644 --- a/src/HeboTech.ATLib.Modems/Generic/ModemBase.cs +++ b/src/HeboTech.ATLib.Modems/Generic/ModemBase.cs @@ -83,10 +83,10 @@ protected virtual void Channel_UnsolicitedEvent(object sender, UnsolicitedEventA public virtual async Task SetRequiredSettingsBeforePinAsync() { - ModemResponse echo = await DisableEchoAsync(); - ModemResponse errorFormat = await SetErrorFormatAsync(1); - ModemResponse currentCharacterSet = await SetCharacterSetAsync(CharacterSet.UCS2); - ModemResponse smsMessageFormat = await SetSmsMessageFormatAsync(SmsTextFormat.PDU); + ModemResponse echo = await DisableEchoAsync().ConfigureAwait(false); + ModemResponse errorFormat = await SetErrorFormatAsync(1).ConfigureAwait(false); + ModemResponse currentCharacterSet = await SetCharacterSetAsync(CharacterSet.UCS2).ConfigureAwait(false); + ModemResponse smsMessageFormat = await SetSmsMessageFormatAsync(SmsTextFormat.PDU).ConfigureAwait(false); return echo.Success && errorFormat.Success && currentCharacterSet.Success && smsMessageFormat.Success; } @@ -97,7 +97,7 @@ public virtual Task SetRequiredSettingsAfterPinAsync() public virtual async Task> GetImsiAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT+CIMI", string.Empty); + AtResponse response = await channel.SendSingleLineCommandAsync("AT+CIMI", string.Empty).ConfigureAwait(false); if (response.Success) { @@ -115,26 +115,26 @@ public virtual async Task> GetImsiAsync() public virtual async Task AnswerIncomingCallAsync() { - AtResponse response = await channel.SendCommand("ATA"); + AtResponse response = await channel.SendCommand("ATA").ConfigureAwait(false); return ModemResponse.IsSuccess(response.Success); } public virtual async Task DialAsync(PhoneNumber phoneNumber, bool hideCallerNumber = false, bool closedUserGroup = false) { string command = $"ATD{phoneNumber}{(hideCallerNumber ? 'I' : 'i')}{(closedUserGroup ? 'G' : 'g')};"; - AtResponse response = await channel.SendCommand(command, TimeSpan.FromSeconds(45)); + AtResponse response = await channel.SendCommand(command, TimeSpan.FromSeconds(45)).ConfigureAwait(false); return ModemResponse.IsSuccess(response.Success); } public virtual async Task DisableEchoAsync() { - AtResponse response = await channel.SendCommand("ATE0"); + AtResponse response = await channel.SendCommand("ATE0").ConfigureAwait(false); return ModemResponse.IsSuccess(response.Success); } public virtual async Task> GetProductIdentificationInformationAsync() { - AtResponse response = await channel.SendMultilineCommand("ATI", null); + AtResponse response = await channel.SendMultilineCommand("ATI", null).ConfigureAwait(false); if (response.Success) { @@ -151,7 +151,7 @@ public virtual async Task> GetPr public virtual async Task HangupAsync() { - AtResponse response = await channel.SendCommand($"AT+CHUP"); + AtResponse response = await channel.SendCommand($"AT+CHUP").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -162,7 +162,7 @@ public virtual async Task HangupAsync() public virtual async Task>> GetAvailableCharacterSetsAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CSCS=?", "+CSCS:"); + AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CSCS=?", "+CSCS:").ConfigureAwait(false); if (response.Success) { @@ -180,7 +180,7 @@ public virtual async Task>> GetAvailableCharac public virtual async Task> GetCurrentCharacterSetAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CSCS?", "+CSCS:"); + AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CSCS?", "+CSCS:").ConfigureAwait(false); if (response.Success) { @@ -200,7 +200,7 @@ public virtual async Task> GetCurrentCharacterSetAsy public virtual async Task SetCharacterSetAsync(CharacterSet characterSet) { - AtResponse response = await channel.SendCommand($"AT+CSCS=\"{CharacterSetHelpers.ToString(characterSet)}\""); + AtResponse response = await channel.SendCommand($"AT+CSCS=\"{CharacterSetHelpers.ToString(characterSet)}\"").ConfigureAwait(false); if (response.Success) { return ModemResponse.IsSuccess(response.Success); @@ -214,7 +214,7 @@ public virtual async Task SetCharacterSetAsync(CharacterSet chara #region _3GPP_TS_27_005 public virtual async Task> GetSmsMessageFormatAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CMGF?", "+CMGF:"); + AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CMGF?", "+CMGF:").ConfigureAwait(false); if (response.Success) { @@ -233,7 +233,7 @@ public virtual async Task> GetSmsMessageFormatAsync() public virtual async Task SetSmsMessageFormatAsync(SmsTextFormat format) { - AtResponse response = await channel.SendCommand($"AT+CMGF={(int)format}"); + AtResponse response = await channel.SendCommand($"AT+CMGF={(int)format}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(response.Success); @@ -244,7 +244,7 @@ public virtual async Task SetSmsMessageFormatAsync(SmsTextFormat //public virtual async Task SetSelectMessageService(int service) //{ - // AtResponse response = await channel.SendCommand($"AT+CSMS={service}"); + // AtResponse response = await channel.SendCommand($"AT+CSMS={service}").ConfigureAwait(false); // if (response.Success) // return ModemResponse.IsSuccess(); @@ -255,7 +255,7 @@ public virtual async Task SetSmsMessageFormatAsync(SmsTextFormat public virtual async Task SetNewSmsIndicationAsync(int mode, int mt, int bm, int ds, int bfr) { - AtResponse response = await channel.SendCommand($"AT+CNMI={mode},{mt},{bm},{ds},{bfr}"); + AtResponse response = await channel.SendCommand($"AT+CNMI={mode},{mt},{bm},{ds},{bfr}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -280,7 +280,7 @@ protected async Task>> SendSmsAsync(SmsS { string cmd1 = $"AT+CMGS={(pdu.Length) / 2}"; string cmd2 = pdu; - AtResponse response = await channel.SendSmsAsync(cmd1, cmd2, "+CMGS:", TimeSpan.FromSeconds(30)); + AtResponse response = await channel.SendSmsAsync(cmd1, cmd2, "+CMGS:", TimeSpan.FromSeconds(30)).ConfigureAwait(false); if (response.Success) { @@ -303,7 +303,7 @@ protected async Task>> SendSmsAsync(SmsS public virtual async Task> GetSupportedPreferredMessageStoragesAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CPMS=?", "+CPMS:"); + AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CPMS=?", "+CPMS:").ConfigureAwait(false); if (response.Success && response.Intermediates.Count > 0) { @@ -325,7 +325,7 @@ public virtual async Task> GetS public virtual async Task> GetPreferredMessageStoragesAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CPMS?", "+CPMS:"); + AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CPMS?", "+CPMS:").ConfigureAwait(false); if (response.Success && response.Intermediates.Count > 0) { @@ -350,7 +350,7 @@ public virtual async Task> GetPreferredM public virtual async Task> SetPreferredMessageStorageAsync(MessageStorage storage1Name, MessageStorage storage2Name, MessageStorage storage3Name) { - AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CPMS=\"{storage1Name}\",\"{storage2Name}\",\"{storage3Name}\"", "+CPMS:"); + AtResponse response = await channel.SendSingleLineCommandAsync($"AT+CPMS=\"{storage1Name}\",\"{storage2Name}\",\"{storage3Name}\"", "+CPMS:").ConfigureAwait(false); if (response.Success && response.Intermediates.Count > 0) { @@ -378,7 +378,7 @@ public virtual async Task> SetPreferredM public virtual async Task> ReadSmsAsync(int index) { - AtResponse pduResponse = await channel.SendMultilineCommand($"AT+CMGR={index}", null); + AtResponse pduResponse = await channel.SendMultilineCommand($"AT+CMGR={index}", null).ConfigureAwait(false); if (pduResponse.Success) { @@ -415,7 +415,7 @@ public virtual async Task>> ListSmssAsync(SmsSt { string command = $"AT+CMGL={(int)smsStatus}"; - AtResponse response = await channel.SendMultilineCommand(command, null); + AtResponse response = await channel.SendMultilineCommand(command, null).ConfigureAwait(false); List smss = new List(); if (response.Success) @@ -446,7 +446,7 @@ public virtual async Task>> ListSmssAsync(SmsSt public virtual async Task DeleteSmsAsync(int index) { - AtResponse response = await channel.SendCommand($"AT+CMGD={index}"); + AtResponse response = await channel.SendCommand($"AT+CMGD={index}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -461,7 +461,7 @@ public virtual async Task DeleteSmsAsync(int index) public virtual async Task> GetSimStatusAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT+CPIN?", "+CPIN:", TimeSpan.FromSeconds(10)); + AtResponse response = await channel.SendSingleLineCommandAsync("AT+CPIN?", "+CPIN:", TimeSpan.FromSeconds(10)).ConfigureAwait(false); if (!response.Success) { @@ -491,7 +491,7 @@ public virtual async Task> GetSimStatusAsync() public virtual async Task EnterSimPinAsync(PersonalIdentificationNumber pin) { - AtResponse response = await channel.SendCommand($"AT+CPIN={pin}"); + AtResponse response = await channel.SendCommand($"AT+CPIN={pin}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -502,7 +502,7 @@ public virtual async Task EnterSimPinAsync(PersonalIdentification public virtual async Task> GetSignalStrengthAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT+CSQ", "+CSQ:"); + AtResponse response = await channel.SendSingleLineCommandAsync("AT+CSQ", "+CSQ:").ConfigureAwait(false); if (response.Success) { @@ -522,7 +522,7 @@ public virtual async Task> GetSignalStrengthAsync( public virtual async Task> GetBatteryStatusAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT+CBC", "+CBC:"); + AtResponse response = await channel.SendSingleLineCommandAsync("AT+CBC", "+CBC:").ConfigureAwait(false); if (response.Success) { @@ -547,7 +547,7 @@ public virtual async Task SetDateTimeAsync(DateTimeOffset value) sb.Append(value.ToString(@"yy/MM/dd,HH:mm:ss", CultureInfo.InvariantCulture)); sb.Append(offsetQuarters.ToString("+00;-#", CultureInfo.InvariantCulture)); sb.Append("\""); - AtResponse response = await channel.SendCommand(sb.ToString()); + AtResponse response = await channel.SendCommand(sb.ToString()).ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -558,7 +558,7 @@ public virtual async Task SetDateTimeAsync(DateTimeOffset value) public virtual async Task> GetDateTimeAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT+CCLK?", "+CCLK:"); + AtResponse response = await channel.SendSingleLineCommandAsync("AT+CCLK?", "+CCLK:").ConfigureAwait(false); if (response.Success) { @@ -591,7 +591,7 @@ public virtual async Task> GetDateTimeAsync() public virtual async Task SendUssdAsync(string code, int codingScheme = 15) { - AtResponse response = await channel.SendCommand($"AT+CUSD=1,\"{code}\",{codingScheme}"); + AtResponse response = await channel.SendCommand($"AT+CUSD=1,\"{code}\",{codingScheme}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -603,7 +603,7 @@ public virtual async Task SendUssdAsync(string code, int codingSc public virtual async Task SetErrorFormatAsync(int errorFormat) { - AtResponse response = await channel.SendCommand($"AT+CMEE={errorFormat}"); + AtResponse response = await channel.SendCommand($"AT+CMEE={errorFormat}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -614,7 +614,7 @@ public virtual async Task SetErrorFormatAsync(int errorFormat) public virtual async Task ShowSmsTextModeParametersAsync(bool activate) { - AtResponse response = await channel.SendCommand($"AT+CSDH={(activate ? "1" : "0")}"); + AtResponse response = await channel.SendCommand($"AT+CSDH={(activate ? "1" : "0")}").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -625,7 +625,7 @@ public virtual async Task ShowSmsTextModeParametersAsync(bool act public virtual async Task ResetToFactoryDefaultsAsync() { - AtResponse response = await channel.SendCommand($"AT&F"); + AtResponse response = await channel.SendCommand($"AT&F").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -636,7 +636,7 @@ public virtual async Task ResetToFactoryDefaultsAsync() public virtual async Task RawCommandAsync(string command) { - AtResponse response = await channel.SendCommand(command); + AtResponse response = await channel.SendCommand(command).ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -647,7 +647,7 @@ public virtual async Task RawCommandAsync(string command) public virtual async Task>> RawCommandWithResponseAsync(string command, string responsePrefix) { - AtResponse response = await channel.SendSingleLineCommandAsync(command, responsePrefix); + AtResponse response = await channel.SendSingleLineCommandAsync(command, responsePrefix).ConfigureAwait(false); if (response.Success) return ModemResponse.IsResultSuccess(response.Intermediates); @@ -658,9 +658,9 @@ public virtual async Task>> RawCommandWithResponseAsy public virtual async Task RestoreUserSettingsAsync() { - AtResponse response = await channel.SendCommand("ATZ0"); + AtResponse response = await channel.SendCommand("ATZ0").ConfigureAwait(false); - await Task.Delay(TimeSpan.FromMilliseconds(300)); + await Task.Delay(TimeSpan.FromMilliseconds(300)).ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -671,7 +671,7 @@ public virtual async Task RestoreUserSettingsAsync() public virtual async Task SaveUserSettingsAsync() { - AtResponse response = await channel.SendCommand("AT&W0"); + AtResponse response = await channel.SendCommand("AT&W0").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); @@ -682,7 +682,7 @@ public virtual async Task SaveUserSettingsAsync() public virtual async Task ResetUserSettingsAsync() { - AtResponse response = await channel.SendCommand("AT&F0"); + AtResponse response = await channel.SendCommand("AT&F0").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); diff --git a/src/HeboTech.ATLib.Modems/SIMCOM/SIM5320.cs b/src/HeboTech.ATLib.Modems/SIMCOM/SIM5320.cs index d5e8033..694aa9b 100644 --- a/src/HeboTech.ATLib.Modems/SIMCOM/SIM5320.cs +++ b/src/HeboTech.ATLib.Modems/SIMCOM/SIM5320.cs @@ -20,7 +20,7 @@ public SIM5320(IAtChannel channel) #region Custom public virtual async Task GetRemainingPinPukAttemptsAsync() { - AtResponse response = await channel.SendSingleLineCommandAsync("AT+SPIC", "+SPIC:"); + AtResponse response = await channel.SendSingleLineCommandAsync("AT+SPIC", "+SPIC:").ConfigureAwait(false); if (response.Success) { @@ -50,7 +50,7 @@ public override async Task>> ListSmssAsync(SmsS { string command = $"AT+CMGL={(int)smsStatus}"; - AtResponse response = await channel.SendMultilineCommand(command, null); + AtResponse response = await channel.SendMultilineCommand(command, null).ConfigureAwait(false); List smss = new List(); if (response.Success) @@ -82,7 +82,7 @@ public override async Task>> ListSmssAsync(SmsS public virtual async Task ReInitializeSimAsync() { - AtResponse response = await channel.SendCommand($"AT+CRFSIM"); + AtResponse response = await channel.SendCommand($"AT+CRFSIM").ConfigureAwait(false); if (response.Success) return ModemResponse.IsSuccess(); diff --git a/src/HeboTech.ATLib.Modems/Telit/ME910C1.cs b/src/HeboTech.ATLib.Modems/Telit/ME910C1.cs index 0c3140d..7c6b208 100644 --- a/src/HeboTech.ATLib.Modems/Telit/ME910C1.cs +++ b/src/HeboTech.ATLib.Modems/Telit/ME910C1.cs @@ -18,15 +18,15 @@ public ME910C1(IAtChannel channel) public override async Task SetRequiredSettingsBeforePinAsync() { - ModemResponse echo = await DisableEchoAsync(); - ModemResponse errorFormat = await SetErrorFormatAsync(1); + ModemResponse echo = await DisableEchoAsync().ConfigureAwait(false); + ModemResponse errorFormat = await SetErrorFormatAsync(1).ConfigureAwait(false); return echo.Success && errorFormat.Success; } public override async Task SetRequiredSettingsAfterPinAsync() { - ModemResponse currentCharacterSet = await SetCharacterSetAsync(CharacterSet.UCS2); - ModemResponse smsMessageFormat = await SetSmsMessageFormatAsync(SmsTextFormat.PDU); + ModemResponse currentCharacterSet = await SetCharacterSetAsync(CharacterSet.UCS2).ConfigureAwait(false); + ModemResponse smsMessageFormat = await SetSmsMessageFormatAsync(SmsTextFormat.PDU).ConfigureAwait(false); return currentCharacterSet.Success && smsMessageFormat.Success; } From aeddea22bf1a8c937e3a6aa497b147a0fa9c5c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Bj=C3=B8rgo?= Date: Sun, 15 Dec 2024 16:22:00 +0100 Subject: [PATCH 3/4] Revert test function --- src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs b/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs index 71b617b..46f6436 100644 --- a/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs +++ b/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs @@ -40,9 +40,8 @@ public static async Task RunAsync(System.IO.Stream stream, string pin) { using AtChannel atChannel = AtChannel.Create(stream); atChannel.EnableDebug(Log); - using IFona3G modem = new Fona3G(atChannel); //using IMC55i modem = new MC55i(atChannel); - //using IDWM222 modem = new DWM222(atChannel); + using IDWM222 modem = new DWM222(atChannel); atChannel.Open(); await atChannel.ClearAsync(); From ce0a49724d0e2929f69da0df28d20ff462e334e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Bj=C3=B8rgo?= Date: Sun, 15 Dec 2024 16:22:20 +0100 Subject: [PATCH 4/4] Revert test function --- src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs b/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs index 46f6436..6732add 100644 --- a/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs +++ b/src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading.Tasks; using HeboTech.ATLib.Modems.Cinterion; -using HeboTech.ATLib.Modems.Adafruit; namespace HeboTech.ATLib.TestConsole {