Click here to Skip to main content
15,891,607 members
Home / Discussions / C#
   

C#

 
AnswerRe: recieveing and splitting serial data from Arduino in C# Pin
Luc Pattyn19-Apr-19 11:00
sitebuilderLuc Pattyn19-Apr-19 11:00 
GeneralRe: recieveing and splitting serial data from Arduino in C# Pin
auting8219-Apr-19 11:36
auting8219-Apr-19 11:36 
GeneralRe: recieveing and splitting serial data from Arduino in C# Pin
Luc Pattyn19-Apr-19 11:52
sitebuilderLuc Pattyn19-Apr-19 11:52 
GeneralRe: recieveing and splitting serial data from Arduino in C# Pin
auting8224-Apr-19 7:34
auting8224-Apr-19 7:34 
GeneralRe: recieveing and splitting serial data from Arduino in C# Pin
Luc Pattyn24-Apr-19 8:37
sitebuilderLuc Pattyn24-Apr-19 8:37 
GeneralRe: recieveing and splitting serial data from Arduino in C# Pin
auting8224-Apr-19 9:45
auting8224-Apr-19 9:45 
GeneralRe: recieveing and splitting serial data from Arduino in C# Pin
Luc Pattyn24-Apr-19 10:05
sitebuilderLuc Pattyn24-Apr-19 10:05 
Questionrecieveing and splitting serial data from Arduino in C# Pin
auting8219-Apr-19 6:04
auting8219-Apr-19 6:04 
Hi, I am fairly new to C# coding so be gentle Laugh | :laugh:
I am trying to receive measurement data from a two sensors DHT11 and soimoisture sensor connected to my Arduino. At this stage I just want to receive the raw measurement data and represent them in separate text boxes. I have almost managed it but I am getting some errors.
More specifically I get this error:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.<br />
Parameter name: index'

Here is my code:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;


namespace PlantMonitoringApp
{
    public partial class Form1 : Form
    {

        private SerialPort myport;
        private DateTime datetime;
        private string in_data;

        public Form1()
        {
            InitializeComponent();
        }

        private void start_btn_Click(object sender, EventArgs e)
        {
            myport = new SerialPort();
            myport.BaudRate = 9600;
            myport.PortName = port_name_tb.Text;
            myport.Parity = Parity.None;
            myport.DataBits = 8;
            myport.StopBits = StopBits.One;
            myport.DataReceived += Myport_DataReceived1;
            try
            {
                myport.Open();
                time_text_box.Text = "";

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }

            // timer1.Start();


        }
        void Myport_DataReceived1(object sender, SerialDataReceivedEventArgs e)
        {

            in_data = myport.ReadLine();

            this.Invoke(new EventHandler(displaydata_event));
            /*String dataFromArduino = myport.ReadLine();
            String[] dataTempHumidMoisture = dataFromArduino.Split();
            int Temperature = (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture[0]), 0));
            //int Humidity = (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture[1]), 0));
           // int SoilMoisture= (int)(Math.Round(Convert.ToDecimal(dataTempHumidMoisture[2]), 0));
            txtTemperature.Text = Temperature.ToString() + "C";
           // txtHumidity.Text = Humidity.ToString() + "%";
            //txtHumidity.Text = SoilMoisture.ToString() + "%";*/





        }
        private void displaydata_event(object sender, EventArgs e)
        {
            datetime = DateTime.Now;
            string time = datetime.Hour + ":" + datetime.Minute + ":" + datetime.Second;
            time_text_box.Text = time;

            


            string[] sensorData = in_data.Split(new char[] { ' ',' ',' '});
            List<string> tokens = new List<string>();
            foreach (string s in sensorData)
            {
                if (s.Length !=0)
                {
                    tokens.Add(s);
                }
            }
            
            
            txtTemperature.Text = tokens[0];
            txtHumidity.Text = tokens[1];
            txtSoil_moisture.Text = tokens[2];

    


        }

Questionsample application to customize combo box with multi selection an check box in winform Pin
ambili3018-Apr-19 0:18
ambili3018-Apr-19 0:18 
AnswerRe: sample application to customize combo box with multi selection an check box in winform Pin
Richard MacCutchan18-Apr-19 1:09
mveRichard MacCutchan18-Apr-19 1:09 
AnswerRe: sample application to customize combo box with multi selection an check box in winform Pin
Eddy Vluggen18-Apr-19 1:21
professionalEddy Vluggen18-Apr-19 1:21 
AnswerRe: sample application to customize combo box with multi selection an check box in winform Pin
OriginalGriff18-Apr-19 3:43
mveOriginalGriff18-Apr-19 3:43 
GeneralRe: sample application to customize combo box with multi selection an check box in winform Pin
#realJSOP18-Apr-19 8:00
mve#realJSOP18-Apr-19 8:00 
GeneralRe: sample application to customize combo box with multi selection an check box in winform Pin
OriginalGriff18-Apr-19 8:05
mveOriginalGriff18-Apr-19 8:05 
GeneralRe: sample application to customize combo box with multi selection an check box in winform Pin
Dave Kreskowiak18-Apr-19 8:55
mveDave Kreskowiak18-Apr-19 8:55 
AnswerRe: sample application to customize combo box with multi selection an check box in winform Pin
Gerry Schmitz18-Apr-19 6:12
mveGerry Schmitz18-Apr-19 6:12 
GeneralRe: sample application to customize combo box with multi selection an check box in winform Pin
OriginalGriff18-Apr-19 6:34
mveOriginalGriff18-Apr-19 6:34 
QuestionHow store all TabPage items in c# Pin
Richi38117-Apr-19 22:58
Richi38117-Apr-19 22:58 
AnswerRe: How store all TabPage items in c# Pin
OriginalGriff17-Apr-19 23:34
mveOriginalGriff17-Apr-19 23:34 
AnswerRe: How store all TabPage items in c# Pin
#realJSOP18-Apr-19 2:18
mve#realJSOP18-Apr-19 2:18 
GeneralRe: How store all TabPage items in c# Pin
Richi38125-Apr-19 20:29
Richi38125-Apr-19 20:29 
AnswerRe: How store all TabPage items in c# Pin
Gerry Schmitz18-Apr-19 6:09
mveGerry Schmitz18-Apr-19 6:09 
AnswerRe: How store all TabPage items in c# Pin
BillWoodruff18-Apr-19 20:48
professionalBillWoodruff18-Apr-19 20:48 
GeneralRe: How store all TabPage items in c# Pin
Richi38125-Apr-19 21:39
Richi38125-Apr-19 21:39 
AnswerRe: How store all TabPage items in c# Pin
BillWoodruff26-Apr-19 4:09
professionalBillWoodruff26-Apr-19 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.