private async Task ResetDevice() { if (this.vehicle != null) { this.vehicle.Dispose(); this.vehicle = null; } Device device = DeviceFactory.CreateDeviceFromConfigurationSettings(this); if (device == null) { this.deviceDescription.Text = "None selected."; return; } this.deviceDescription.Text = device.ToString(); this.vehicle = new Vehicle(device, new MessageFactory(), new MessageParser(), this); await this.InitializeCurrentDevice(); }
private async void testButton_Click(object sender, EventArgs e) { Device device; if (this.DeviceCategory == Configuration.Constants.DeviceCategorySerial) { device = DeviceFactory.CreateSerialDevice(this.SerialPort, this.SerialPortDeviceType, this.logger); } else if (this.DeviceCategory == Configuration.Constants.DeviceCategoryJ2534) { device = DeviceFactory.CreateJ2534Device(this.J2534DeviceType, this.logger); } else { this.status.Text = "No device specified."; return; } if (device == null) { this.status.Text = "Device not found."; return; } this.status.Text = device.ToString() + " created."; bool initialized = await device.Initialize(); if (initialized) { this.status.Text = device.ToString() + " initialized successfully."; } else { this.status.Text = "Unable to initalize " + device.ToString(); } device.Dispose(); }