Click here to Skip to main content
15,034,292 members
Articles / Desktop Programming / Win32
Article
Posted 1 Nov 2009

Stats

45.8K views
3.3K downloads
48 bookmarked

A Beautiful Oscilloscope Based on DirectX

Rate me:
Please Sign up or sign in to vote.
4.56/5 (6 votes)
1 Nov 2009CPOL2 min read
Fast, real, and easy to connect to your application.

The Oscilloscope, displaying demodulated QPSK data

Introduction

This project is a simple oscilloscope that can be connected to any application. The graphics of the software is based on Direct3D, which makes the scene similar to a physical oscilloscope; and instead of the CPU, much of the workload is performed by the GPU.

If your application deals with digital demodulation, this project is for you. To be specific, if your application demodulates the PSK data, then you can use this software oscilloscope to view the constellation of output data. The oscilloscope can display data of any rate. You just need to implant a little bunch of code to your application, and my executable oscilloscope will communicate with your application through Inter-Process Communication (IPC). If you don't know IPC, don't worry. You just need to copy and paste it to your own code.

Background

Before proceeding, I recommend you to download and run the demo application. This will help you to have a basic understanding of how the oscilloscope looks and how it connects to a data-source (i.e., your application). The demo application contains a data-source 'Signal Generation.exe' which generates the QPSK data and runs the oscilloscope to simultaneously show the constellation.

Using the Code

I'll explain how to work with the oscilloscope in four steps:

  1. Inside your code, create a shared buffer. This will be the memory to store the constellation data and the symbol rate. Your application will use this buffer to communicate with me. Add the following code to your application. Read the comments for more information:
  2. C++
    #include "..\Oscilloscope\SharedBuffer.h"
    // Specify the path to SharedBuffer.h
    
    // Global Variable
    SHARED_BUFFER *pSharedBuffer = NULL;
    HANDLE hMapFile = NULL;
    // Global Variable
    
    bool CreateMapFile(void)
    // Call this function from inside
    // the entry-point of your code. Must return true.
    {
        TCHAR szMapName[] = L"MyFileMappingObject";
    
        hMapFile = CreateFileMapping(
            INVALID_HANDLE_VALUE,    // use paging file
            NULL,            // default security 
            PAGE_READWRITE,        // read/write access
            0,            // max. object size 
            sizeof(SHARED_BUFFER),    // buffer size  
            szMapName);        // name of mapping object
    
        if (!hMapFile) 
        { 
            MessageBox(NULL, L"Could not open file mapping object.", 
                       L"Error", MB_OK | MB_ICONERROR);
            return false;
        } 
    
        pSharedBuffer = (SHARED_BUFFER *) MapViewOfFile(
            hMapFile,            // handle to mapping object
            FILE_MAP_ALL_ACCESS,    // read/write permission
            0,
            0,
            sizeof(SHARED_BUFFER));
    
        if (!pSharedBuffer) 
        { 
            MessageBox(NULL, L"Could not map view of file.", 
                             L"Error", MB_OK | MB_ICONERROR);
            return false;
        }
    
        return true;
    }
    
    void CloseMapFile()
    // Call this function just before the exit point of your code.
    {
        if(pSharedBuffer)
            UnmapViewOfFile(pSharedBuffer);
        pSharedBuffer = NULL;
    
        if(hMapFile)
            CloseHandle(hMapFile);
        hMapFile = NULL;
    }
  3. Now, it's your responsibility to store the constellation data (the X and Y components of the sample data) in the shared buffer in sync with the symbol rate. For example, having a symbol rate of 2000, you will have to store 1000 samples in the shared buffer every 0.5 seconds. Samples better be within the range [-1, 1]. pSharedBuffer->x and pSharedBuffer->y are circular buffers; i.e., whenever you reach the end of these buffers, you must wrap to the beginning of them. The oscilloscope also reads these buffers in a circular way. Buffer length is defined by BUFF_SIZE. The structure SHARED_BUFFER is declared in SharedBuffer.h.
  4. Run the oscilloscope to view the constellation. Add the following snippet to your code:
  5. C++
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory(&si, sizeof(si));
    ZeroMemory(&pi, sizeof(pi));
    CreateProcess(L"Oscilloscope.exe", NULL, NULL, NULL, TRUE, NULL, 
                  NULL, NULL, &si, &pi);
  6. My oscilloscope will initialize pSharedBuffer->hWnd to point to itself. So, when you are finished working with the oscilloscope, you can close it easily:
  7. C++
    PostMessage(pSharedBuffer->hWnd, WM_QUIT, 0, 0);

Remarks

  1. To use the executable oscilloscope, no extra file or module is required. But if you want to customize the oscilloscope code, or compile and build it, you must have DirectX 9.0 SDK installed and integrated with Visual Studio.
  2. The first version is for demonstration, and is subject to change and improvements. Your ideas, suggestions, and experiences can help me make the application better. I'm looking forward to hearing from you.

History

  • November 1, 2009: First version uploaded. Waiting for feedback.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ali Tavakol
Engineer
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

Comments and Discussions

 
GeneralNot compiling yet Pin
Jay Bowden19-Oct-10 16:14
MemberJay Bowden19-Oct-10 16:14 
Steps that seemed to work for me to satisfy:
"you must have DirectX 9.0 SDK installed and integrated with Visual Studio"

Find DirectX download site from Microsoft here:
http://msdn.microsoft.com/en-us/directx/aa937788.aspx

Choose "June 2010 DirectX SDK"

Download BIG file:
DXSDK_Jun10.exe
571.7MB

Run the DXSDK_Jun10.exe to install (takes several minutes I
believe, I walked away and came back)

Run VS2008 by clicking on Oscilloscope.sln

Now add the Include and Libraries directories of DirectX to the
Oscilloscope.sln project in VS2008:

Tools/Options.../Projects and Solutions/VC++ Directories

Next add 1 line to each of 2 categories: Include Files and Libraries

First category Include Files:
Platform: [WIn32] (was already set to this for me)
Show directories for: [Include files]

Click on "New Folder" button (hint said "New Line (Ctrl-Insert)")
Browse to: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include
Click on Select Folder

Second category Library files
Platform: [WIn32] (was already set to this for me)
Show directories for: [Library files]

Click on "New Folder" button (hint said "New Line (Ctrl-Insert)")
Browse to: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86
Click on Select Folder

The steps above seemed successful in that the "cannot find (various directx.h files)"
went away.

But now I get a handfull of other errors:

Error	1	error C2143: syntax error : missing ';' before '*'	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	36	Oscilloscope
Error	2	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	36	Oscilloscope
Error	3	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	36	Oscilloscope
Error	4	error C2146: syntax error : missing ';' before identifier 'GetDirectSound'	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	43	Oscilloscope
Error	5	error C2433: 'CSoundManager::LPDIRECTSOUND8' : 'inline' not permitted on data declarations	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	43	Oscilloscope
Error	6	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	43	Oscilloscope
Error	7	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	43	Oscilloscope
Warning	8	warning C4183: 'GetDirectSound': missing return type; assumed to be a member function returning 'int'	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	43	Oscilloscope
Error	9	error C2065: 'm_pDS' : undeclared identifier	c:\users\jay b\desktop\beautiful\oscilloscope\oscilloscope\common\dxutsound.h	43	Oscilloscope


Who has been successful in compiling this?

And ideas for me?

Should I have chosen an older DirectX?

My VS2008 says:
Microsoft Visual Studio 2008
Version 9.0.21022.8 RTM
Microsoft .NET Framework
Version 3.5 SP1

Installed Edition: Professional

Microsoft Visual Basic 2008 91605-270-5613085-60757
Microsoft Visual Basic 2008

Microsoft Visual C# 2008 91605-270-5613085-60757
Microsoft Visual C# 2008

Microsoft Visual C++ 2008 91605-270-5613085-60757
Microsoft Visual C++ 2008

Microsoft Visual Studio 2008 Tools for Office 91605-270-5613085-60757
Microsoft Visual Studio 2008 Tools for Office

Microsoft Visual Web Developer 2008 91605-270-5613085-60757
Microsoft Visual Web Developer 2008

Crystal Reports AAJ60-G0MSA4K-68000CF
Crystal Reports Basic for Visual Studio 2008


Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB944899) KB944899
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/944899.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB945282) KB945282
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/945282.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946040) KB946040
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946040.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946308) KB946308
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946308.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946344) KB946344
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946344.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946581) KB946581
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/946581.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947171) KB947171
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947171.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947173) KB947173
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947173.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947180) KB947180
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947180.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947540) KB947540
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947540.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947789) KB947789
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/947789.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB948127) KB948127
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/948127.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB953256) KB953256
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/953256.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB971091) KB971091
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/971091.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB973674) KB973674
This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/973674.

Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB972221) KB972221
This update is for Microsoft Visual Studio 2008 Professional Edition - ENU.
If you later install a more recent service pack, this update will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/972221.

I would really like to try this code out. Thanks!

- Jay
GeneralRe: Not compiling yet Pin
Ali Tavakol19-Oct-10 21:26
MemberAli Tavakol19-Oct-10 21:26 
GeneralRe: Not compiling yet (much improved, but..) Pin
Jay Bowden20-Oct-10 10:58
MemberJay Bowden20-Oct-10 10:58 
GeneralRe: Not compiling yet (much improved, but..) Pin
Ali Tavakol20-Oct-10 22:26
MemberAli Tavakol20-Oct-10 22:26 
GeneralBache Goozoo Pin
HofstraProgrammer4-Nov-09 11:48
MemberHofstraProgrammer4-Nov-09 11:48 
GeneralImprovements Pin
JamieFay1-Nov-09 14:32
MemberJamieFay1-Nov-09 14:32 
GeneralRe: Improvements Pin
Ali Tavakol1-Nov-09 18:47
MemberAli Tavakol1-Nov-09 18:47 
GeneralOne question Pin
gaurav_verma_mca1-Nov-09 3:40
Membergaurav_verma_mca1-Nov-09 3:40 
GeneralRe: One question Pin
Ali Tavakol1-Nov-09 7:28
MemberAli Tavakol1-Nov-09 7:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.