/// <summary>
 /// Create the port
 /// </summary>
 /// <param name="layer">the brick layer</param>
 /// <param name="port">the port name</param>
 internal OutputPort(ChainLayer layer, OutputPortName port)
 {
     Layer  = layer;
     Name   = port;
     Status = PortStatus.Empty;
     Number = port.AbsolutePortNumber(layer);
 }
Esempio n. 2
0
        /// <summary>
        /// Read information about external device
        /// </summary>
        /// <param name="port"></param>
        /// <param name="layer"></param>
        /// <returns></returns>
        public async Task <Format> GetFormat(OutputPortName port, ChainLayer layer = ChainLayer.One)
        {
            int portNumber = port.AbsolutePortNumber(layer);

            return(await InputMethods.GetFormat(Brick.Socket, layer, portNumber));
        }
Esempio n. 3
0
        public static void Connect(IOPort brickPorts, List <DeviceOptions> devices)
        {
            foreach (DeviceOptions device in devices)
            {
                ChainLayer layer = device.Layer;

                switch (device.Type)
                {
                case DeviceType.MediumMotor:
                {
                    OutputPortName port       = (OutputPortName)Enum.Parse(typeof(OutputPortName), device.Port, true);
                    int            portNumber = port.AbsolutePortNumber(layer);
                    LoadMediumMotor(device.Id).Connect(brickPorts.Output.Ports[portNumber]);
                    break;
                }

                case DeviceType.LargeMotor:
                {
                    OutputPortName port       = (OutputPortName)Enum.Parse(typeof(OutputPortName), device.Port, true);
                    int            portNumber = port.AbsolutePortNumber(layer);
                    LoadLargeMotor(device.Id).Connect(brickPorts.Output.Ports[portNumber]);
                    break;
                }

                case DeviceType.TouchSensor:
                {
                    InputPortName port       = (InputPortName)Enum.Parse(typeof(InputPortName), device.Port, true);
                    int           portNumber = port.AbsolutePortNumber(layer);
                    LoadTouchSensor(device.Id).Connect(brickPorts.Input.Ports[portNumber]);
                    break;
                }

                case DeviceType.ColorSensor:
                {
                    InputPortName port       = (InputPortName)Enum.Parse(typeof(InputPortName), device.Port, true);
                    int           portNumber = port.AbsolutePortNumber(layer);
                    LoadColorSensor(device.Id).Connect(brickPorts.Input.Ports[portNumber]);
                    break;
                }

                case DeviceType.GyroscopeSensor:
                {
                    InputPortName port       = (InputPortName)Enum.Parse(typeof(InputPortName), device.Port, true);
                    int           portNumber = port.AbsolutePortNumber(layer);
                    LoadGyroscopeSensor(device.Id).Connect(brickPorts.Input.Ports[portNumber]);
                    break;
                }

                case DeviceType.InfraredSensor:
                {
                    InputPortName port       = (InputPortName)Enum.Parse(typeof(InputPortName), device.Port, true);
                    int           portNumber = port.AbsolutePortNumber(layer);
                    LoadInfraredSensor(device.Id).Connect(brickPorts.Input.Ports[portNumber]);
                    break;
                }

                case DeviceType.UltrasonicSensor:
                {
                    InputPortName port       = (InputPortName)Enum.Parse(typeof(InputPortName), device.Port, true);
                    int           portNumber = port.AbsolutePortNumber(layer);
                    LoadUltrasonicSensor(device.Id).Connect(brickPorts.Input.Ports[portNumber]);
                    break;
                }
                }
            }
        }