Simple Real-time Class for Advanced Charts and Plotting


Click here for larger image

Environment: VC6, NT4 SP5, Windows 95b/98

In real time applications it is necessary to have some graphics functions which can make plotting using dynamic engineering data. The CRealTime class provide such functions which have been implemented using SDK rather than MFC.

1. Features:

(1). Use permanent circular buffers to stored data rather than resize data storage or memory copy 
(2). Scroll through time automatically
(3). Multi-line display with most property features at different time levels
(4). Multiple legends and data annotations
(5). Scroll and zooming
(6). Memory Device Context drawing
(7). Printing
 

2. History

From Nov. 1999 to May 2000, I involved to write a multithread real-time simulation application using MFC on Windows NT. It communicates with several processes running on different machines through TCP/IP. One of its features is real-time plotting, logging, and periodic background printing with data received from other processes.

However, the provided class, which has been rewritten using Win32 API completely rather than MFC, only implements part of the original MFC CRealTime class. Due to time constraints, logging, periodic background printing, read and write locking, and multithread features have not been rewritten. Therefore, those features are not included in the above class.

You are free to use or modify this class and to use it in any of your applications. But I make no guarantees about this class suitability for use. If there is any problem with anything I wrote, I will certainly try to help solve it.

3. Source Code

(1). ClassArr.h: template based class to implement dynamic array. It is similar to CArray in MFC but independent on MFC.

(2). Graphics.h and Graphics.cpp: property definition and drawing framework description.

(3). Random.h and Random.cpp: a portable subtractive pseudorandom number generator, which is faster than rand() in C Run time. It generates and simulates new data coming in.

(4). RealTime.h and RealTime.cpp: CGraphics derived component and contains most of the real-time plot source.

(4). Str.h and Str.cpp: Simple string class.

4. Demo Project

The RTDemo, which is an MFC MDI application, demonstrates how to use CRealTime. It uses a splitter window, which includes two views (one for plot and the other for legends and data annotations). Please note that running RTDemo needs MSFlex grid 6.0 control, which comes with VC6.0.

From the Edit menu, you can test open Insert, Delete, and Modify a line at run time. The Property menu includes grid, boundary, title, memory drawing, and back color properties. Kill and restore timer can be found in the View menu. Right click in the top view, the Timer Speed menu will popup, and you can select one of 10 timer speed levels. Also you can drag a vertical line on the slider bar by clicking the left mouse button.

About the Author

I am a senior software engineer for TechComm Simulation Pty Ltd., Sydney, Australia, where I specialise in Client/Server and TCP/IP programming on Unix and Windows NT. My e-mail address is yuantuh@techsim.com.au.

Downloads

Download demo project - 63 Kb
Download source - 18 Kb