public MainWindow() { InitializeComponent(); usb_connection = new HID_Connection(); DataContext = this; superuserAccess = false; greenBrush = new SolidColorBrush(); orangeBrush = new SolidColorBrush(); redBrush = new SolidColorBrush(); grayBrush = new SolidColorBrush(); greenBrush.Color = Color.FromRgb(50, 200, 0); orangeBrush.Color = Color.FromRgb(255, 165, 0); redBrush.Color = Color.FromRgb(255, 0, 0); grayBrush.Color = Color.FromRgb(128, 128, 128); if (OutputBox != null) { outputAdapter = new BSLRichTextBoxOutputBridge(OutputBox); } passwordWindow = null; PasswordBoxCommand.InputGestures.Add(new KeyGesture(Key.W, ModifierKeys.Control)); PasswordCommand.Command = PasswordBoxCommand; RefreshButtonEnabled = true; ReadProgress.Maximum = Registers.adc_registers.Length + Registers.dac_registers.Length + Registers.sel_registers.Length; BaseMode = HEX_MODE; //Hex Mode OnPropertyChanged("RefreshButtonEnabled"); OnPropertyChanged("RefreshButtonVisibility"); }
private async void Connection_Click(object sender, RoutedEventArgs e) { bool currentStatus = connectionStatus; string pidStr = PID_Textbox.Text.ToLower(); string vidStr = VID_Textbox.Text.ToLower(); if (!currentStatus && !(vidStr.Equals("") || pidStr.Equals(""))) { int vid; int pid; if (pidStr.StartsWith("0x")) { pidStr = Convert.ToInt32(pidStr, 16).ToString(); } if (pidStr.StartsWith("0b")) { pidStr = Convert.ToInt32(pidStr.Substring(2), 2).ToString(); } if (vidStr.StartsWith("0x")) { vidStr = Convert.ToInt32(vidStr, 16).ToString(); } if (vidStr.StartsWith("0b")) { vidStr = Convert.ToInt32(vidStr.Substring(2), 2).ToString(); } if (int.TryParse(pidStr, out pid) && int.TryParse(vidStr, out vid)) { usb_connection = new HID_Connection(vid, pid); } else { string messageBoxText = $"Unable to parse VID/PID. Use Default Values?\nVID: {HID_Connection.DefaultVIDString()}\nPID: {HID_Connection.DefaultPIDString()}"; string caption = "Parsing Failed!"; MessageBoxButton button = MessageBoxButton.YesNo; MessageBoxImage icon = MessageBoxImage.Error; MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon); if (result == MessageBoxResult.No) { //do nothing, no connection attempt return; } } } ToggleConnection(currentStatus); OnPropertyChanged("ConnectionText"); OnPropertyChanged("ConnectionStatus"); OnPropertyChanged("SettingsGridVisibility"); if (connectionStatus) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed CheckConnection(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed RefreshButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); //ADC_Registers.ItemsSource = await Task.Run(refreshADCRegisters); //DAC_Registers.ItemsSource = await Task.Run(refreshDACRegisters); //SEL_Registers.ItemsSource = await Task.Run(refreshSELRegisters); } }
private void LoadDefaultFirmware(object sender, RoutedEventArgs e) { #if DEBUG string curDir = Directory.GetCurrentDirectory(); string baseDir = Directory.GetParent(Directory.GetParent(curDir).FullName).FullName; try { System.Diagnostics.Process.Start(curDir + "\\FirmwareInstall.bat", HID_Connection.DefaultVIDString() + " " + HID_Connection.DefaultUninstalledPIDString() + " \"" + curDir + curFirmwareName + "\""); } catch { } #else #endif }
private void LoadCustomFirmware(object sender, RoutedEventArgs e) { #if DEBUG string curDir = Directory.GetCurrentDirectory(); string baseDir = Directory.GetParent(Directory.GetParent(curDir).FullName).FullName; string filePath = string.Empty; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "bin files (*.bin)|*.bin|All files (*.*)|*.*"; bool?result = openFileDialog.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document string bin_filename = openFileDialog.FileName; System.Diagnostics.Process.Start(curDir + "\\FirmwareInstall.bat", HID_Connection.DefaultVIDString() + " " + HID_Connection.DefaultUninstalledPIDString() + " \"" + bin_filename + "\""); } #else #endif }