private async void ConnToggleButton_Click(object sender, RoutedEventArgs e) { ConnToggleButton.IsEnabled = false; if (ConnToggleButton.Content as string == "Disconnect") { if (_client != null) { await _client.Disconnect(); _client = null; devControl.Reset(); } ConnToggleButton.Content = "Connect"; AdressTextBox.IsEnabled = true; } else { ConnToggleButton.Content = "Disconnect"; AdressTextBox.IsEnabled = false; if (_client == null) { devControl.Reset(); _client = new ButtplugWSClient("Example Client"); _client.DeviceAdded += OnDeviceChanged; _client.DeviceRemoved += OnDeviceChanged; _client.ErrorReceived += OnError; Connect(); } } ConnToggleButton.IsEnabled = true; }
private void OnError(object sender, ErrorEventArgs e) { MessageBox.Show(e.Message.ErrorMessage, "Error"); if (_client?.IsConnected ?? false) { // Disconnect the client as we failed connecting Task.Run(async() => { await _client.Disconnect(); }); } _client = null; }
private void InitClient() { // Set name to connect with _client = new ButtplugWSClient("Test client"); // Bind eventhandlers _client.DeviceAdded += OnDeviceChanged; _client.DeviceRemoved += OnDeviceChanged; _client.ErrorReceived += OnError; Connect(); }
public ItemsPage() { InitializeComponent(); BindingContext = viewModel = new ItemsViewModel(); _client = new ButtplugWSClient("Xamarin test"); _client.DeviceAdded += async(s, a) => { await Navigation.PushModalAsync(new NavigationPage(new NewItemPage(a.Device))); }; _client.Connect(new Uri("wss://192.168.0.8/b******g"), true).Wait(); _client.StartScanning().Wait(); }
private void OnError(object sender, ErrorEventArgs e) { Dispatcher.Invoke(async() => { MessageBox.Show(e.Message.ErrorMessage, "Error"); if (_client.IsConnected) { await _client.Disconnect(); } _client = null; ConnToggleButton.Content = "Connect"; AdressTextBox.IsEnabled = true; }); }
/// <summary> /// Initialize the B******g Client and Connect /// Use async to not block Rendering /// </summary> async void Start() { //Initialize your Client and give it any fitting name, we'll call it Unity Client _bpClient = new ButtplugWSClient("Unity Client"); //Try to connect to the B******g Server await _bpClient.Connect(new Uri(ConnectionUrl)); //Get all connected Devices await _bpClient.RequestDeviceList(); //Scan for Devices await _bpClient.StartScanning(); }
public async Task <bool> Connect() { try { var client = new ButtplugWSClient("ScriptPlayer"); client.DeviceAdded += Client_DeviceAddedOrRemoved; client.DeviceRemoved += Client_DeviceAddedOrRemoved; await client.Connect(new Uri(_url)); _client = client; Devices = (await GetDeviceList()).ToList(); return(true); } catch (Exception) { _client = null; return(false); } }
public async Task <bool> Connect() { try { var client = new ButtplugWSClient("ScriptPlayer"); client.DeviceAdded += Client_DeviceAddedOrRemoved; client.DeviceRemoved += Client_DeviceAddedOrRemoved; await client.Connect(new Uri(_url)); _client = client; return(true); } catch (Exception e) { Debug.WriteLine(e.Message); File.AppendAllText(Environment.ExpandEnvironmentVariables("%APPDATA%\\ScriptPlayer\\ButtplugConnectionError.log"), ExceptionHelper.BuildException(e)); _client = null; return(false); } }
// Gets invoked on every graphic update. public void OnUpdate() { // Reload config if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.R)) { OnApplicationStart(); } // Open and close the serial port connection when Control+K is pressed on the keyboard if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.K)) { try { if (serialPort?.IsOpen == true) { // Close the serial port connection var portName = serialPort.PortName; serialPort.Close(); serialPort = null; Console.WriteLine($"Serial port {portName} is closed."); } else { // Open the serial port connection serialPort = new SerialPort(serialPortName, serialPortBaudRate); serialPort.Open(); Console.WriteLine($"Serial port {serialPort.PortName} is {(serialPort.IsOpen ? "open":"closed")}."); } } catch (Exception e) { Console.WriteLine($"Error: {e}"); } } // Open and close the serial port connection when Control+K is pressed on the keyboard if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.I)) { try { if (bpClient?.IsConnected == true) { // Close the serial port connection bpClient.Disconnect(); bpClient = null; Console.WriteLine("BP connection is closed."); } else { // Open the serial port connection bpClient = new ButtplugWSClient($"{Name} {Version}"); bpClient.Connect(new Uri(buttplugUrl), true); Console.WriteLine($"Connected to B******g ser at {buttplugUrl}"); if (bpClient.StartScanning().Result) { Console.WriteLine("B******g Scanning started"); } bpClient.ErrorReceived += (sender, args) => Console.WriteLine($"B******g Error: {args.Message}\n{args.Exception}"); bpClient.Log += (sender, args) => Console.WriteLine($"B******g Event: {args.Message}"); } } catch (Exception e) { Console.WriteLine($"B******g Error: {e}"); } } // Cycle the female index value based on available female chara in the current scene when Control+C is pressed on the keyboard if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.C)) { if (femaleIndex + 1 < femaleCount) { femaleIndex++; } else { femaleIndex = 0; } if (femaleIndex >= femaleCount) { femaleIndex = 0; } if (charaDiagnostics >= (int)CharDiagLevel.BASIC) { Console.WriteLine($"Female chara Index: {femaleIndex} of {femaleCount}"); } } // Handles the case when the number of female chara's in the current scene changes if (femaleIndex >= femaleCount) { femaleIndex = 0; } // Cycle the male index value based on available male chara in the current scene when Shift+C is pressed on the keyboard if ((Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) && Input.GetKeyDown(KeyCode.C)) { if (maleIndex + 1 < maleCount) { maleIndex++; } else { maleIndex = 0; } if (maleIndex >= maleCount) { maleIndex = 0; } if (charaDiagnostics >= (int)CharDiagLevel.BASIC) { Console.WriteLine($"Male chara Index: {maleIndex} of {maleCount}"); } } // Handles the case when the number of male chara's in the current scene changes if (maleIndex >= maleCount) { maleIndex = 0; } // Get ms elapsed since current stopwatch interval float msElapsed = sw.ElapsedMilliseconds; // If the ms elapsed is greater than the period based on the robot's update frequency then // stop the stopwatch, call the robot update function, and restart the stopwatch if (msElapsed < robotUpdateFrequency) { return; } sw.Stop(); if (configDiagnostics) { Console.WriteLine($"Time taken: {msElapsed}ms, Frequency: {msElapsed/1000}Hz"); } UpdatePositions(); sw = Stopwatch.StartNew(); }