1 Replies - 332 Views - Last Post: 26 August 2019 - 04:19 AM Rate Topic: -----

#1 Yaswanth619   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-August 19

Split up serialport.ReadLine(); the values i am getting from arduino

Posted 26 August 2019 - 03:56 AM

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 hardware_split
{
    public partial class Form1 : Form
    {
        private SerialPort myport;
        private string text;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            myport = new SerialPort();
            myport.BaudRate = 115200;
            myport.PortName = "COM14";
            myport.Parity = Parity.None;
            myport.DataBits = 8;
            myport.StopBits = StopBits.One;
            myport.DataReceived += myport_DataReceived;
            myport.Open();
        }

        private void myport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            text = myport.ReadLine();
            this.Invoke(new EventHandler(displaydata_event));
        }

        private void displaydata_event(object sender, EventArgs e)
        {
            textBox1.AppendText("\t" + text);         
        }

        private void button2_Click(object sender, EventArgs e)
        {
            text = textBox1.Text;
            string[] arr = text.Split(' ');
            textBox2.AppendText(arr[0] + "\n");
            textBox3.AppendText(arr[1] + "\n");
            textBox4.AppendText(arr[2] + "\n");
        }
    }
}



eg 44 56 78 three values are serial communication values in one text box.
that has to split like 44 in one box and 5 in one and another 78 in one box.

This post has been edited by Skydiver: 26 August 2019 - 04:11 AM
Reason for edit:: Put code in code tags. Please learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: Split up serialport.ReadLine(); the values i am getting from arduino

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7106
  • View blog
  • Posts: 24,129
  • Joined: 05-May 12

Re: Split up serialport.ReadLine(); the values i am getting from arduino

Posted 26 August 2019 - 04:19 AM

If you actually read the code in that thread that you tried to necro-post, instead of just asking for the code, you would have realized that the solution was already present there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1