I am sending data from arduino to Visual Studio using C #, I am sending the data from a proximity sensor, and now I also have to send the humidity and temperature sensor data, then how to differentiate the data corresponding to said sensor.
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;
using datacenter.Properties;
using System.Threading;
namespace datacenter {
public partial class datacenter : Form {
string dato;
public datacenter() {
InitializeComponent();
serialPort1.PortName = "COM5";
serialPort1.BaudRate = 9600;
serialPort1.Open();
alarmaof.Visible = true;
serialPort1.DataReceived += serialrecive;
}
private void Form1_Load(object sender, EventArgs e)
{
circularProgressBar2.Value = 0;
circularProgressBar2.Minimum = 0;
circularProgressBar2.Maximum = 10000;
}
private void serialrecive(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string line = serialPort1.ReadLine();
this.BeginInvoke(new LineReceivedEvent(lineRecived), line);
}
private delegate void LineReceivedEvent(string line);
public void lineRecived(string line)
{
//procedimiento para mostrar los datos
circularProgressBar2.Text = line;
//Procedimiento para calcular la distancia
if(Convert.ToInt32(line) <1000)
{
alarmaof.Visible = false;
}
else
{
alarmaof.Visible = true;
}
// procedimiento para la barra circular
Thread.Sleep(5);
circularProgressBar2.Value = Convert.ToInt32(line);
circularProgressBar2.Update();
}
}
}