public async Task SendAsync(SPPMessage msg) { if (!IsConnected) { OnBluetoothError(new BluetoothException(BluetoothException.ErrorCodes.SendFailed, "Attempted to send command to disconnected device")); return; } try { Log.Verbose($"<< Outgoing: {msg}"); foreach (var hook in ScriptManager.Instance.MessageHooks) { hook?.OnMessageSend(ref msg); } var raw = msg.EncodeMessage(); foreach (var hook in ScriptManager.Instance.RawStreamHooks) { hook?.OnRawDataSend(ref raw); } await _backend.SendAsync(raw); } catch (BluetoothException ex) { OnBluetoothError(ex); } }