basic skills
In this design, data processing can use powerful software such as MATLAB on PC, but this type of existing data processing software cannot directly control the lower computer acquisition module of the specific data acquisition system. Therefore, it is necessary to write corresponding upper computer software for the specific data acquisition system. The upper computer software is designed and written for the above purpose and is the control front end and data storage and processing center of the entire acquisition system. The control function mainly includes controlling the start and end of the lower computer acquisition, the frequency of acquisition, etc. The data processing function mainly includes drawing waveform graphs, displaying data in lists, and storing data in files. Storing data in files will facilitate the use of existing data processing software to perform some numerical algorithm processing on the data to achieve scientific research, conclusion verification, etc.
Development Environment
The C++ programming language can well implement object-oriented programming ideas. When using C++ to write the host computer program, each functional module can be encapsulated into a class. Modifying the implementation of a class and adding class functions will not affect the framework of the entire program, which makes it easy to maintain and expand functions. In addition, the software functions we want to implement require calling a large number of Windows API function libraries, so VC++6.0 is used as the development environment for the host computer.
Program function module division
The overall functional module mainly includes three modules, namely, HID device reading and writing module, data acquisition module, and data processing module.
Searching and reading and writing HID devices
(1) Enumeration
After the USB host detects that a USB device is plugged in, it will enumerate the device. Enumeration is to read some information from the device to know what kind of device it is and how to communicate, so that the host can load the appropriate driver based on this information.
(2)HID
Human Interface Device (HID) refers to devices that interact directly with people, such as mice and keyboards. In Windows, devices with similar properties and providing similar services are classified as one device type, and one type of device can use a universal device driver. On a PC running Windows 98 or higher, applications can use the HID class driver built into the operating system to communicate with the HID. This makes it easy to develop and run USB devices that comply with the HID class.
(3) Searching for HID devices
There are many HID-related API functions built into the Windows operating system. By calling these functions, you can start searching for the specified HID device. The ultimate goal of searching for the HID device is to obtain the path name of the device, the device's access capacity and other information, so as to prepare for future reading and writing of the device.
(4) Reading and writing HID devices
After obtaining the path of the HID device, you can start reading and writing the HID device. The reading and writing of the device is also achieved by calling the corresponding functions.
Control the lower computer to collect data
The upper computer sends commands to the lower computer, controls the lower computer to collect data, and obtains data from the lower computer. In this process, the synchronization of the two threads must be handled properly, that is, the data collection thread and the data processing thread can work in coordination to ensure that the system can work correctly and stably. The specific solution is to implement atomic operations on certain data accesses, that is, when one thread accesses public data, another thread cannot interrupt until the operation thread completes the operation and gives up the right to use the data, and then the other thread can access the data.
After the lower computer obtains the relevant parameters for collection, it can start collecting data, collecting data at a certain interval. When the number of collected data reaches the limit value, the collection is completed. At this time, the lower computer starts to send the collected data to the upper computer.
Processing of collected data by the host computer
After the upper computer sends the data acquisition command to the lower computer, all it has to do is wait for the lower computer to complete the acquisition and receive the data. Therefore, the upper computer will cyclically query the working status of the lower computer. Once it detects the sign that the lower computer has completed the acquisition, the upper computer will start processing the data.
There are three types of data processing:
(1) Draw a waveform graph
There are two requirements for drawing a waveform graph: first, it should not flicker frequently, which would affect observation; second, the waveform graph is dynamic, because the drawing area is limited, while the collected data is constantly increasing, so the waveform graph is required to be able to be updated dynamically.
(2) Add to list display
All data collected so far can be viewed intuitively.
(3) Save to file
Use powerful data processing software to process the data more deeply.
Interface display
Collecting unipolar sine wave working interface
Code:
1 HID device communication module implementation code /*hid.h header file*/
2 #ifndef HID_H
3 #define HID_H
4 #include
5 #include
6 #include
7 #include “commonuse.h”
8 using std::string;
9 #pragma comment( lib, “setupapi.lib” )
10 external “C” {
11 #include “hidsdi.h”
12 }
13 #pragma comment( lib, “hid.lib” )
14
15
16 class Hid
17 {
18
19 public:
20 Hid(const string &DeviceIdStr = MY_DEVICE_ID);
21 //Hid(DWORD Vid, DWORD Pid) {}
22 ~Hid() ;
23 BOOL Connect() ;
24 //BOOL ChangeDevice() {}
25 BOOL WriteHid(const BYTE * WriteBuff);
26 BOOL ReadHid(BYTE * ReadBuff);
27 BOOL IsWriteValid() const { return m_WriteValid ; }
28 BOOL IsReadValid() const { return m_ReadValid ; }
29 BOOL IsConnected() const { return m_IsConnected; }
30 const string & GetDeviceIDDesc() const { return m_DeviceIdStr ;}
31 private:
32 BOOL GetWRHandle() ;
33 private:
34 HANDLE m_WriteHandle;
35 HANDLE m_ReadHandle ;
36 string m_DeviceIdStr; //Device description string
37 DWORD m_PID;
38 DWORD m_VID;
39 BOOL m_IsConnected ; //Is it connected?
40 BOOL m_ReadValid; //Whether the read operation is possible
41 BOOL m_WriteValid; //Whether the write operation is possible
42 BYTE m_RWBuff[USB_BUFF_SIZE+1] ; // read and write buffer
43
44
45 } ;
46
47
48
49 #endif
50
51
52 /*hic.cpp source file*/
53
54 #include “Hid.h”
55
56 Hid::Hid(const string &DeviceIdStr):
57 m_DeviceIdStr(DeviceIdStr)
58 {
59
60 m_WriteHandle = INVALID_HANDLE_VALUE ;
61 m_ReadHandle = INVALID_HANDLE_VALUE ;
62 m_PID = 0;
63 m_WID = 0;
64 m_IsConnected = FALSE ;
65 m_ReadValid = FALSE ;
66 m_WriteValid = FALSE;
67 strcpy((char *)m_RWBuff,“”) ;
68 }
69
70 BOOL Hid::GetWRHandle()
71 {
72 GUID InterfaceClassGuid =
73 {0x4d1e55b2, 0xf16f, 0x11cf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30};
74 HDEVINFO DeviceInfoTable = INVALID_HANDLE_VALUE;
75 PSP_DEVICE_INTERFACE_DATA InterfaceDataStructure = new SP_DEVICE_INTERFACE_DATA;
76 PSP_DEVICE_INTERFACE_DETAIL_DATA DetailedInterfaceDataStructure = new SP_DEVICE_INTERFACE_DETAIL_DATA;
77 SP_DEVINFO_DATA DevInfoData;
78
79 DWORD InterfaceIndex = 0;
80 DWORD StatusLastError = 0;
81 DWORD dwRegType;
82 DWORD dwRegSize;
83 DWORD StructureSize = 0;
84 PBYTE PropertyValueBuffer;
85 bool MatchFound = false;
86 DWORD ErrorStatus;
87 DeviceInfoTable = SetupDiGetClassDevs(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT “ DIGCF_DEVICEINTERFACE);
88 while(true)
89 {
90 InterfaceDataStructure-》cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
91 if(SetupDiEnumDeviceInterfaces(DeviceInfoTable, NULL, &InterfaceClassGuid, InterfaceIndex, InterfaceDataStructure))
92 {
93 ErrorStatus = GetLastError();
94 if(ERROR_NO_MORE_ITEMS == ErrorStatus)
95 {
96 SetupDiDestroyDeviceInfoList(DeviceInfoTable);
97 return FALSE;
98 }
99 }
100 else
101 {
102
103 ErrorStatus = GetLastError();
104 SetupDiDestroyDeviceInfoList(DeviceInfoTable);
105 return FALSE;
106 }
107
108 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
109 SetupDiEnumDeviceInfo(DeviceInfoTable, InterfaceIndex, &DevInfoData);
110
111 SetupDiGetDeviceRegistryProperty(DeviceInfoTable, &DevInfoData, SPDRP_HARDWAREID, &dwRegType, NULL, 0, &dwRegSize);
112 Pr
Previous article:How to use PIC microcontroller to realize the function of timing stopwatch
Next article:The configuration word of the PIC microcontroller is defined using the CONFIG command
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Corporate Culture Sharing: How to cultivate scarce silicon IP professionals? SmartDV's journey of personal growth and teamwork
- Corporate Culture Sharing: How to cultivate scarce silicon IP professionals? SmartDV's journey of personal growth and teamwork
- NXP releases first ultra-wideband wireless battery management system solution
- NXP releases first ultra-wideband wireless battery management system solution
- Beijing Jiaotong University undergraduates explore Tektronix's advanced semiconductor open laboratory and experience the charm of cutting-edge high technology
- Beijing Jiaotong University undergraduates explore Tektronix's advanced semiconductor open laboratory and experience the charm of cutting-edge high technology
- New CEO: Dr. Torsten Derr will take over as CEO of SCHOTT AG on January 1, 2025
- How Edge AI Can Improve Everyday Experiences
- How Edge AI Can Improve Everyday Experiences
- Apple is going to launch first! TSMC announces that 2nm is ready
- [GD32L233C-START Review] Review 2: Library function analysis, GPIO lighting
- Applications of Optocouplers
- Design of an ultra-low power micro-ECG stethoscope
- GPS Tips
- Modeling and simulation of power electronics and motor control systems
- NMOS+PMOS controls battery voltage output
- Z-stack problem help
- EEWORLD University - Designing wide input DC/DC converters for smart lock applications
- Common field effect tube and transistor parameters
- VS1053 module