Pages: [1]   Go Down
Author Topic: how to showing data xbee arduino in c#  (Read 695 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I intended to make an interface so that the data can be viewed on a computer, but I am confused make an interface with c #, does anyone have a sample program with c # arduino xbee? or  how to connect data between arduino + xbee + sensor to apllication with c# because my code not running..
there  my code

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace coba_arduino
{
    public partial class Form1 : Form
    {
        private StringBuilder recievedData = new StringBuilder();
        public Form1()
        {
            InitializeComponent();
        }


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort1.PortName = cmbCOMPort.Text;

            if (!serialPort1.IsOpen)
                serialPort1.Open();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
         foreach (string portname in SerialPort.GetPortNames())
            {
                cmbCOMPort.Items.Add(portname);
            }
            timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
                serialPort1.Close();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen)
                serialPort1.Close();
        }

        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            recievedData.Append(serialPort1.ReadExisting());
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            richTextBox1.Text = richTextBox1.ToString();
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
and show when i'm running the program :



very  need help..

im sorry my english bad..
« Last Edit: April 24, 2013, 07:01:50 am by Fightforjuly » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you posted a large enough picture that could actually be read, that might help.

C# runs the GUI in one thread, and Serial processing in another. You need to deal with this multiple thread situation. The C# program I attached does.

* CommunicateWithArduino.zip (53.99 KB - downloaded 15 times.)
Logged

Ottawa, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 20
32 year veteran of Ottawa high tech community
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks PaulS for uploading your C# program dealing with multithreading. I have been experimenting for 2 days with Arduino and C# and trying to synchronize communications between the two. I am working on a large project that uses a PC based program to control an Arduino based test fixture. I need control over the process so that the PC program knows when to send commands and what to expect back from the Arduino. 
Logged

Pages: [1]   Go Up
Jump to: