Click here to Skip to main content
15,918,275 members
Home / Discussions / C#
   

C#

 
GeneralRe: Extracting regex from string Pin
jschell21-Apr-19 7:48
jschell21-Apr-19 7:48 
GeneralRe: Extracting regex from string Pin
#realJSOP21-Apr-19 11:45
professional#realJSOP21-Apr-19 11:45 
GeneralRe: Extracting regex from string Pin
jschell27-Apr-19 6:11
jschell27-Apr-19 6:11 
GeneralRe: Extracting regex from string Pin
ormonds21-Apr-19 12:19
ormonds21-Apr-19 12:19 
AnswerRe: Extracting regex from string Pin
jschell21-Apr-19 7:52
jschell21-Apr-19 7:52 
AnswerRe: Extracting regex from string Pin
Luc Pattyn22-Apr-19 15:45
sitebuilderLuc Pattyn22-Apr-19 15:45 
QuestionI need help with console app in C# Pin
User 1428799220-Apr-19 11:24
User 1428799220-Apr-19 11:24 
AnswerRe: I need help with console app in C# (old mac donald had a farm) Pin
OriginalGriff20-Apr-19 11:31
mveOriginalGriff20-Apr-19 11:31 
AnswerRe: I need help with console app in C# (old mac donald had a farm) Pin
Dave Kreskowiak20-Apr-19 13:01
mveDave Kreskowiak20-Apr-19 13:01 
AnswerRe: I need help with console app in C# (old mac donald had a farm) Pin
Luc Pattyn20-Apr-19 15:27
sitebuilderLuc Pattyn20-Apr-19 15:27 
GeneralRe: I need help with console app in C# (old mac donald had a farm) Pin
Dave Kreskowiak20-Apr-19 15:54
mveDave Kreskowiak20-Apr-19 15:54 
Questionmy programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Member 1432102120-Apr-19 5:47
Member 1432102120-Apr-19 5:47 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
OriginalGriff20-Apr-19 6:03
mveOriginalGriff20-Apr-19 6:03 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Member 1432102120-Apr-19 6:15
Member 1432102120-Apr-19 6:15 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
OriginalGriff20-Apr-19 6:24
mveOriginalGriff20-Apr-19 6:24 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Gerry Schmitz20-Apr-19 6:06
mveGerry Schmitz20-Apr-19 6:06 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
OriginalGriff20-Apr-19 6:18
mveOriginalGriff20-Apr-19 6:18 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Gerry Schmitz20-Apr-19 8:22
mveGerry Schmitz20-Apr-19 8:22 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Simon_Whale20-Apr-19 6:14
Simon_Whale20-Apr-19 6:14 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
BillWoodruff23-Apr-19 7:49
professionalBillWoodruff23-Apr-19 7:49 
QuestionMerge Sort linked list Pin
Member 1431822319-Apr-19 12:23
Member 1431822319-Apr-19 12:23 
AnswerRe: Merge Sort linked list Pin
#realJSOP19-Apr-19 12:38
professional#realJSOP19-Apr-19 12:38 
GeneralRe: Merge Sort linked list Pin
Member 1431822320-Apr-19 9:12
Member 1431822320-Apr-19 9:12 
Questionrecieveing and splitting serial data from Arduino in C# Pin
auting8219-Apr-19 7:07
auting8219-Apr-19 7:07 
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];

    


        }

AnswerRe: recieveing and splitting serial data from Arduino in C# Pin
Gerry Schmitz19-Apr-19 9:20
mveGerry Schmitz19-Apr-19 9:20 

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.