i want to send 3 sensor data to pc via Serial Connection ... And analyze the data using C# app ...
I Still dont know the theory of sending multiple values .. So any idea to do that ???
i want to send 3 sensor data to pc via Serial Connection ... And analyze the data using C# app ...
Permission is hereby granted. Proceed.
I Still dont know the theory of sending multiple values
And yet you've figured out to type multiple words in such a way that others can understand them. Am I missing something?
Send a value. Send a delimiter. Repeat as many times as needed.
So any idea to do that ???
But of course.
Devise some kind of protocol that allows the C# program to figure out which reading is which. A simple way is:
<32.1,45.0,23.9>
So you have a start of packet and end of packet marker and comma separated readings. You know which is which, so you can parse out the readings in your C# code. You can add checksums, acknowledgment, named parameters etc. etc, but that basic method should get you started.
thanx for the advice....
I want to send readings from 2 ultrasound Sensors....
#define echo1 7
#define trig1 12
#define echo2 3
#define trig2 13
long dis1,pulse1,dis2,pulse2;
void setup()
{
pinMode(echo1,INPUT);
pinMode(trig1,OUTPUT);
pinMode(echo2,INPUT);
pinMode(trig2,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trig1,LOW);
delayMicroseconds(10);
digitalWrite(trig1,HIGH);
delayMicroseconds(10);
digitalWrite(trig1,LOW);
pulse1=pulseIn(echo1,HIGH);
dis1=pulse1/58.2;
digitalWrite(trig2,LOW);
delayMicroseconds(10);
digitalWrite(trig2,HIGH);
delayMicroseconds(10);
digitalWrite(trig2,LOW);
pulse2=pulseIn(echo2,HIGH);
dis2=pulse2/58.2;
Serial.write(int(dis1));
Serial.write(int(dis2));
delay(500);
}
I need a C# programme to catch these data ...
IS THIS OK ???
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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
SerialPort port = new SerialPort("COM15", 9600);
string rawdata;
string[] data;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
port.Open();
}
catch
{
MessageBox.Show("Error of Opening tjhe Ports", "Atention");
}
while (port.IsOpen)
{
data = port.ReadLine().Split(',');
textBox1.Text = data[0];
textBox2.Text = data[1];
}
}
}
}
I want to send readings from 2 ultrasound Sensors....
So, instead of writing a function, I'm just going to duplicate the code.
IS THIS OK ???
No. The sender is sending binary data with no delimiters. The C# application is expecting ASCII data separated by a comma.
The sender needs to use:
Serial.print(dis1);
Serial.print(",");
Serial.println(dis2);
Note the use of println for the last value, to add the carriage return and line feed that ReadLine() is expecting.