Exemplo n.º 1
0
        public static NodeDevice StaticBuild()
        {
            FieldIdentifier code;
            FieldGuid       typeId;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName deviceName;

            code          = new FieldIdentifier(CODE);
            typeId        = new FieldGuid(TYPE_ID);
            address       = new FieldString(string.Empty);
            configuration = new FieldBase64(string.Empty);
            deviceName    = new FieldDeviceName(Resources.Strings.Unknown_Phidget_Name);

            NodeDevice device = NodeDevice.BuildWith(code, typeId, address, configuration, deviceName);

            return(device);
        }
Exemplo n.º 2
0
        public override NodeDevice Build()
        {
            var device = NodeDevice.BuildWith(
                new FieldIdentifier(CODE),
                new FieldGuid(TYPE_ID),
                new FieldString(string.Empty),
                new FieldBase64(string.Empty),
                new FieldDeviceName(this.Name));

            device = device.NodeStringInputChildren.Append(
                NodeStringInput.BuildWith(
                    new FieldIdentifier(STRING_INPUT_0_CODE),
                    new FieldString(string.Empty),
                    new FieldSignalName(Resources.Strings.UserStatusMonitor_StringInput0)));
            device = device.NodeDiscreteInputChildren.Append(
                NodeDiscreteInput.BuildWith(
                    new FieldIdentifier(DISCRETE_INPUT_0_CODE),
                    new FieldString(string.Empty),
                    new FieldSignalName(Resources.Strings.UserStatusMonitor_DiscreteInput0)));
            return(device);
        }
        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 static NodeDevice StaticBuildHelper(string deviceName, string typeId, Guid instanceId, string code,
                                                   int buttons, int axes, int povhats)
        {
            FieldIdentifier c;
            FieldGuid       typ;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName dName;

            c             = new FieldIdentifier(code);
            typ           = new FieldGuid(typeId);
            address       = new FieldString(instanceId.ToString());
            configuration = new FieldBase64(string.Empty);
            dName         = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection <NodeDiscreteInput>();

            for (int i = 0; i < buttons; i++)
            {
                int buttonNumber = i + 1;
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                                      new FieldIdentifier(Resources.Strings.Button + buttonNumber),
                                      new FieldString(i.ToString()),
                                      new FieldSignalName(Resources.Strings.Button + " " + buttonNumber)));
            }
            var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable);

            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection <NodeAnalogInput>();

            for (int i = 0; i < axes; i++)
            {
                if (i == 3)
                {
                    break;         // only supports up to 3 axes
                }
                int    axisNumber = i + 1;
                string axisName   =
                    axisNumber == 1 ? "X" :
                    axisNumber == 2 ? "Y" :
                    axisNumber == 3 ? "Z" :
                    null;

                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(axisName),
                                            new FieldString(axisName),
                                            new FieldSignalName(axisName)));

                string rotationName = "Rotation" + axisName;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(rotationName),
                                            new FieldString(rotationName),
                                            new FieldSignalName(rotationName)));
            }
            for (int i = 0; i < povhats; i++)
            {
                int povNumber = i + 1;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.PoVHat + povNumber.ToString()),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.PoVHat + " " + povNumber.ToString())));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable));

            return(device);
        }
Exemplo n.º 5
0
        public static NodeDevice StaticBuildHelper(string deviceName, int serialNumber, string code, string typeId,
                                                   int discreteInputs, int discreteOutputs, int analogInputs, int analogOutputs, int stringInputs, int stringOutputs,
                                                   string analogOutputNameOverride, string discreteOutputNameOverride)
        {
            FieldIdentifier c;
            FieldGuid       typ;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName dName;

            c             = new FieldIdentifier(code);
            typ           = new FieldGuid(typeId);
            address       = new FieldString(serialNumber.ToString());
            configuration = new FieldBase64(string.Empty);
            dName         = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection <NodeDiscreteInput>();

            for (int i = 0; i < discreteInputs; i++)
            {
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                                      new FieldIdentifier(Resources.Strings.Input + i),
                                      new FieldString(i.ToString()),
                                      new FieldSignalName(Resources.Strings.Input + " " + i)));
            }
            var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable);

            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection <NodeAnalogInput>();

            for (int i = 0; i < analogInputs; i++)
            {
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.AnalogInput + i),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.AnalogInput + " " + i)));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable));

            var stringInputsMutable = new Collection <NodeStringInput>();

            for (int i = 0; i < stringInputs; i++)
            {
                stringInputsMutable.Add(NodeStringInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.StringInput + i),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.StringInput + " " + i)));
            }
            device = device.NodeStringInputChildren.Append(new ReadOnlyCollection <NodeStringInput>(stringInputsMutable));

            // Add the outputs
            var outputsMutable = new Collection <NodeDiscreteOutput>();

            for (int i = 0; i < discreteOutputs; i++)
            {
                outputsMutable.Add(NodeDiscreteOutput.BuildWith(
                                       new FieldIdentifier(Resources.Strings.Output + i),
                                       new FieldString(i.ToString()),
                                       new FieldSignalName(discreteOutputNameOverride + " " + i)));
            }
            var outputs = new ReadOnlyCollection <NodeDiscreteOutput>(outputsMutable);

            device = device.NodeDiscreteOutputChildren.Append(outputs);

            var analogOutputsMutable = new Collection <NodeAnalogOutput>();

            for (int i = 0; i < analogOutputs; i++)
            {
                analogOutputsMutable.Add(NodeAnalogOutput.BuildWith(
                                             new FieldIdentifier(Resources.Strings.AnalogOutput + i),
                                             new FieldString(i.ToString()),
                                             new FieldSignalName(analogOutputNameOverride + " " + i)));
            }
            device = device.NodeAnalogOutputChildren.Append(new ReadOnlyCollection <NodeAnalogOutput>(analogOutputsMutable));

            var stringOutputsMutable = new Collection <NodeStringOutput>();

            for (int i = 0; i < stringOutputs; i++)
            {
                stringOutputsMutable.Add(NodeStringOutput.BuildWith(
                                             new FieldIdentifier(Resources.Strings.StringOutput + i),
                                             new FieldString(i.ToString()),
                                             new FieldSignalName(Resources.Strings.StringOutput + " " + i)));
            }
            device = device.NodeStringOutputChildren.Append(new ReadOnlyCollection <NodeStringOutput>(stringOutputsMutable));

            return(device);
        }