public void Add() { var repo = new DeviceRepository(); var device = DeviceFactory.CreateDevice("OldCamera", "old camera"); Assert.Equal(device, repo.Add(device)); }
private void CreateDevices(List <dynamic> configs) { foreach (var deviceConfig in configs) { DeviceBase device; try { DeviceCreationInfo info = new DeviceCreationInfo(deviceConfig, mServiceManager, mDeviceManager); device = DeviceFactory.CreateDevice(info); mDeviceManager.AddDevice(device); } catch (Exception e) { Log.Error("Failed creating device for node with config: " + deviceConfig.name); if (e.InnerException != null) { Log.Error("Inner Exception: {0}\nCallstack:\n{1}", e.InnerException.Message, e.InnerException.StackTrace); } else { Log.Error("Exception: {0}\nCallstack:\n{1}", e.Message, e.StackTrace); } continue; } Log.Info("Created device: {0} of type: {1}", device.Name, device.GetType().ToString()); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { this.UCChannelStationDTOne1.IsSelectOneStation = true; MasterPageHelper.SetTitle(this, "水位修改"); this.UCChannelStationDTOne1.QueryEvent += new EventHandler(UCChannelStationDTOne1_QueryEvent); if (!IsPostBack) { if (GetQueryParams()) { this.Device = DeviceFactory.CreateDevice(_queryDeviceID); StationClass station = this.Device.StationClass; this.UCChannelStationDTOne1.SelectedChannel = station.Channel; this.UCChannelStationDTOne1.SelectedStation = station; DateTime begin = _queryDateTime.Date; DateTime end = begin.Add(TimeSpan.FromDays(1d)); QueryData(_queryDeviceID, begin, end); } } else { //this.Device = this.UCChannelStationDTOne1.SelectedStation.DeviceCollection[0]; } }
private void saveBtn_Click(object sender, EventArgs e) { var selectedDevice = (DeviceModel)(allDevicesCb.SelectedItem); var storageModel = (DataStorageConfigModel)fileTypeSelectionCb.SelectedItem; var operatorModel = (OperatorModel)operatorsCb.SelectedItem; var facilityModel = (FacilityModel)facilitiesCb.SelectedItem; var activeChannels = GetActiveChannels(); var configBox = (IDeviceConfigControl)deviceSettingsContainer.Controls[0]; var devConfig = configBox.GetDeviceConfig(); if (devConfig != null && selectedDevice != null && storageModel != null) { this.DialogResult = DialogResult.OK; currentDevice = DeviceFactory.CreateDevice(selectedDevice); var devInterface = PeripheralFactory.CreatePeripheral(devConfig); var dataWriter = DataWriterFactory.CreateDataWriter(fileNameTb.Text, storageModel.Type); var errorHandler = new FileErrorHandler("application_errors.txt"); dataWriter.create(); dataWriter.open(); dataWriter.writeHeader(activeChannels, operatorModel, facilityModel); dataWriter.close(); currentDevice.SetDataWriter(dataWriter); currentDevice.SetPeripheralInterface(devInterface); currentDevice.SetErrorHandler(errorHandler); this.Close(); } }
public DeviceBase CreateDevice(dynamic deviceConfiguration) { var info = new DeviceCreationInfo(deviceConfiguration, ServiceManager, DeviceManager); var device = DeviceFactory.CreateDevice(info); DeviceManager.AddDevice(device); return(device); }
/// <summary> /// /// </summary> /// <returns></returns> private DeviceClass GetDevice() { if (IsAdd()) { int deviceid = GetDeviceID(); return(DeviceFactory.CreateDevice(deviceid)); } return(null); }
public void GetNotExistedDevice() { var repo = new DeviceRepository(); //add one var oldDevice = DeviceFactory.CreateDevice("OldCamera", "old camera"); repo.Add(oldDevice); Assert.Null(repo.Get("somethingNotExisted")); }
public void Get(string type, string name) { //add one first var repo = new DeviceRepository(); var device = DeviceFactory.CreateDevice(type, name); repo.Add(device); //get it Assert.Equal(device, repo.Get(name)); }
public void CreateDevice() { var title = "Test device"; var providerName = "Test provider"; var deviceNumber = 0; var device = DeviceFactory.CreateDevice(title, providerName, deviceNumber.ToString(), deviceNumber); Assert.That(device.Title, Is.EqualTo(title)); Assert.That(device.ProviderName, Is.EqualTo(providerName)); Assert.That(device.DeviceHandle, Is.EqualTo(deviceNumber.ToString())); }
public void AddDuplicateName() { var repo = new DeviceRepository(); //add old one var oldDevice = DeviceFactory.CreateDevice("OldCamera", "old camera"); repo.Add(oldDevice); //make a new one with duplicate name should replace the old one var newDevice = DeviceFactory.CreateDevice("NewCamera", "old camera"); Assert.Equal(newDevice, repo.Add(newDevice)); }
public void ShouldCreateAWaterMeter() { var form = new DeviceForm { Type = DeviceType.WATER_METER, ID = "42", SerialNumber = "42", FirmwareVersion = "1.0", State = "Connected" }; var actual = deviceFactoryUT.CreateDevice(form); Assert.That(actual, Is.InstanceOf <WaterMeter>()); var actualDevice = actual as WaterMeter; Assert.That(actualDevice.ID, Is.EqualTo(form.ID)); Assert.That(actualDevice.SerialNumber, Is.EqualTo(form.SerialNumber)); Assert.That(actualDevice.FirmwareVersion, Is.EqualTo(form.FirmwareVersion)); Assert.That(actualDevice.State, Is.EqualTo(form.State)); }
private void CreateDevices(Device[] devices) { var all = devices.Select(x => DeviceFactory.CreateDevice(this, x)).ToArray(); var grouped = all.ToLookup(x => x.id.Split('_').First()); Devices = grouped.Where(x => x.Count() == 1).Select(x => x.First()) .Concat( grouped.Where(x => x.Count() > 1).Select(x => DeviceFactory.CreateMultiDevice(x)) ) .ToArray(); deviceCache = all.ToDictionary(x => x.id); }
public void RemoveNotExisted() { var repo = new DeviceRepository(); //add one var device = DeviceFactory .CreateDevice("OldCamera", "old camera"); repo.Add(device); //remove repo.Remove("nameNotExisted"); Assert.Single(repo.GetAll()); }
public void CreateOldCamera() { var device = DeviceFactory.CreateDevice("OldCamera", "my old camera"); var camera = new OldCamera("my old camera", new OldCameraCommChannel()); //check name Assert.Equal(camera.Name, device.Name); //check type Assert.Equal(camera.GetType(), device.GetType()); //check status Assert.Equal(camera.CheckStatus(), device.CheckStatus()); //check Connection Assert.Equal(camera.CheckConnection(), device.CheckConnection()); }
public void CreateRocketLauncher() { var device = DeviceFactory.CreateDevice("RocketLauncher", "my RocketLauncher"); var launcher = new RocketLauncher("my RocketLauncher", new RocketLauncherCommChannel()); //check name Assert.Equal(launcher.Name, device.Name); //check type Assert.Equal(launcher.GetType(), device.GetType()); //check status Assert.Equal(launcher.CheckStatus(), device.CheckStatus()); //check Connection Assert.Equal(launcher.CheckConnection(), device.CheckConnection()); }
public void Remove(string type, string name) { var repo = new DeviceRepository(); //add one var device = DeviceFactory .CreateDevice(type, name); repo.Add(device); //remove repo.Remove(name); Assert.Empty(repo.GetAll()); }
/// <summary> Connects a device. </summary> /// <param name="serialNo"> The serial no. </param> private void ConnectDevice(string serialNo) { // unload device if not desired type if (_genericDevice != null) { if (_genericDevice.CoreDevice.DeviceID == serialNo) { return; } DisconnectDevice(); } // create new device IGenericCoreDeviceCLI device = DeviceFactory.CreateDevice(serialNo); GenericDeviceHolder devices = new GenericDeviceHolder(device); _genericDevice = devices[1]; if (_genericDevice == null) { MessageBox.Show("Unknown Device Type"); return; } // connect device try { _genericDevice.CoreDevice.Connect(serialNo); // wait for settings to be initialized _genericDevice.Device.WaitForSettingsInitialized(5000); } catch (DeviceException ex) { MessageBox.Show(ex.Message); return; } // create view via factory // get factory IUIFactory factory = DeviceManager.GetUIFactory(_genericDevice.CoreDevice.DeviceID); // create and initialize view model for device IDeviceViewModel viewModel = factory.CreateViewModel(DisplayTypeEnum.Full, _genericDevice); viewModel.Initialize(); // create view and attach to our display _contentControl.Content = factory.CreateLargeView(viewModel); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnOK_Click(object sender, EventArgs e) { DeviceCollection cs = GetInOrOutDeviceCollection(); cs.Clear(); foreach (ListItem li in this.clStation.Items) { if (li.Selected) { int id = Convert.ToInt32(li.Value); DeviceClass device = DeviceFactory.CreateDevice(id); cs.Add(device); } } Redirect(); }
public void GetAll() { var repo = new DeviceRepository(); //add two var oldDevice = DeviceFactory.CreateDevice("OldCamera", "old camera"); var newDevice = DeviceFactory.CreateDevice("NewCamera", "new camera"); repo.Add(oldDevice); repo.Add(newDevice); List <Device> devices = new List <Device> { oldDevice, newDevice }; Assert.Equal(devices, repo.GetAll().ToList()); }
static void Main(string[] args) { TCubeDCServo.RegisterDevice(); KCubeDCServo.RegisterDevice(); // get parameters from command line int argc = args.Count(); if (argc < 1) { Console.WriteLine("Usage = DC_Console_net_managed [serial_no] [position: optional (0 - 50)] [velocity: optional (0 - 5)]"); Console.ReadKey(); return; } decimal position = 0m; if (argc > 1) { position = decimal.Parse(args[1]); } decimal velocity = 0m; if (argc > 2) { velocity = decimal.Parse(args[2]); } string serialNo = args[0]; try { // build device list DeviceManagerCLI.BuildDeviceList(); } catch (Exception ex) { Console.WriteLine("Exception raised by BuildDeviceList {0}", ex); Console.ReadKey(); return; } // get available KCube DC Servos and check our serial number is correct List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(new List <int> { KCubeDCServo.DevicePrefix, TCubeDCServo.DevicePrefix }); if (!serialNumbers.Contains(serialNo)) { if (serialNumbers.Count > 0) { serialNo = serialNumbers[0]; Console.WriteLine("using serial number {0}", serialNo); } else { Console.WriteLine("{0} is not a valid serial number", serialNo); Console.ReadKey(); return; } } // create the device IGenericCoreDeviceCLI device = DeviceFactory.CreateDevice(serialNo); IGenericAdvancedMotor motor = device as IGenericAdvancedMotor; if (motor == null) { Console.WriteLine("{0} is not a DCServo", serialNo); Console.ReadKey(); return; } // connect device try { Console.WriteLine("Opening device {0}", serialNo); device.Connect(serialNo); if (!motor.IsSettingsInitialized()) { motor.WaitForSettingsInitialized(5000); } // display info about device DeviceInfo di = device.GetDeviceInfo(); Console.WriteLine("Device {0} = {1}", di.SerialNumber, di.Name); // start the device polling motor.StartPolling(250); } catch (DeviceException ex) { Console.WriteLine("Failed to open device {0} - {1}", ex.DeviceID, ex.Message); Console.ReadKey(); return; } DeviceUnitConverter deviceUnitConverter; try { // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real unit parameters MotorConfiguration motorSettings = motor.GetMotorConfiguration(serialNo); motorSettings.DeviceSettingsName = "PRM1-Z8"; motorSettings.UpdateCurrentConfiguration(); MotorDeviceSettings motorDeviceSettings = motor.MotorDeviceSettings; motor.SetSettings(motorDeviceSettings, true, false); // test code to test get / sert of parameters using real world units TestVelocityParameters(motor); TestJogParameters(motor); TestHomingParameters(motor); TestLimitParameters(motor); if (device is TCubeDCServo) { TestPotentiometerParameters(device as TCubeDCServo); // TDC Only } motorSettings.UpdateCurrentConfiguration(); deviceUnitConverter = motor.UnitConverter; } catch (DeviceException ex) { Console.WriteLine("Failed prepare settings {0} - {1}", ex.DeviceID, ex.Message); Console.ReadKey(); return; } try { if (!Home_1(motor)) { Console.WriteLine("Failed to home device"); Console.ReadKey(); return; } } catch (DeviceException ex) { Console.WriteLine("Failed to Home device settings {0} - {1}", ex.DeviceID, ex.Message); Console.ReadKey(); return; } try { // if position is set if (position != 0) { // update velocity if required using real world methods if (velocity != 0) { VelocityParameters velPars = motor.GetVelocityParams(); velPars.MaxVelocity = velocity; motor.SetVelocityParams(velPars); } if (!MoveTo_1(motor, position, deviceUnitConverter)) { Console.WriteLine("Failed to set position"); Console.ReadKey(); } } else { char c = '\0'; do { do { Console.WriteLine("Press a key"); Console.WriteLine("0 to exit"); Console.WriteLine("1 to test StopImmediate()"); Console.WriteLine("2 to test Stop(5000)"); Console.WriteLine("3 to test Stop(WaitEvent)"); c = Console.ReadKey().KeyChar; } while (c < '0' || c > '3'); if (c != '0') { motor.MoveContinuous(MotorDirection.Forward); Console.WriteLine("Press any key to stop"); Console.ReadKey(); StatusBase status; if (c == '1') { motor.Stop(5000); } if (c == '2') { motor.StopImmediate(); } if (c == '3') { ManualResetEvent waitEvent = new ManualResetEvent(false); waitEvent.Reset(); motor.Stop(p => { Console.WriteLine("Message Id {0}", p); waitEvent.Set(); }); if (!waitEvent.WaitOne(5000)) { Console.WriteLine("Failed to Stop"); } } do { status = motor.Status; Console.WriteLine("Status says {0} ({1:X})", status.IsInMotion ? "Moving" : "Stopped", status.Status); Thread.Sleep(50); } while (status.IsInMotion); } } while (c != '0'); } } catch (DeviceException ex) { Console.WriteLine("Failed to Move device settings {0} - {1}", ex.DeviceID, ex.Message); Console.ReadKey(); return; } try { device.Disconnect(true); } catch (DeviceException ex) { Console.WriteLine("Failed to Disconnect {0} - {1}", ex.DeviceID, ex.Message); } Console.ReadKey(); }
public void SetDevice(DeviceType device) { _device = DeviceFactory.CreateDevice(device); }
public void CreateInvalidType() { var device = DeviceFactory.CreateDevice("SomeWieldThing", "my RocketLauncher"); Assert.Null(device); }
private XBeeNode CreateNode(HardwareVersion hardwareVersion, ushort firmwareVersion, NodeAddress address = null) { return(DeviceFactory.CreateDevice(hardwareVersion, firmwareVersion, address, this)); }
private void CreateDevices(Device[] devices) { Devices = devices.Select(x => DeviceFactory.CreateDevice(this, x)).ToArray(); deviceCache = Devices.ToDictionary(x => x.deviceid); }