public void ScanInputs(NodeDriver driver) { foreach (var device in driver.NodeDeviceChildren.Items) { kickOffBackgroundRequestIfNecessary(device); switch (device.TypeId.ToString()) { case UserStatusMonitor.TYPE_ID: NodeStringInput latestStatus = device.NodeStringInputChildren.Items[0]; var statuses = deviceState.GetUserStatusMonitor(device); var oldStatus = latestStatus.Value; if (statuses.Count > 0) { latestStatus.Value = statuses[0].Text; } else { latestStatus.Value = string.Empty; } NodeDiscreteInput statusChanged = device.NodeDiscreteInputChildren.Items[0]; statusChanged.Value = oldStatus != latestStatus.Value; break; } } }
public void ScanOutputs(NodeDriver driver, NodeRuntimeApplication runtimeApplication) { // No outputs yet //foreach (var device in driver.NodeDeviceChildren.Items) //{ //} }
// BE CAREFUL! RUNS ON A SEPARATE THREAD! public NodeDriver ReadConfiguration() { var driver = NodeDriver.BuildWith( new FieldGuid(SnapDriver.TWITTER_DRIVER_ID), // TypeId new FieldString(string.Empty), // Address new FieldBase64(string.Empty), // Configuration new FieldString(Resources.Strings.DriverName)); // DriverName driver = driver.SetRunning(new FieldBool(Running)); // status only if (Running) // Running property is threadsafe { var devicesMutable = new Collection <NodeDevice>(); driver = driver.NodeDeviceChildren.Append( new ReadOnlyCollection <NodeDevice>(devicesMutable)); } return(driver); }
public void ScanInputs(NodeDriver driver) { if (this.directInput == null) { return; } foreach (var device in driver.NodeDeviceChildren) { switch (device.TypeId.ToString()) { case JoystickDevice.TYPE_ID: scanJoystickInputs(device); break; } } }
public void ScanInputs(NodeDriver driver) { foreach (var device in driver.NodeDeviceChildren.Items) { if (device.Address.ToString() != string.Empty) { switch (device.Code.ToString()) { case Phidget_InterfaceKit_488.CODE: case Phidget_InterfaceKit_888.CODE: case Phidget_InterfaceKit_0_16_16.CODE: var ifKit = OpenInterfaceKit(device); if (ifKit.Attached) { for (int i = 0; i < ifKit.inputs.Count; i++) { foreach (var input in device.NodeDiscreteInputChildren.Items) { if (Int32.Parse(input.Address.ToString()) == i) { input.Value = ifKit.inputs[i]; } } } for (int i = 0; i < ifKit.sensors.Count; i++) { foreach (var input in device.NodeAnalogInputChildren.Items) { if (Int32.Parse(input.Address.ToString()) == i) { input.Value = ifKit.sensors[i].Value; } } } } break; } } } }
// BE CAREFUL! RUNS ON A SEPARATE THREAD! public NodeDriver ReadConfiguration() { var driver = NodeDriver.BuildWith( new FieldGuid(SnapDriver.GAMECONTROLLERS_DRIVER_ID), // TypeId new FieldString(string.Empty), // Address new FieldBase64(string.Empty), // Configuration new FieldString(Resources.Strings.DriverName)); // DriverName driver = driver.SetRunning(new FieldBool(Running)); // status only if (Running && this.directInput != null) // Running property is threadsafe { var devicesMutable = new Collection <NodeDevice>(); var joystickDevices = getJoystickCompatibleDevices(); foreach (var joystickDevice in joystickDevices) { var dev = JoystickDevice.StaticBuild(this.directInput, joystickDevice); devicesMutable.Add(dev); } driver = driver.NodeDeviceChildren.Append( new ReadOnlyCollection <NodeDevice>(devicesMutable)); } return(driver); }
// BE CAREFUL! RUNS ON A SEPARATE THREAD! public NodeDriver ReadConfiguration() { var driver = NodeDriver.BuildWith( new FieldGuid(SnapDriver.PHIDGETS_DRIVER_ID), // TypeId new FieldString(string.Empty), // Address new FieldBase64(string.Empty), // Configuration new FieldString(Resources.Strings.DriverName)); // DriverName driver = driver.SetRunning(new FieldBool(Running)); // status only if (Running) // Running property is threadsafe { var devicesMutable = new Collection <NodeDevice>(); // Phidgets claims to be a threadsafe library, // and manager is readonly foreach (Phidget phidget in manager.Devices) { var dev = new PhidgetsDevice(phidget); devicesMutable.Add(dev.Device); } driver = driver.NodeDeviceChildren.Append( new ReadOnlyCollection <NodeDevice>(devicesMutable)); } return(driver); }
public LinodeNode(string id, string name, NodeState state, List<IPAddress> public_ips, List<IPAddress> private_ips, NodeDriver driver) : base(id, name, state, public_ips, private_ips, driver) { }
internal static NodeDeviceConfiguration MergeDeviceConfiguration( DeviceConfigurationResponse deviceConfigurationResponse, NodeDeviceConfiguration existingDeviceConfiguration = null) { var driversMutable = new Collection <NodeDriver>(); var nodeDriver = NodeDriver.BuildWith( new FieldGuid(SnapDriver.ARDUINO_LOCAL_IO_DRIVER_TYPE_ID), // TypeId new FieldString(string.Empty), // Address FieldBase64.Encode(string.Empty), // Configuration new FieldString(deviceConfigurationResponse.DeviceName)); var devicesMutable = new Collection <NodeDevice>(); // Just creating 4 "virtual" devices under the Arduino Local I/O driver // so that it looks organized in the Solution Explorer var discreteInputsDevice = NodeDevice.BuildWith( new FieldIdentifier("DiscreteInputs"), // Code new FieldGuid(DISCRETE_INPUTS_DEVICE_ID), // TypeId new FieldString(), // Address new FieldBase64(string.Empty), // Configuration new FieldDeviceName("Discrete Inputs")); var discreteOutputsDevice = NodeDevice.BuildWith( new FieldIdentifier("DiscreteOutputs"), // Code new FieldGuid(DISCRETE_OUTPUTS_DEVICE_ID), // TypeId new FieldString(), // Address new FieldBase64(string.Empty), // Configuration new FieldDeviceName("Discrete Outputs")); var analogInputsDevice = NodeDevice.BuildWith( new FieldIdentifier("AnalogInputs"), // Code new FieldGuid(ANALOG_INPUTS_DEVICE_ID), // TypeId new FieldString(), // Address new FieldBase64(string.Empty), // Configuration new FieldDeviceName("Analog Inputs")); var analogOutputsDevice = NodeDevice.BuildWith( new FieldIdentifier("AnalogOutputs"), // Code new FieldGuid(ANALOG_OUTPUTS_DEVICE_ID), // TypeId new FieldString(), // Address new FieldBase64(string.Empty), // Configuration new FieldDeviceName("Analog Outputs")); var discreteInputsMutable = new Collection <NodeDiscreteInput>(); var discreteOutputsMutable = new Collection <NodeDiscreteOutput>(); var analogInputsMutable = new Collection <NodeAnalogInput>(); var analogOutputsMutable = new Collection <NodeAnalogOutput>(); foreach (var ioSignal in deviceConfigurationResponse.IOSignals) { switch (ioSignal.Type) { case DeviceConfigurationResponse.IOSignalType.DiscreteInput: var newDiscreteInput = NodeDiscreteInput.BuildWith( new FieldIdentifier(ioSignal.Name), new FieldString(ioSignal.Address), new FieldSignalName(ioSignal.Name)); if (existingDeviceConfiguration != null) { var existingDiscreteInput = existingDeviceConfiguration.GetChildrenRecursive() .Select(x => x.Value as NodeDiscreteInput) .Where(x => x != null) .Where(x => x.Code.ToString() == ioSignal.Name) .SingleOrDefault(x => x.Address.ToString() == ioSignal.Address); if (existingDiscreteInput != null) { newDiscreteInput = newDiscreteInput .SetSignal(existingDiscreteInput.Signal); } } discreteInputsMutable.Add(newDiscreteInput); break; case DeviceConfigurationResponse.IOSignalType.DiscreteOutput: var newDiscreteOutput = NodeDiscreteOutput.BuildWith( new FieldIdentifier(ioSignal.Name), new FieldString(ioSignal.Address), new FieldSignalName(ioSignal.Name)); if (existingDeviceConfiguration != null) { var existingDiscreteOutput = existingDeviceConfiguration.GetChildrenRecursive() .Select(x => x.Value as NodeDiscreteOutput) .Where(x => x != null) .Where(x => x.Code.ToString() == ioSignal.Name) .SingleOrDefault(x => x.Address.ToString() == ioSignal.Address); if (existingDiscreteOutput != null) { newDiscreteOutput = newDiscreteOutput .SetSignalIn(existingDiscreteOutput.SignalIn); } } discreteOutputsMutable.Add(newDiscreteOutput); break; case DeviceConfigurationResponse.IOSignalType.AnalogInput: var newAnalogInput = NodeAnalogInput.BuildWith( new FieldIdentifier(ioSignal.Name), new FieldString(ioSignal.Address), new FieldSignalName(ioSignal.Name)); if (existingDeviceConfiguration != null) { var existingAnalogInput = existingDeviceConfiguration.GetChildrenRecursive() .Select(x => x.Value as NodeAnalogInput) .Where(x => x != null) .Where(x => x.Code.ToString() == ioSignal.Name) .SingleOrDefault(x => x.Address.ToString() == ioSignal.Address); if (existingAnalogInput != null) { newAnalogInput = newAnalogInput .SetSignal(existingAnalogInput.Signal); } } analogInputsMutable.Add(newAnalogInput); break; case DeviceConfigurationResponse.IOSignalType.AnalogOutput: var newAnalogOutput = NodeAnalogOutput.BuildWith( new FieldIdentifier(ioSignal.Name), new FieldString(ioSignal.Address), new FieldSignalName(ioSignal.Name)); if (existingDeviceConfiguration != null) { var existingAnalogOutput = existingDeviceConfiguration.GetChildrenRecursive() .Select(x => x.Value as NodeAnalogOutput) .Where(x => x != null) .Where(x => x.Code.ToString() == ioSignal.Name) .SingleOrDefault(x => x.Address.ToString() == ioSignal.Address); if (existingAnalogOutput != null) { newAnalogOutput = newAnalogOutput .SetSignalIn(existingAnalogOutput.SignalIn); } } analogOutputsMutable.Add(newAnalogOutput); break; } } discreteInputsDevice = discreteInputsDevice.NodeDiscreteInputChildren.Append( new ReadOnlyCollection <NodeDiscreteInput>(discreteInputsMutable)); discreteOutputsDevice = discreteOutputsDevice.NodeDiscreteOutputChildren.Append( new ReadOnlyCollection <NodeDiscreteOutput>(discreteOutputsMutable)); analogInputsDevice = analogInputsDevice.NodeAnalogInputChildren.Append( new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable)); analogOutputsDevice = analogOutputsDevice.NodeAnalogOutputChildren.Append( new ReadOnlyCollection <NodeAnalogOutput>(analogOutputsMutable)); devicesMutable.Add(discreteInputsDevice); devicesMutable.Add(discreteOutputsDevice); devicesMutable.Add(analogInputsDevice); devicesMutable.Add(analogOutputsDevice); nodeDriver = nodeDriver.NodeDeviceChildren.Append( new ReadOnlyCollection <NodeDevice>(devicesMutable)); driversMutable.Add(nodeDriver); var nodeDeviceConfiguration = NodeDeviceConfiguration.BuildWith( new ReadOnlyCollection <NodeDriver>(driversMutable)); return(nodeDeviceConfiguration); }
public void ScanOutputs(NodeDriver driver, NodeRuntimeApplication runtimeApplication) { }
public DriverItem(ISolutionItem parent, NodeDriver driver) : base(parent, driver.TypeId.ToString()) { Driver = driver; }
public void ScanOutputs(NodeDriver driver, NodeRuntimeApplication runtimeApplication) { foreach (var device in driver.NodeDeviceChildren.Items) { if (device.Address.ToString() != string.Empty) { switch (device.Code.ToString()) { case Phidget_InterfaceKit_004.CODE: case Phidget_InterfaceKit_008.CODE: case Phidget_InterfaceKit_488.CODE: case Phidget_InterfaceKit_888.CODE: case Phidget_InterfaceKit_0_16_16.CODE: var ifKit = OpenInterfaceKit(device); if (ifKit.Attached) { for (int i = 0; i < ifKit.outputs.Count; i++) { foreach (var output in device.NodeDiscreteOutputChildren.Items) { if (Int32.Parse(output.Address.ToString()) == i) { try { ifKit.outputs[i] = output.GetValue(runtimeApplication); } catch { // FIXME - tie in to error reporting mechanism } } } } } break; case Phidget_ServoMotor_1.CODE: case Phidget_ServoMotor_4.CODE: case Phidget_ServoMotor_8.CODE: var mtrControl = OpenServo(device); if (mtrControl.Attached) { for (int i = 0; i < mtrControl.servos.Count; i++) { foreach (var output in device.NodeAnalogOutputChildren.Items) { if (Int32.Parse(output.Address.ToString()) == i) { try { mtrControl.servos[i].Position = Convert.ToDouble(output.GetValue(runtimeApplication)); } catch { // FIXME - tie in to error reporting mechanism } } } } } break; case Phidget_AdvancedServo.CODE: var advServo = OpenAdvancedServo(device); if (advServo.Attached) { for (int i = 0; i < advServo.servos.Count; i++) { var enable = (from o in device.NodeDiscreteOutputChildren.Items where Int32.Parse(o.Address.ToString()) == i select o).FirstOrDefault(); if (enable != null) { try { advServo.servos[i].Engaged = enable.GetValue(runtimeApplication); } catch { // FIXME - tie in to error reporting mechanism } } var output = (from o in device.NodeAnalogOutputChildren.Items where Int32.Parse(o.Address.ToString()) == i select o).FirstOrDefault(); if (output != null) { try { advServo.servos[i].Position = Convert.ToDouble(output.GetValue(runtimeApplication)); } catch { // FIXME - tie in to error reporting mechanism } } } } break; case Phidget_TextLCD_2x20.CODE: var textLCD = OpenTextLCD(device); if (textLCD.Attached) { for (int i = 0; i < textLCD.rows.Count; i++) { foreach (var output in device.NodeStringOutputChildren.Items) { if (Int32.Parse(output.Address.ToString()) == i) { var text = output.GetValue(runtimeApplication); if (text.Length > textLCD.rows[i].MaximumLength) { text = text.Substring(0, textLCD.rows[i].MaximumLength); } try { textLCD.rows[i].DisplayString = text; } catch { // FIXME - tie in to error reporting mechanism } } } } } break; } } } }