Open source
custom rule creation in sonar for c# project
3D image in Windows store applications
C# - Zedgraph, plotting serial data too much delay and time
I'm new to C# programming and trying to write an application which is part of my final thesis.
I have a microprocessor that continuously send data from a sensor to my computer via serial port. All I want is to plotting this data using Zedgraph.
The problem is that the graph got too much delay and time lag. It seems the problem happens because I continuously update the whole graph at a very high rate. I have stucked on this problem in a week and still dont find out a solution. I'll be more than happy if someone can help me out.
This is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using System.IO.Ports;
using System.Threading;
namespace DynamicData
{
publicpartialclassForm1 : Form
{
private SerialPort port;
privatestring buffer = "";
privatevoid connect()
{
port = new SerialPort("COM8", 115200, Parity.None, 8, StopBits.One);
port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);
if (!port.IsOpen) port.Open();
}
public Form1()
{
InitializeComponent();
}
privatevoid Form1_Load( object sender, EventArgs e )
{
connect();
GraphPane myPane = zedGraphControl1.GraphPane;
RollingPointPairList list = new RollingPointPairList(500);
LineItem curve = myPane.AddCurve( "Sensor", list, Color.Blue, SymbolType.None );
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 10;
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.Max = 300;
myPane.XAxis.Scale.MinorStep = 0.5;
myPane.XAxis.Scale.MajorStep = 1;
zedGraphControl1.AxisChange();
}
privatevoid port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
//sample data: ;100*100000:
//sampling rate ~100Hz
buffer += port.ReadExisting();
//flush incomplete package
while (buffer[0] != ';')
{
buffer = buffer.Remove(0, 1);
if (buffer.Length < 1) break;
}
//got a complete package, go to data handling
while (buffer.Contains(":"))
{
DataHandling();
}
}
privatevoid DataHandling()
{
string[] nameArray = buffer.Split(new[] { ";", ":", "*" }, StringSplitOptions.RemoveEmptyEntries);
//plot sensor data vs. time
draw(Convert.ToInt32(nameArray[0]), Convert.ToInt32(nameArray[1]));
//remove handled package in buffer
var index = buffer.IndexOf(":");
buffer = buffer.Remove(0, index + 1);
}
double time = 0;
privatevoid draw(int sensor, int t)
{
//convert tick to sec (uP clock rate = 16MHZ)
time = time + (t / 16000000.0);
// Get the first CurveItem in the graph
LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
// Get the PointPairList
IPointListEdit list = curve.Points as IPointListEdit;
list.Add(time, sensor);
//Keep the X scale at a rolling 10 second interval, with one
//major step between the max X value and the end of the axis
Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
if (time > xScale.Max - xScale.MajorStep)
{
xScale.Max = time + xScale.MajorStep;
xScale.Min = xScale.Max - 10.0;
}
//Display sensor data
this.Invoke(newAction(() => { textBox1.Text = byte1.ToString(); }));
axisChangeZedGraph(zedGraphControl1);
}
delegatevoid axisChangeZedGraphCallBack(ZedGraphControl zg);
privatevoid axisChangeZedGraph(ZedGraphControl zg)
{
if (zg.InvokeRequired)
{
axisChangeZedGraphCallBack ad = new axisChangeZedGraphCallBack(axisChangeZedGraph);
zg.Invoke(ad, newobject[] { zg });
}
else
{
// zg.AxisChange();
zg.Invalidate();
zg.Refresh();
}
}
}
}
C# share reusable library
The code in the calling program currently looks like the following:
strConsoleAppLocation = ConfigurationManager.AppSettings["dll_location"];
string Process_Arguments = null;
Process RPT_Process = new Process();
RPT_Process.StartInfo.FileName = strConsoleAppLocation;
Process_Arguments = " 7 " + strCUSTID + " 1";
RPT_Process.StartInfo.Arguments = Process_Arguments;
RPT_Process.Start();
RPT_Process.WaitForExit();
RPT_Process.Dispose();
My goal is to share the same reuseable object and pass parameter values to methods that are exposed. Let me know what I suggest is a good idea or not? Also can you show me some code on how to accomplish this goal?
C# How to make one item from Menustrip be default selected?
I am working on C# WFA. I have one menustrip which has one item called: Settings, under this I have three items: ID, Number, and Time. Under Number item there has 5 items again which man can choose. Now I want to make it like this: first make one of the items under Number is default chosen, Secondly, I want to have one more textbox in the GUI, which will show which item is selected under number.
For example:
Settings---ID---Number----NUMBER1----Number2----Number3---Time
So I want to set the Number 2 as the default chosen item, how can I do that? I want to display the selected Number item in textbox when one is selected, How can I do that?
Thanks a lot!
BR Emma
how to add read more link to dataset in repeater control
How to show crystal report Doc in button click with Preview?
IS Primary Key Always Better ?
xml parsing . want to access internet on emulator
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Height="778" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="24,-45,0,0" Name="listBoxAuthors" VerticalAlignment="Top" Width="444" Loaded="listBox1_Loaded" SelectionChanged="listBoxAuthors_SelectionChanged">
<phone:WebBrowser HorizontalAlignment="Center" Name="web" Margin="9,121,0,0" />
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding AuthorImage}" Width="150" Stretch="UniformToFill" HorizontalAlignment="Center" />
<StackPanel Width="370">
<TextBlock Text="{Binding AuthorName}" FontWeight="Bold" FontSize="22" Name="id"/>
<TextBlock Text="{Binding Description}" Name="name" />
<TextBlock x:Name="srctxtbox" Text="{Binding Source}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
code behind it
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
}
private void listBox1_Loaded(object sender, RoutedEventArgs e)
{
var element = XElement.Load("Authors.xml");
var authors = from var in element.Descendants("Author")
orderby var.Attribute("AuthorName").Value
select new Authors
{
AuthorId = Convert.ToInt32(var.Attribute("AuthorId").Value),
AuthorName = var.Attribute("AuthorName").Value,
AuthorImage = GetImage(var.Attribute("AuthorImage").Value),
Description = var.Attribute("Description").Value,
Source = var.Attribute("Source").Value
};
listBoxAuthors.DataContext = authors;
}
public ImageSource GetImage(string path)
{
return new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
}
private void listBoxAuthors_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var listBoxItem = listBoxAuthors.SelectedItem as ListBoxItem;
TextBlock nameBlock = listBoxItem.FindName("srctxtbox") as TextBlock;
MessageBox.Show(nameBlock.Text);
}
}an i get value please help me out
Using ComboBox in vs 2012 express for windows phone
how to change style properties of dropdownlist to various ?
C# web browser
like Safari
Datagrid binding with multiple Collections using MVVM
1. User(UserId,Name,EmailId,RoleId)
2. Role(RoleId,RoleName)
Right join the both collections and databind the itemsource to datagrid.
Vs C++
How to create pdf file......? pls sent me link...
Windows Server 2012 Backup and Restore Instructions Step by
Form to a Word Document Template
Is I-Phone is good for career if i have .net developer.please give me some advice
place desktop icon in metro style app
Hi,
I would like to know how to place an icon in metro style app using C#.