Go Down

Topic: how to showing data xbee arduino in c# (Read 958 times) previous topic - next topic

Fightforjuly

Apr 24, 2013, 04:22 am Last Edit: Apr 24, 2013, 02:01 pm by Fightforjuly Reason: 1
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: [Select]
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..

PaulS

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.

ScottMurchison

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. 

Go Up