private void allDevicesCb_SelectedIndexChanged(object sender, EventArgs e) { DeviceModel selectedDevice = ((DeviceModel)(allDevicesCb.SelectedItem)); UserControl devConfigMenu; ListBox tempList = (ListBox)channelsCbList; tempList.DataSource = selectedDevice.Channels; tempList.DisplayMember = "name"; for (int i = 0; i < channelsCbList.Items.Count; i++) { channelsCbList.SetItemChecked(i, true); } deviceSettingsContainer.Controls.Clear(); if (selectedDevice.Interface == DeviceInterface.SERIAL_INTERFACE) { devConfigMenu = new SerialDeviceConfig(dcm); devConfigMenu.Location = new Point(5, 20); deviceSettingsContainer.Controls.Add(devConfigMenu); } else if (selectedDevice.Interface == DeviceInterface.UDP_INTERFACE) { devConfigMenu = new UDPDeviceConfig(dcm); devConfigMenu.Location = new Point(5, 20); deviceSettingsContainer.Controls.Add(devConfigMenu); } else if (selectedDevice.Interface == DeviceInterface.TCP_INTERFACE) { throw new NotImplementedException("TCP INTERFACE NOT Implemented yet"); } }
public DeviceSimulatorTests() { moqSerialConnection = new Mock <ISerialConnection>(); serialConfig = new SerialDeviceConfig { CommPortName = "COM9" }; deviceInformation = new DeviceInformation() { ComPort = "COM9", Manufacturer = "Simulator", Model = "SimCity", SerialNumber = "CEEEDEADBEEF", ProductIdentification = "SIMULATOR", VendorIdentifier = "BADDCACA" }; subject = new DeviceSimulator(); using (IKernel kernel = new StandardKernel()) { kernel.Settings.InjectNonPublic = true; kernel.Settings.InjectParentPrivateProperties = true; kernel.Bind <ISerialConnection>().ToConstant(moqSerialConnection.Object).WithConstructorArgument(deviceInformation); kernel.Inject(subject); } }
public override Task DoWork() { string pluginPath = Controller.PluginPath; List <ICardDevice> availableCardDevices = null; List <ICardDevice> discoveredCardDevices = null; List <ICardDevice> validatedCardDevices = null; try { availableCardDevices = Controller.DevicePluginLoader.FindAvailableDevices(pluginPath); // filter out devices that are disabled if (availableCardDevices.Count > 0) { DeviceSection deviceSection = Controller.Configuration; foreach (var device in availableCardDevices) { switch (device.ManufacturerConfigID) { case "IdTech": { device.SortOrder = deviceSection.IdTech.SortOrder; break; } case "Verifone": { device.SortOrder = deviceSection.Verifone.SortOrder; break; } case "Simulator": { device.SortOrder = deviceSection.Simulator.SortOrder; break; } } } availableCardDevices.RemoveAll(x => x.SortOrder == -1); if (availableCardDevices?.Count > 1) { availableCardDevices.Sort(); } } // Probe validated devices discoveredCardDevices = new List <ICardDevice>(); validatedCardDevices = new List <ICardDevice>(); validatedCardDevices.AddRange(availableCardDevices); for (int i = validatedCardDevices.Count - 1; i >= 0; i--) { if (string.Equals(availableCardDevices[i].ManufacturerConfigID, DeviceType.NoDevice.ToString(), StringComparison.OrdinalIgnoreCase)) { continue; } bool success = false; try { List <DeviceInformation> deviceInformation = availableCardDevices[i].DiscoverDevices(); if (deviceInformation == null) { continue; } foreach (var deviceInfo in deviceInformation) { DeviceConfig deviceConfig = new DeviceConfig() { Valid = true }; SerialDeviceConfig serialConfig = new SerialDeviceConfig { CommPortName = Controller.Configuration.DefaultDevicePort }; deviceConfig.SetSerialDeviceConfig(serialConfig); ICardDevice device = validatedCardDevices[i].Clone() as ICardDevice; device.DeviceEventOccured += Controller.DeviceEventReceived; // Device powered on status capturing: free up the com port and try again. // This occurs when a USB device repowers the USB interface and the virtual port is open. CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); IDeviceCancellationBroker cancellationBroker = Controller.GetCancellationBroker(); var timeoutPolicy = cancellationBroker.ExecuteWithTimeoutAsync <List <LinkErrorValue> >( _ => device.Probe(deviceConfig, deviceInfo, out success), Timeouts.DALGetStatusTimeout, CancellationToken.None); if (timeoutPolicy.Result.Outcome == Polly.OutcomeType.Failure) { Console.WriteLine($"Unable to obtain device status for - '{device.Name}'."); device.DeviceEventOccured -= Controller.DeviceEventReceived; device?.Dispose(); LastException = new StateException("Unable to find a valid device to connect to."); _ = Error(this); return(Task.CompletedTask); } else if (success) { discoveredCardDevices.Add(device); } } } catch (Exception e) { Console.WriteLine($"device: exception='{e.Message}'"); discoveredCardDevices[i].DeviceEventOccured -= Controller.DeviceEventReceived; // Consume failures if (success) { success = false; } } if (success) { continue; } validatedCardDevices.RemoveAt(i); } } catch { availableCardDevices = new List <ICardDevice>(); } if (discoveredCardDevices?.Count > 1) { discoveredCardDevices.Sort(); } if (discoveredCardDevices?.Count > 0) { Controller.SetTargetDevices(discoveredCardDevices); } if (Controller.TargetDevices != null) { foreach (var device in Controller.TargetDevices) { //Controller.LoggingClient.LogInfoAsync($"Device found: name='{device.Name}', model={device.DeviceInformation.Model}, " + // $"serial={device.DeviceInformation.SerialNumber}"); Console.WriteLine($"Device found: name='{device.Name}', model='{device?.DeviceInformation?.Model}', " + $"serial='{device?.DeviceInformation?.SerialNumber}'"); device.DeviceSetIdle(); } } else { //Controller.LoggingClient.LogInfoAsync("Unable to find a valid device to connect to."); Console.WriteLine("Unable to find a valid device to connect to."); LastException = new StateException("Unable to find a valid device to connect to."); _ = Error(this); return(Task.CompletedTask); } _ = Complete(this); return(Task.CompletedTask); }