Serial port transmission structure is to convert the structure into an array and then transmit the char in the array.
That is, struct - - - - - - ->> char [ ] ;
Then char[ ] - - - -- - - - -->> struct .
Here is a simple example code:
#include #include /*--------------------------start file---------------------------------*/ typedef struct { int id; char name[10]; int score; }student; int struct_array(char* des, student *src) { int num; char *temp = (char *) src ; for(num=0;num return num; } void array_struct(student * des ,char * src) { char* temp = (char *) des; int num; for(num=0;num < sizeof(student);num++) *(temp++)= src[num]; } void show_student(student * name) { printf("id is : %dn",name->id); printf("name is : %sn",name->name); printf("score is : %d n",name->score); } void show_array(char *str, int len) { printf("len is : %d n" ,len); while(len--) { putchar('|'); putchar(*str++); } printf("|n"); } int main() { char name[10] = "laomao"; student laomao = { 123 , {"laomao"} , 99 } ; char save[100]; int len ; student * answer; len = struct_array(save, &laomao); show_array(save, len); array_struct(answer, save); show_student(answer); show_student(&laomao); return 0; } /*---------------------------end file----------------------------------*/ operation result: ------------------------------------------------------- len is : 20 |{| | | |l|a|o|m|a|o| | | | | | |c| | | | id is : 123 name is : laomao score is : 99 id is : 123 name is : laomao score is : 99 ---------------------------------------------------------------
Previous article:STC8 MCU + 8-pin OLED driver to display ADC value source program
Next article:Calculation of transmission time at different baud rates
Recommended ReadingLatest update time:2024-11-23 11:20
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- 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?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- 【Example】Conduction + radiation, rectification case!
- [Support eSports] Invite your friends to join the 19 National Competition Exchange Group and share a thousand-yuan cash gift!
- Overcurrent protection of power modules
- What is a hysteresis comparator?
- More than 20 commonly used power symbols
- [New CH554 Review-DIY] 7.USB-Host Routine Test
- 【Maturity Cycle】Maturity Cycle of Automotive Electronics Engineers
- Quartus12.0sof can be downloaded, but the generated .jic cannot be downloaded
- A collection of ESP32 experience posts. Netizens who are learning ESP32 can take a look.
- 883 Q What does Q stand for in the device identification?