Click here to Skip to main content
15,861,125 members
Articles / Programming Languages / C++
Article

ECG for Windows XP (Export data to TXT files)

Rate me:
Please Sign up or sign in to vote.
3.67/5 (13 votes)
1 Sep 20045 min read 95.1K   6.1K   40   10
This is ECG_1.1 project version. Now the program can save medical records in to TXT files and can run on Windows XP.

Introduction

Finally I found some free time to make ECG_1 more useful. So now, ECG_1 application is running on Windows NT, XP, and 2000 operating systems, and can collect data in real time. To accomplish this, you must download and install free driver for low level in/out ports access. But functions are predefined. Because this is not the end version, I made it for friends who have to convert data from medical records in to TXT format.

And, let’s go… If you have questions, refer to my first article, ECG recording, storing, filtering and recognition.

The new things are: drvECG_1.dll and ECG_1.exe with capabilities to store data in a TXT file. First download and compile source files, or just download a demo project. To run NT Windows support you will need first to download a “DriverLINX Port I/O Driver for Win95 and WinNT” – it is free, and can be done after a registration here.

Sample screenshot

After this, you may need to install the driver, simply click on just downloaded file. In future I’m planning to build my own driver, but for this moment this one works well. Follow the instructions and confirm installation by clicking on Next button.

Do not change anything, just click Next.

Sample screenshot

After installing the port access driver, you need to restart the PC, this will be done automatically. After restarting the PC, you can start ECG_1 application by clicking on its icon - ECG_1.exe.

To use the program, you may need to open files with data. So use the download link to get an data.ecg file. After this, use the menu File->Open to open the open file name dialog.

Sample screenshot

Select a file data.ecg and click OK or Open. After this, you will be asked to confirm the record, so do this.

Sample screenshot

After this operation, the data.ecg file will be opened and you can move inside the records:

Sample screenshot

To save all records in to TXT format you need to use: File->ExportData->Export All Records to TXT, or if you want to export only the selected record to TXT file, use: File->ExportData->Export Current Record to TXT.

Sample screenshot

If you use Export Current Record, the program will show you the exact number of the selected records, so click OK.

Sample screenshot

After this, Save File dialog will be opened to ask you to specify the file name and location on the HDD.

Sample screenshot

So write a test file name and click OK to save the current record, or all the records to a TXT file. The separator between each point in the record is “ ; ”. Note this when opening TXT file. Now you can open the just saved TXT file to view it in notepad.

Sample screenshot

You can see the separators – “ ; “.

Now to use your data in Microsoft Excel program to perform some extra calculations on it, open MS Excel program and click on File->Open and select your just saved test.txt data file from ECG_1 program and follow the pictures. Because this TXT is a text file, and MS Excel does not support such files directly. You may need to specify in the Open File dialog that you need to see all files, so do it. After this, find on your HDD just saved data.txt file and click Open.

Sample screenshot

You need to go on a little procedure to accommodate TXT file in to Excel file. So click OK on the upper screen.

Sample screenshot

Check the Delimiter properties and click Next button.

Sample screenshot

Select the check box Other and in the input field write a “ ; “. Click Finish to accomplish the procedure.

Sample screenshot

Now your Excel will contain a single row of values. To make a graph from them go in the Insert Menu and select Chart.

Sample screenshot

Select chart type as it is shown on the upper picture, then you will need to click next and specify the data to draw.

Sample screenshot

To do this, click one tile in the data range field, and after this, click before row 1 to select all records in the first row. Click Finish.

Sample screenshot

Now you can make additional calculations on your file. Because Excel do not support larger data fields, you may need to use Math Cad to use TXT data for additional calculations. I’m not going to discuss this now. But try it. Now is time for some code. To see the full explanations, on ECG_1 code search for my first article in CodeProject. In ECG_1, I added some new functions to support data.TXT file saving.

//This function takes CString as a file name - "C:/mydocuments/data.ecg"
void CECG_Data::SaveDataTXT(CString File_Name)
{
            CFile sFile(File_Name,CFile::modeCreate|CFile::modeWrite);
            CArchive dArchive(&sFile,CArchive::store);
            //Serialize the arrays
            Serialize_DATA_TXT(&dArchive);
}

This function uses the next one function which is created to make the conversion to CString from CWordArray DATA array that is used in ECG.exe to store the medical records data.

void CECG_Data::Serialize_DATA_TXT(CArchive *ar)
{
            int i=0;
            CString str;
            CString stmp;
            DATA_TXT.RemoveAll();
            //This string is addet to te begining of the 
            //TXT file so to know what is the exact data in
            //this file if someone else open the txt file.
            str = "Start from ECG_1 data file;";
            //Now we go through the loop to convert 
            //each one CWordArray DATA value
            //in int variable.
            for(int j=0;j<DATA.GetSize();j++)
            {
                        stmp.Empty();
                        char ch[5];
                        i = int(short(DATA.GetAt(j)));
                        //This function converts an integer to a char array
                        _itoa(i, ch, 10 );
                        for(int k=0;k<4;k++)
                        {
                                  //To fit each one char value in a 
                                  //CString variable we make a 
                                  //short loop across char array
                                   stmp = stmp + ch[k];
                        }
                       //Current value is set in to a char array and 
                       //now we can add a separator - " ; "
                        stmp = stmp + ";";
                       //befor the end we add the stmp CString value 
                       //in the end aff str array
                        str = str + stmp;
            }
            //because DATA_TXT is a CStringArray, I use this to make 
            //easy serializing the txt data
            DATA_TXT.Add(str);
            //DATA_TXT is Serialized and saved in to a TXT file
            DATA_TXT.Serialize(*ar);
}

Important: This loop can take a lot of time!

This one converts CWordArray DATA array into one CStringArray DATA_TXT array. I’m using CStringArray instead of a single CString variable, because it doesn’t support Serialize function directly but CStringArray support it. One additional function is:

void CECG_Data::SaveCurDataRecTXT(CString File_Name)
{
            CFile sFile(File_Name,CFile::modeCreate|CFile::modeWrite);
            CArchive dArchive(&sFile,CArchive::store);
            //Serialize the arrays
            Serialize_Cor_DATA_TXT(&dArchive);
}

It saves the selected records only! But before using it, we set the current position in the data field – selected record.

void CECG_Data::SetCurSaveTXTPos(int pos)
{
            //sets the current record number
            save_to_txt_cur_rec_pos = pos;
}

Now we can serialize data in to TXT format. This function saves only the selected medical records into TXT file, so it takes much shorter time than the upper one.

void CECG_Data::Serialize_Cor_DATA_TXT(CArchive *dArchive)
{
            //Saves only selected data in a TXT file
            if(save_to_txt_cur_rec_pos+2500<=GetAllDataLenght())
            {
            int i=0;
            CString str;
            CString stmp;
            DATA_TXT.RemoveAll();
            str = "Start from ECG_1 data file;";
            for(int j=save_to_txt_cur_rec_pos;j<
                 save_to_txt_cur_rec_pos+2500;j++)
            {
                        stmp.Empty();
                        char ch[5];
                        i = int(short(DATA.GetAt(j)));
                        _itoa(i, ch, 10 );
                        for(int k=0;k<4;k++)
                        {
                                   stmp = stmp + ch[k];
                        }
                        stmp = stmp + ";";
                        str = str + stmp;
            }
            DATA_TXT.Add(str);
            DATA_TXT.Serialize(*dArchive);
            }
            else
            MessageBox(NULL,"Selected record to save out of data lenth.",
                     NULL,MB_OK);
}

Calculations on TXT files take a lot of time, so I made this feature in ECG.exe to support some of you with the ability to use my data files in Mat Lab, Mat Cad, Excel and other programs that you may use every day. But my opinion is that txt files are not a good choice for storing data. Many programs offer this capabilities and I found it useful to make this feature in ECG.exe.

History

  • 01.09.2004

    I added some useful features in ECG.exe, so now you can see signal spectrum. To do this, use check box (FFT) see the picture below.

    Sample screenshot

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Systems Engineer
Bulgaria Bulgaria
PhD, Cum Laude in digital automation systems
M.S. in Telemommunication management
B.S. in Telecommunication systems engineering
Programming: CUDA, C/C++, VHDL
Software and Hardware development and consulting:
data acquisition, image processing, medical instrumentation

Comments and Discussions

 
Generalsoftware error when fill form Pin
vitthalsangale20-Aug-10 17:52
vitthalsangale20-Aug-10 17:52 
QuestionMath. formula(s) for ECG emulation? Pin
WilfredoWilly14-Oct-09 8:39
WilfredoWilly14-Oct-09 8:39 
Questioneroor Pin
suweiti2-Mar-08 11:57
suweiti2-Mar-08 11:57 
QuestionError Pin
Gracee4-Apr-06 23:11
Gracee4-Apr-06 23:11 
AnswerRe: Error Pin
Georgi Petrov4-Apr-06 23:39
Georgi Petrov4-Apr-06 23:39 
GeneralError message Pin
cricripot31-May-05 21:35
cricripot31-May-05 21:35 
GeneralRe: Error message Pin
Georgi Petrov4-Jun-05 21:23
Georgi Petrov4-Jun-05 21:23 
GeneralRe: Error message Pin
sarah jacks13-Sep-06 18:54
sarah jacks13-Sep-06 18:54 
GeneralUnable to download the DriverLINX Port I/O Pin
Antonio Barros1-Sep-04 1:20
professionalAntonio Barros1-Sep-04 1:20 
GeneralRe: Unable to download the DriverLINX Port I/O Pin
Georgi Petrov2-Sep-04 3:41
Georgi Petrov2-Sep-04 3:41 
Dear friend,
instal VC++ environment, ecg.exe file is compiled to be small (if i include all files to ecg.exe file this will result to large exe file)

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.