Strip Chart for the CUWIN

Applications, examples, and sample programs using products from Comfile Technology

Strip Chart for the CUWIN

Postby Mike » Sun Feb 12, 2012 10:20 pm

This Visual Studio project demonstrates a strip chart control. The project is a .Net Compact Framework 3.5 project for the CUWIN 5000/6000 series, but the code can be copied without modification into a .Net Compact Framework 2.0 project for use on the CUWIN 3000/4000 series.

screenshot.jpg
Screenshot
screenshot.jpg (40.82 KiB) Viewed 2359 times


How to use it.

1. Create one or more StripChart.Line objects. The last parameter is actually a function that the StripChart control will call every StripChart.UpdateInterval milliseconds.
C#
Code: Select all
_sine = new StripChart.Line(Color.FromArgb(0xFF, 0x00, 0x00), ComputeSine);
_cosine = new StripChart.Line(Color.FromArgb(0x00, 0x00, 0xFF), ComputeCosine);

private StripChart.Line.DataPoint ComputeSine()
{
    double t = (double)GetTickCount() / 1000.0d - _t0;
    double amplitude = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0d;
    return new StripChart.Line.DataPoint(t, amplitude * Math.Sin(Frequency * t));
}

private StripChart.Line.DataPoint ComputeCosine()
{
    double t = (double)GetTickCount() / 1000.0d - _t0;
    double amplitude = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0d;
    return new StripChart.Line.DataPoint(t, amplitude * Math.Cos(Frequency * t));
}

VB
Code: Select all
_sine = New StripChart.Line(Color.FromArgb(&HFF, &H0, &H0), AddressOf ComputeSine)
_cosine = New StripChart.Line(Color.FromArgb(&H0, &H0, &HFF), AddressOf ComputeCosine)

Private Function ComputeSine() As StripChart.Line.DataPoint
    Dim t As Double = CDbl(GetTickCount()) / 1000.0 - _t0
    Dim amplitude As Double = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0
    Return New StripChart.Line.DataPoint(t, amplitude * Math.Sin(Frequency * t))
End Function

Private Function ComputeCosine() As StripChart.Line.DataPoint
    Dim t As Double = CDbl(GetTickCount()) / 1000.0 - _t0
    Dim amplitude As Double = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0
    Return New StripChart.Line.DataPoint(t, amplitude * Math.Cos(Frequency * t))
End Function


2. Add the Lines to the StripChart control.
C#
Code: Select all
_stripChart.AddLine(_sine);
_stripChart.AddLine(_cosine);

VB
Code: Select all
_stripChart.AddLine(_sine)
_stripChart.AddLine(_cosine)


3. Specify how often the StripChart control should update.
C#
Code: Select all
_stripChart.UpdateInterval = 100;

VB
Code: Select all
_stripChart.UpdateInterval = 100


4. Specify the minimum and maximum values for the Y Axis using StripChart.YMinimum and StripChart.YMaximum.

5. Specify the amount of time one full screen should be with StripChart.Range. Be sure StripChart.Range, StripChart.XAxisGridLines.OnEvery, and DataPoint.X all use the same units (i.e. minutes, seconds, milliseconds, etc...)

6. (Optional) Add grid lines. Example: If StripChart.YMinimum is -100.0 and StripChart.YMaximum is +100.0 and YAxisGridLines.OnEvery = 20.0, then there will be one grid line for every 20.0 units between -100 and 100, for a total of 10 divisions.
C#
Code: Select all
_xAxisGridLines = new StripChart.GridLines(Color.FromArgb(0x99, 0x99, 0x99), 1.0d);
_yAxisGridLines = new StripChart.GridLines(Color.FromArgb(0x99, 0x99, 0x99), 20.0d);

_stripChart.XAxisGridLines = _xAxisGridLines;
_stripChart.YAxisGridLines = _yAxisGridLines;

VB
Code: Select all
_xAxisGridLines = New StripChart.GridLines(Color.FromArgb(&H99, &H99, &H99), 1.0)
_yAxisGridLines = New StripChart.GridLines(Color.FromArgb(&H99, &H99, &H99), 20.0)

_stripChart.XAxisGridLines = _xAxisGridLines
_stripChart.YAxisGridLines = _yAxisGridLines


This code can be optimized to provide better performance, but it will make it quite a bit more complicated. I hope, at least, this can serve as a model from which you can make your own implementation.
Attachments
StripChartSample_VB.zip
CUWIN 5000/6000 Series Visual Studio 2008 Project (VB)
(62.84 KiB) Downloaded 650 times
StripChartSample.zip
CUWIN 5000/6000 Series Visual Studio 2008 Project (C#)
(50.7 KiB) Downloaded 667 times
Mike
Mike
SuperDuperDuper
 
Posts: 551
Joined: Thu Mar 17, 2011 3:54 pm
Location: Seoul, South Korea

Return to Applications and Examples

Who is online

Users browsing this forum: No registered users and 3 guests

cron