Username:     
Password:     
             

Projects
ECGMonitor: USB PC Source Code for ECG Primer 1.0
 
This is the companion PC project for ECG Primer 1.0. It receives the USB ECG data (HID class) and displays the data on a window. You can modify it for your STM32 Primer USB application.

Code size:PC application Author:jingxizhang
Source files included:yes Version:1.0
Use circleOS:yes (circleOSversion) Creation date:2008-03-02 22:15:56
Hardware modification:no Modification date:2008-03-02 23:36:16
Based on the STM32 Primer:Primer1
   
Downloads:2328 Views:27158
   
Vote:
Average ratings:3/5 (937 rates)

Download:    ECGMonitor-USB-PC-Source-Code-for-ECG-Primer-1.0.zip (101 KB)

Description:
This is the companion PC project for ECG Primer 1.0. It receives the USB ECG data (HID class) and displays the data on a window. You can modify it for your STM32 Primer USB application. The program uses USB HID (Human Interface Device) class. Don’t be fooled by the class name. You can use the HID class to transmit many different data stream which have nothing to do with the human interface (ECG data is one example). Although it is a C# project (Visual Studio 2005), the system USB API calls are converted from C/C++. It can easily be adapted to C/C++ project.
 
Program structure:
- HIDPInvoke class converts the system device libraries from C to C#.
- HIDDevice is abstract class handles the USB device enumeration, receiving and sending HID reports.
- ECGDevice is the real class inherits from HIDDevice. It dispatches the data receiving event to the upper application layer.
- Report is abstract class for input and output reports.
- InputReport class inherits from Report class and is for the receiving data.
- OutputReport class inherits from Report class and is not used in this application (there is no data sending from host to device in this application).
- ECGForm is the application main GUI window. It contains a user control TraceView for drawing the ECG trace.
- TraceView is a user control class for drawing the ECG trace.
 
                                             Figure 1. Program structure
 
USB HID Device Enumeration:
The ECG Primer has to be plugged into the USB port before starting the application. The application searches for the ECG Primer device when it starts. The enumeration steps are shown in Figure 2.
                                   Figure 2. USB HID device enumeration steps
 
How do you make your own device handler?
You can use the ECGMonitor as the skeleton for handling your USB data. You can simply modify few things to make application work for you:
 
1. Change the vender id STM32_CIRCLE_ECG_VID and product id STM32_CIRCLE_ECG_VIP in the ECGForm for your need. I used in this example 0x0483 and 0x5810, respectively. In real product you should apply for the vendor id.
 
2. Modify the ECGForm event handler ECGDevice_OnInputReportDataReceived( ) for handling your own data: replay the following 2 lines with your own data handling function:
...
else
{
    ECGTraceView.AddDataAtEnd(filterProcess(args.data));
    ECGTraceView.Invalidate();
}
 
3. Make sure your vender id, product id and report descriptor defined your STM32 Primer application are match to the Host application.
 
4. Plug your STM32 Primer (the Primer application must started first, use either battery or the power from the debug USB port) into the PC USB port. Start your PC USB application. Voila, you have your STM32 Primer USB device working!
 

The ECGMonitor is adapted from Ashley Deakin’s article “Making USB C# friendly” and you may be interested to read the detail at www.vsj.co.uk/articles/display.asp.