473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Displaying Chart for serial data received through serial port.

I am working on serial port programming. Here in my case, continuous set of data is coming through a serial port and i want to display that data in chart. means each time a new set of data is received the chart should change according to the value.
My problem is when i am using message box it is working. but when i remove the message box, the chart is not appearing. What should i do? here is my code which is working...
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO.Ports;
  10. using System.Threading;
  11.  
  12. namespace MaintainGraph
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.             //ResizeRedraw = true;
  21.         }
  22.  
  23.         private void rcv_btn_Click(object sender, EventArgs e)
  24.         {
  25.             SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
  26.             try
  27.             {
  28.                 if (!port.IsOpen)
  29.                     port.Open();
  30.             }
  31.             catch (Exception ex)
  32.             {
  33.                 Console.WriteLine(ex.Message);
  34.             }
  35.             Thread.Sleep(2000);
  36.             port.ReadTimeout = 1000;
  37.             while (true)
  38.             {
  39.                 double[] arr = new double[6];
  40.                 try
  41.                 {
  42.                     arr[0] = Convert.ToDouble(port.ReadLine());
  43.                     arr[1] = Convert.ToDouble(port.ReadLine());
  44.                     arr[2] = Convert.ToDouble(port.ReadLine());
  45.                     arr[3] = Convert.ToDouble(port.ReadLine());
  46.                     arr[4] = Convert.ToDouble(port.ReadLine());
  47.                     arr[5] = Convert.ToDouble(port.ReadLine());
  48.                 }
  49.  
  50.                 catch (System.TimeoutException ex)
  51.                 {
  52.                 }
  53.  
  54.  
  55.                 MessageBox.Show("Hello");
  56.  
  57.                 txt.Text = arr[0] + " " + arr[1] + " " + arr[2] + " " + arr[3] + " " + arr[4] + " " + arr[5];
  58.                 this.chart1.Series["Values"].Points.AddXY("Depth", arr[0]);
  59.                 this.chart1.Series["Values"].Points.AddXY("PositionX", arr[1]);
  60.                 this.chart1.Series["Values"].Points.AddXY("PositionY", arr[2]);
  61.                 this.chart1.Series["Values"].Points.AddXY("Heading", arr[3]);
  62.                 this.chart1.Series["Values"].Points.AddXY("Surge", arr[4]);
  63.                 this.chart1.Series["Values"].Points.AddXY("Alimetry", arr[5]);
  64.                 MessageBox.Show("Bye");
  65.                 Thread.Sleep(1000);
  66.                 try
  67.                 {
  68.                     chart1.Series["Values"].Points.Clear();
  69.                 }
  70.                 catch (System.ArgumentException ex)
  71.                 { }
  72.             }
  73.  
  74.         }
  75.  
  76.         private void Form1_Load(object sender, EventArgs e)
  77.         {
  78.        }      
}
}
Oct 29 '14 #1
0 1719

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sonoman | last post by:
Hello everyone: I am new to Visual Basic and I have a problem that I cannot put my finger on. I am working on a school project and I am getting some serial data from a microprocessor. I have...
1
by: kiran | last post by:
Hi all, I have a problem to communicate with serial port(COM3:). I am able to open the handle but cannot send any data. 1. I connected my motoroala handset to PC through datacable. 2. I...
2
by: Padu | last post by:
Hi, I know that the System.IO.Ports.Serial port event for receiving data (DataReceived) happens on a secondary thread, and that if there will be any interaction of that data with the UI, it...
1
by: marsha | last post by:
i have problem with my script. i have input from several sensor then i send to serial port. the serial data received with vb. data appear not in a single data, but in some packet. so, how to...
7
by: Lou | last post by:
I have a class that uses the serial port class Private SerialPort as New SerialPort When I receive the asyncronous serial port response it appears that data is on a different thread than my...
6
by: anu29dolly | last post by:
Hello everyone... I have written a program to write and read data from serial port.... I am able to write 80(in binary)..and is expecting 1B but i am uable to read it... My code goes as...
3
by: Mary Mah | last post by:
Hi, iam building a system which will send data from website to serial port using PHP, the problem that i want to send bits to the serial port not only data. i wrote a php code to do so but it still...
0
by: steve472 | last post by:
import serial import threading import Queue import Tkinter as tk class SerialThread(threading.Thread): def __init__(self, queue): threading.Thread.__init__(self) ...
1
by: parvathireddy | last post by:
I need to receive data from pc to Pos using serial port RS 232 . I am receiving data but garbage values and overlapping is occuring. // data received //...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.