Пример #1
0
        protected void ProcessArduinoResults(string data)
        {
            data = data.Replace("\n", "").Replace("\r", "");
            //P=A12,V=708
            if (data.StartsWith("="))
            {
                //Se introduce este fix, dado que la lectura elmina el primer caracter
                data = "P" + data;
            }
            var multipleCommand = data.Split('|');

            foreach (var command in multipleCommand)
            {
                try
                {
                    if (command.Contains("P=") && command.Contains("V="))
                    {
                        int             indexP          = command.IndexOf("P=", StringComparison.Ordinal);
                        int             indexV          = command.IndexOf("V=", StringComparison.Ordinal) + 2;
                        int             indexComa       = command.IndexOf(",", StringComparison.Ordinal) - 2;
                        string          pin             = command.Substring(2, indexComa);
                        var             countFin        = command.Length - 5 - indexComa;
                        string          value           = command.Substring(indexV, countFin);
                        ArduinoDataRead dataSendArduino = new ArduinoDataRead(pin, value);
                        this.Ports.ReadDataPortArduino(dataSendArduino);
                    }
                }
                catch (Exception ex)
                {
                    //throw new Exception("Error en el procesamiento de comando. Commando mal Formateado : " + data);
                }
            }
        }
Пример #2
0
        private async Task ManagerLogicAsync(ArduinoDataRead dataRead)
        {
            if (dataRead.Pin == PIN_SENSOR_LUZ)
            {
                txtSensorLuz.Text = dataRead.Value;
                if (int.Parse(dataRead.Value) > LIMITE_SENSOR_LUZ)
                {
                    await this._arduinosManager.ArduinoMega2560.WriteCommand("W", PIN_LUZ, "1");

                    txtLedRojo.Text = "Prendido";
                }
                else
                {
                    await this._arduinosManager.ArduinoMega2560.WriteCommand("W", PIN_LUZ, "0");

                    txtLedRojo.Text = "Apagado";
                }
            }
            else if (dataRead.Pin == PIN_SUELO)
            {
                txtHumedad.Text = dataRead.Value;
                if (int.Parse(dataRead.Value) < LIMITE_HUMEDAD_SUELO)
                {
                    await this._arduinosManager.ArduinoMega2560.WriteCommand("W", PIN_AGUA, "0");

                    txtBomba.Text = "Apagado";
                }
                else
                {
                    await this._arduinosManager.ArduinoMega2560.WriteCommand("W", PIN_AGUA, "1");

                    txtBomba.Text = "Prendido";
                }
            }
            else if (dataRead.Pin == "A1")
            {
                if (int.Parse(dataRead.Value) < 200)
                {
                    await this._arduinosManager.ArduinoMega2560.WriteCommand("W", "7", "1");
                }
                else
                {
                    await this._arduinosManager.ArduinoMega2560.WriteCommand("W", "7", "0");
                }
            }
        }