Skip to main content
Email Password   helpLost your password?

Sample Image

Introduction

This is a simple implementation of Oscilloscope control. This control shows last N points of user data. It has up to 8 channels (number of channels are defined by OSC_MAX_CHANNELS parameter in header file). Each channel can show only one curve (in this version). Oscilloscope includes zoom in implementation by X (Horizontal), by Y (Vertical), and by both axes simultaneously (Rectangle). Zoom out is also available by pressing right mouse button in channel area (hold CTRL key to full zoom out).

Using the code

To use this control in your application:

Don't forget to turn on any channels you need.

#include "Oscilloscope.h"


//...


class CMainDlg : public CDialogImpl<CMainDlg>
{     
    BEGIN_MSG_MAP(CMainDlg)          
       ...          
       MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)          
       REFLECT_NOTIFICATIONS()     
    END_MSG_MAP()
    ...
    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
        LPARAM /*lParam*/, BOOL& /*bHandled*/);
    ...
    OscilloscopeCtrl m_oscill;     
    ...
}; 

//...


LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
      LPARAM /*lParam*/, BOOL& /*bHandled*/) 
{
     ...     
     m_oscill.SubclassWindow( ::GetDlgItem( IDC_AREA ) );     
     m_oscil.ShowChannel(0);
     m_oscil.ShowChannel(2);
     ...
}

After creating Oscilloscope control, you can set special colors for curves and background (for each channel), point styles (how to draw the data points of curves), turn on/off grid, padding, and set padding coefficient. Padding is auto calculating value and used to offset curve by Y axis. By increasing padding coefficient (k>1), it is possible to decrease the gap between curve and channel top boundary box. If k<1, the gap will be increased (then k != 0). You can change oscilloscope layout by turning on/off X and Y axes and changing their positions (up or bottom for X axis; left or right for Y axis). Important: X axis is only one for all channels and Y axis is unique for every channel.

     ...
     m_oscil.UseGrid(true); // trun on grid

     m_oscil.UsePadding(true); // use padding

     m_oscil.PaddingCoef(2.0); // set padding coefficient

     m_oscil.PointStyle(UTriangle); // set point style to UTriangle

     m_oscil.GetChannel(0)->SetLnColor( RGB(0,255,0) ); // green curve

     m_oscil.GetChannel(0)->SetBgColor( RGB(0,0,0) ); // white background

     m_oscil.BottomXAxis(true); // adds bottom X axis

     m_oscil.LeftYAxis(true); // adds left Y axis

     ...

Then you need to supply data for oscilloscope (pointers to double arrays). It's important that double arrays you pass to oscilloscope have to be global. To increase drawing speed, oscilloscope doesn't copy data to its buffers (!!!). The double arrays contains only Y values, oscilloscope calculates X values automatically by using user time.

     ...
     // number of arrays have to be equal to OSC_MAX_CHANNELS !!!

     // but if you don't need data for example

     // for channel 1 the m_values[1] can be NULL

     double*  m_values[OSC_MAX_CHANNELS];
     size_t   m_cnt;
     size_t   m_time;
     ...
     m_oscil.SetPoints(m_time, m_values, m_cnt);
     ...

Updates

  • Removed using namespace std from header file :)
  • Added double buffering to avoid flickering on draw (thanks to Michal Mecinski)

    Demo program

    The small demo program shows how to use the oscilloscope control. Add buttons to control its layout, to change zoom mode, points styles, last points, and etc. You can change source code for any future usage.

  • You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    GeneralSetPoints Pin
    justinlacroix
    7:01 17 Nov '06  
    GeneralVery slow :( Pin
    HyperThreading
    10:39 24 Oct '06  
    GeneralHelp to create MFC program using Oscilloscope Pin
    Muralish
    21:52 16 Sep '06  
    GeneralPossible Bug Pin
    PiotrGutkowski
    8:26 28 Mar '06  
    GeneralOscilloscope? Really? Pin
    Michael__Ber
    21:25 21 Jan '06  
    GeneralRe: Oscilloscope? Really? Pin
    kezhu
    21:59 25 Mar '08  
    GeneralThis one (oscilloscope-lib) doesn't give ... Pin
    Michael__Ber
    8:02 26 Mar '08  
    Generalmutliple siginals Pin
    rbuchana
    12:09 6 Jan '06  
    GeneralRe: mutliple siginals Pin
    rbuchana
    7:34 20 Feb '06  
    Generaldisplay sound Pin
    TassadaqHussain
    13:30 15 Aug '05  
    Generalto MFC Pin
    EMTA41
    3:00 19 May '05  
    GeneralRe: to MFC Pin
    Alexander Yadykin
    4:43 8 Jun '05  
    GeneralRe: to MFC Pin
    Schwenner Simon
    6:28 13 Jun '05  
    GeneralRe: to MFC Pin
    Alexander Yadykin
    21:04 13 Jun '05  
    GeneralRe: to MFC Pin
    Schwenner Simon
    2:28 14 Jun '05  
    GeneralPlease HELP with MISSING Files Pin
    vishnya
    13:11 5 Apr '05  
    GeneralRe: Please HELP with MISSING Files Pin
    gyar
    12:16 6 Apr '05  
    GeneralRe: Please HELP with MISSING Files Pin
    Anonymous
    13:12 6 Apr '05  
    GeneralRe: Please HELP with MISSING Files Pin
    vishnya
    13:41 6 Apr '05  
    Generalcould you give me missed files? Pin
    windshade
    12:28 11 Aug '04  
    GeneralRe: could you give me missed files? Pin
    Anonymous
    13:24 6 Apr '05  
    GeneralSpeed Pin
    manu777
    23:18 2 Aug '04  
    GeneralOsc screen Pin
    gyar
    5:39 1 Jul '04  
    Generalmissing files ? Pin
    MaxHacker
    8:55 24 Jun '04  
    GeneralRe: missing files ? Pin
    autodebug
    15:57 15 Sep '04  


    Last Updated 23 Jun 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009