版权声明
本资料为沈阳晏如电子技术有限公司专有财产,非经本公司之书面授权,不得透露或使用本资料,亦不得复印、复制或转换成其它任何形式。
公司名称:沈阳晏如电子有限公司 公司网址:www.yanrus.com
公司地址:辽宁省沈阳市沈北新区东北总部基地西六区20号楼1楼
01
通信协议与寄存器地址
寄存器地址和参数与具体的设备型号和功能有关,此处仅列出版本更新时的通用寄存器地址,获取详细的功能与寄存器映射,请在设备购买或定制完成后联系我们。
Part1. 读寄存器过程
发送请求 (Request)
| 从机地址 | 功能码 | 开始地址高位 | 开始地址低位 | 寄存器个数高位 | 寄存器个数低位 | CRC校验低位 | CRC校验高位 |
|---|---|---|---|---|---|---|---|
| 0x02 | 0x03 | XX | XX | XX | XX | CRCL | CRCH |
接收数据 (Response)
| 从机地址 | 功能码 | 返回的总字节数 | 寄存器数据内容 | ... | 寄存器数据内容 | CRC校验低位 | CRC校验高位 |
|---|---|---|---|---|---|---|---|
| 0x02 | 0x03 | XX | XX | XX | XX | CRCL | CRCH |
寄存器介绍 (Register)
| 地址 | 数据 | 描述 | 标准 | 大小 |
|---|---|---|---|---|
| 0x0000 | FIL_SC_H | 灯丝短路错误 | 0(Normal) 1(Fault) | 1 |
| 0x0001 | FIL_OI_H | 灯丝过流错误 | 0(Normal) 1(Fault) | 1 |
| 0x0002 | PREP_EN_STAT | 曝光使能状态1 | 0(Disable) 1(Enable) | 1 |
| 0x0003 | DRV_EN_STAT | 曝光使能状态2 | 0(Disable) 1(Enable) | 1 |
| 0x0004 | KV_OV | 千伏过压错误 | 0(Normal) 1(Fault) | 1 |
| 0x0005 | mA_OI | 毫安过流错误 | 0(Normal) 1(Fault) | 1 |
| 0x0006 | RI_OI | 谐振过流错误 | 0(Normal) 1(Fault) | 1 |
| 0x0007 | ARC | 打火错误 | 0(Normal) 1(Fault) | 1 |
| 0x0008 | STARTER_ERR | 阳极错误 | 0(Normal) 1(Fault) | 1 |
| 0x0009 | STARTER_HEAT | 阳极热量 | ret×1J | 16 |
| 0x000A | CONTATOR_STAT | 交流接触器状态 | 0(Off) 1(On) | 1 |
| 0x000B | BEAMFAULT | 系统总体错误 | 0(Normal) 1(Fault) | 1 |
| 0x000C | EXP_DUTY_STAT | 曝光占空比标志 | 0(Normal) 1(Busy) | 16 |
| 0x000D | DC_BUS | 母线电压 | ret×1V | 16 |
| 0x000E | KV_FB | 千伏反馈 | ret×10kV | 16 |
| 0x000F | mA_FB | 毫安反馈 | ret×100mA | 16 |
| 0x0010 | FIL_FB | 灯丝反馈 | ret×100A | 16 |
| 0x0011 | TIME_FB_low | 曝光时间反馈低位 | (65536×reth+retl)×1ms | 16 |
| 0x0012 | TIME_FB_high | 曝光时间反馈高位 | (65536×reth+retl)×1ms | 16 |
| 0x0013 | TEMP_INV | 逆变温度反馈 | ret×1℃ | 8 |
| 0x0014 | TEMP_TANK | 油温度反馈 | ret×1℃ | 8 |
| 0x0015 | WORK_MODE_FB | 工作状态反馈 | 0(Burst) 1(Pulse) | 1 |
| 0x0016 | DEV_ID0_High | 射线系统序列号高位 | string | 16 |
| 0x0017 | DEV_ID0_Low | 射线系统序列号低位 | string | 16 |
| 0x0018 | LASER_CM | 激光测距反馈 | ret×1cm | 16 |
| 0x0019 | ExpTimesSumH | 曝光时间汇总 | (65536×reth+retl)×1ms | 16 |
| 0x001A | ExpTimesSumL | 曝光时间汇总 | (65536×reth+retl)×1ms | 16 |
| 0x001B | ExpTimeSum | 曝光次数汇总 | ret×1 | 16 |
| 0x001C | Power_FB | 主机电源反馈 | ret×1 | 0 |
| 0x001D | Keep_For_System | 系统保留 | None | 0 |
| 0x001E | Keep_For_System | 系统保留 | None | 0 |
| 0x001F | Keep_For_System | 系统保留 | None | 0 |
Part2. 写寄存器过程
发送请求 (Request)
| 从机地址 | 功能码 | 写寄存器地址高位 | 写寄存器地址低位 | 写数据高位 | 写数据低位 | CRC校验低位 | CRC校验高位 |
|---|---|---|---|---|---|---|---|
| 0x02 | 0x06 | XX | XX | XX | XX | CRCL | CRCH |
接收数据 (Response)
| 从机地址 | 功能码 | 写寄存器地址高位 | 写寄存器地址低位 | 写数据高位 | 写数据低位 | CRC校验低位 | CRC校验高位 |
|---|---|---|---|---|---|---|---|
| 0x02 | 0x06 | XX | XX | XX | XX | CRCL | CRCH |
寄存器 (Register)
| 地址 | 数据 | 描述 | 标准 | 大小 |
|---|---|---|---|---|
| 0x0020 | Keep_For_System | 系统保留 | None | 1 |
| 0x0021 | INV_DRV_EN | 逆变驱动使能 | 0(Disable) 1(Enable) | 1 |
| 0x0022 | FIL_DRV_EN | 灯丝驱动使能 | 0(Disable) 1(Enable) | 1 |
| 0x0023 | HV_RST | 错误复位 | 0(Disable) 1(Enable) | 1 |
| 0x0024 | KV_REF | 千伏设定 | ret×10kV | 16 |
| 0x0025 | mA_REF | 毫安设定 | ret×100mA | 16 |
| 0x0026 | FIL_REF | 灯丝设定 | ret×100A | 16 |
| 0x0027 | TIME_REF_low | 曝光时间设定低位 | (65536×reth+retl)×1ms | 16 |
| 0x0028 | TIME_REF_high | 曝光时间设定高位 | (65536×reth+retl)×1ms | 4 |
| 0x0029 | UART_PARA_SEL | 串口使能 | 0(LCD) 1(Usart) 2(WIFI) | 1 |
| 0x002A | CONTACTOR_ON | 开机命令 | 0(Off) 1(On) | 1 |
| 0x002B | FPGA_FIL_SEL | 灯丝选择控制 | 0(Big FIL) 1(Small FIL) | 1 |
| 0x002C | FIL_CTRL_EN | 灯丝闭环控制 | 0(Disable) 1(Enable) | 1 |
| 0x002D | P_FIL | 灯丝P | ret | 16 |
| 0x002E | I_FIL | 灯丝I | ret | 16 |
| 0x002F | D_FIL | 灯丝D | ret | 16 |
| 0x0030 | KV_CTRL_EN | 千伏闭环控制 | 0(Disable) 1(Enable) | 1 |
| 0x0031 | P_KV | 千伏P | ret | 16 |
| 0x0032 | I_KV | 千伏I | ret | 16 |
| 0x0033 | D_KV | 千伏D | ret | 16 |
| 0x0034 | mA_CTRL_EN | 毫安闭环控制 | 0(Disable) 1(Enable) | 1 |
| 0x0035 | P_mA | 毫安P | ret | 16 |
| 0x0036 | I_mA | 毫安I | ret | 16 |
| 0x0037 | D_mA | 毫安D | ret | 16 |
| 0x0038 | Keep_For_System | 系统保留 | None | 16 |
| 0x0039 | Keep_For_System | 系统保留 | None | 16 |
| 0x003A | LIGHT_ON | 视野灯信号 | 0(Disable) 1(Enable) | 1 |
| 0x003B | Laser_ON | 测距使能信号 | 0(Disable) 1(Enable) | 1 |
| 0x003C | Max_Power | 最大功率使能信号 | 0(Disable) 1(Enable) | 1 |
| 0x003D | Delay_ExpTimes | 延迟时间设定 | ret×1s | 16 |
| 0x003E | Keep_For_System | 系统保留 | None | 0 |
| 0x003F | Keep_For_System | 系统保留 | None | 0 |
02
开发注意事项
Part1. 主要数据范围
| 主要数据 | 单位 | 最大值 | 最小值 | 分度值 | 设置标准 |
|---|---|---|---|---|---|
| 千伏反馈 | kV | 90 | 10 | 1 | ret×10kV |
| 毫安反馈 | mA | 10 | 0.1 | 0.1 | ret×100mA |
| 灯丝反馈 | A | 2.5 | 0 | 0.01 | ret×100A |
| 曝光时间反馈 | ms | 5000 | 0 | 1 | (65536×reth+retl)×1ms |
| 逆变温度反馈 | ℃ | 60 | 0 | 1 | ret×1℃ |
| 千伏设定 | kV | 90 | 10 | 1 | ret×10kV |
| 毫安设定 | mA | 10 | 0.1 | 0.1 | ret×100mA |
| 灯丝设定 | A | 1.2 | 0 | 0.01 | ret×100A |
| 曝光时间设定 | ms | 5000 | 0 | 1 | (65536×reth+retl)×1ms |
| 激光测距反馈 | cm | 200 | 0 | 1 | ret×1cm |
| 曝光时间汇总 | s | / | / | 1 | (65536×reth+retl)×1s |
| 曝光次数汇总 | / | / | / | 1 | ret×1 |
Part2. 开发注意事项
通信连接 (Connect)
| 通信方式 | 注意事项 |
|---|---|
| Usart | 串口的通信方式已经由配套的屏幕统一完成,其通信协议与前通信协议部分不同,参数:8位数据位,1位停止位,波特率为115200 |
| WIFI | 网络的通信方式需要配置网络端口为10.10.100.254:8899,通信协议遵循前通信协议部分 |
两种通信方式不可同时使能,默认为网络的通信方式,如需更改请根据需求进行参数配置。
参数与流程配置 (Configuration)
| 配置步骤 | 配置寄存器 | 注意 |
|---|---|---|
| 开启设备 | 0x002A | 无 |
| ID与PID参数确定 | 0x002C至0x0037 | 对于不支持此功能的设备可以跳过 |
| 错误复位 | 0x0023 | 无 |
| 配置通信方式 | 0x0029 | 如果需要进行更改且设备支持此功能可进行更改 |
| 配置千伏 | 0x0024 | 无 |
| 配置毫安 | 0x0025 | 无 |
| 配置曝光时间 | 0x0027至0x0028 | 无 |
| 配置灯丝 | 0x002B和0x0026 | 无 |
| 打开灯丝 | 0x0020和0x0022 | 如果参数设置过大此处会出现报错 |
| 开始曝光 | 0x0020至0x0021 | 如果参数设置过大此处会出现报错 |
| 关闭灯丝 | 0x0020和0x0022 | 无 |
| 关闭曝光 | 0x0020至0x0021 | 无 |
配置过程中若发生报错提醒,则需要进行错误复位后才可继续进行后续配置。若在打开灯丝后发生报错提醒,则需要额外关闭灯丝再进行操作。
使用过程中需要注意,设备需要以1:30的占空比进行休息。
心跳信号 (Heartbeat)
虽然通信过程中无严格要求的心跳信号,此处还是建议以一定频率获取全部寄存器的数据,以保证准时发现错误信号。
具体的寄存器获取频率无具体要求,需要根据实际情况进行设置,确保通信正常即可。
本设备在通信上为从机设备,需要接收到正确的主机命令才会有反馈,无主机信号发送或信号命令错误时均无信号返回。
校验算法 (CRC Validation)
unsigned short int CRC_Test(unsigned char* HEX, int len) { unsigned short int ret = 0xFFFF; unsigned char i; while(len--){ ret ^= *HEX++; for(i = 0; i < 8; i++){ if(ret & 0x0001) ret = (ret >> 1) ^ 0xA001; else ret >>= 1; } } return ret; }
03
开发指南
Part1. 数据结构
typedef enum { State_Wait = 0x00, // The data is suspended in this state State_Ready = 0x01, // The data is ready in this state State_Run = 0x02 // The data is processed in this state } Data_StateTypedef; typedef struct Dev_Data { Data_StateTypedef state; // Current status of Dev_Data unsigned short int data; // Data of Dev_Data unsigned short int Address; // Address of Dev_Data unsigned char Arr[200]; // The data buffer of Dev_Data void (*Data_Deal)(void); // Dev_Data's data processing function } Dev_Data;
Part2. 辅助函数
// CRC check function // HEX : Pointer to input data // len : Length of the input data // return : CRC Results unsigned short int CRC_Test(unsigned char *HEX, int len) { unsigned short int ret = 0xFFFF; unsigned char i; while(len--) { ret ^= *HEX++; for(i = 0; i < 8; i++) { if(ret & 0x0001) ret = (ret >> 1) ^ 0xA001; else ret >>= 1; } } return ret; } // Check whether the two HEX data are consistent // str1 : Pointer to input data1 // len1 : Length of the input data1 // str2 : Pointer to input data2 // len2 : Length of the input data2 // return : Check Results unsigned char My_StrStr(unsigned char *str1, int len1, unsigned char *str2, int len2) { int i, j; if(len1 <= 0 || len2 <= 0) return 0; if(len2 > len1) return 0; for(i = 0; i <= len1 - len2; i++) { for(j = 0; j < len2; j++) if(str1[i + j] != str2[j]) break; if(j == len2) return 1; } return 0; } // Send data to the device // Address : Address of the target data // Wdata : Target data // pData : Sent and returned data // return : None void SendDataToDev(unsigned short int Address, unsigned short int Wdata, unsigned char *pData) { unsigned short int CRC_Da; unsigned int i; pData[0] = 0x02; pData[1] = 0x06; pData[2] = (unsigned char)((Address & 0xFF00) >> 8); pData[3] = (unsigned char)(Address & 0x00FF); pData[4] = (unsigned char)((Wdata & 0xFF00) >> 8); pData[5] = (unsigned char)(Wdata & 0x00FF); CRC_Da = CRC_Test(pData, 6); pData[6] = (unsigned char)(CRC_Da & 0x00FF); pData[7] = (unsigned char)((CRC_Da & 0xFF00) >> 8); // Send characters one by one on Serial Port 2 for(i = 0; i < 8; i++) Usart2_SendByte(pData[i]); } // Get data from the device // return : None void GetDataFromDev(void) { unsigned char data[8]; unsigned short int CRC_Da; unsigned int i; data[0] = 0x02; data[1] = 0x03; data[2] = 0x00; data[3] = 0x00; data[4] = 0x00; data[5] = 0x40; CRC_Da = CRC_Test(data, 6); data[6] = (unsigned char)(CRC_Da & 0x00FF); data[7] = (unsigned char)((CRC_Da & 0xFF00) >> 8); // Send characters one by one on Serial Port 2 for(i = 0; i < 8; i++) Usart2_SendByte(data[i]); }
Part3. 数据发送
// Define a global variable, here taking Contator_On as an example Dev_Data Contator_On; void ops_Contator_On(void) // Contator_On's data processing function { // If the data is suspended, return immediately if(Contator_On.state == State_Wait) { return; } // If the data is in the ready state, send the data if(Contator_On.state == State_Ready) { // Send the data Contator_On.data to the address Contator_On.Address // Retrieve the data into Contator_On.Arr SendDataToDev(Contator_On.Address,Contator_On.data,Contator_On.Arr); // Data transmission completed, preparation for data processing Contator_On.state = State_Run; return; } // If the data is in a running state, process it if(Contator_On.state == State_Run) { // The feedback received is incorrect, resend the data // Dev_UsartData_buf is the content of the current serial port buffer // Dev_len_buf is the length of the existing data if(My_StrStr(Dev_UsartData_buf,Dev_len_buf,Contator_On.Arr,8) == 0x00) SendDataToDev(Contator_On.Address,Contator_On.data,Contator_On.Arr); else { // You can perform related operations here // TODO : Some operations you need // This example shows printing 'Contator_On Finish' on Serial Usart1 Usart1_Printf("Contator_On Finish\n"); // Suspend the status Contator_On.state = State_Wait; } return; } } void DevData_Init(void) { // The Address of Contator_On is 0x002A (Chapter 1 Part 2) Contator_On.Address = 0x002A; // The data of Contator_On will be initialized to 0x00 Contator_On.data = 0x0000; // The data is suspended Contator_On.state = State_Wait; // Initialize data processing pointer Contator_On.Data_Deal = ops_Contator_On; } // You also need a signal to notify the ops function to enter State_Ready // Here, taking key detection as an example // This is the timer interrupt function unsigned char last_State1 = 0x00; // Local variable for key detection unsigned char State1 = 0x00; // Local variable for key detection void TIM2_IRQHandler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET) { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); last_State1 = State1; State1 = (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == Bit_RESET) ? 0x01 : 0x00; // Rising edge detected if((State1 == 0x01)&&(last_State1 == 0x00)) { // The data is assigned the value 0x0001 and enters the ready state Contator_On.state = State_Ready; Contator_On.data = 0x0001; } } } // You need to loop the corresponding ops function in the main function int main(void) { DevData_Init(); Usart1_Init(); Usart2_Init(); Tim2_Init(); while(1) { Contator_On.Data_Deal(); // You also need to take relevant measures to prevent data overflow. // Here is a caching mechanism provided as an example memset(Dev_UsartData_buf,0x00,500); Dev_len_buf = Dev_len; memcpy(Dev_UsartData_buf,Dev_UsartData,500); memset(Dev_UsartData,0x00,500); Dev_len = 0; } }
Part4. 数据处理
// For convenience, the original data structure is used here. Dev_Data Get_Data_Deal; void ops_Get_Data_Deal(void) // Get_Data_Deal's data processing function { // If the data is suspended, return immediately if(Get_Data_Deal.state == State_Wait) { return; } // If the data is in the ready state, send the data if(Get_Data_Deal.state == State_Ready) { // Send a request to get data GetDataFromDev(); // Data transmission completed, preparation for data processing Get_Data_Deal.state = State_Run; return; } // If the data is in a running state, process it if(Get_Data_Deal.state == State_Run) { // Calculate the actual checksum based on the previous data unsigned short int CRC_Text = CRC_Test(Get_Data_Deal.Arr,131); // Obtain the CRC checksum from the data packet unsigned short int CRC_EE = (unsigned short int)Get_Data_Deal.Arr[131] + (unsigned short int)Get_Data_Deal.Arr[132]*256; // Verification failed, resend the request to obtain data if(CRC_Text != CRC_EE) { GetDataFromDev(); return; } // Verification passed, you can handle your data here // TODO : Some operations you need // This example shows printing 'Get_Data Finish' on Usart1 Usart1_Printf("Get_Data Finish\n"); // Destroy the check bits to prevent the data from being reused Get_Data_Deal.Arr[132] = 0x00; Get_Data_Deal.Arr[133] = 0x00; // Suspend the status Get_Data_Deal.state = State_Wait; return; } } void DevData_Init(void) { // Since there is no address and no data to write, no assignment is made here directly. Get_Data_Deal.state = State_Wait; // The data is suspended Get_Data_Deal.Data_Deal = ops_Get_Data_Deal; // Initialize data processing pointer } // For convenience, the function enabled by this button is set to a single query. // This is the timer interrupt function unsigned char last_State1 = 0x00; // Local variable for key detection unsigned char State1 = 0x00; // Local variable for key detection void TIM2_IRQHandler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET) { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); last_State1 = State1; State1 = (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == Bit_RESET) ? 0x01 : 0x00; // Rising edge detected if((State1 == 0x01)&&(last_State1 == 0x00)) { // Set the ops for obtaining data to ready state Get_Data_Deal.state = State_Ready; } } } // You need to loop the corresponding ops function in the main function int main(void) { DevData_Init(); Usart1_Init(); Usart2_Init(); Tim2_Init(); while(1) { Get_Data_Deal.Data_Deal(); // You also need to take relevant measures to prevent data overflow. // Here is a caching mechanism provided as an example memset(Dev_UsartData_buf,0x00,500); Dev_len_buf = Dev_len; memcpy(Dev_UsartData_buf,Dev_UsartData,500); memset(Dev_UsartData,0x00,500); Dev_len = 0; } }
Part5. 数据处理技巧
// Here is the data processing method of our other device // You can refer to this kind of handling technique // This union takes advantage of memory continuity and defines 133 pieces of data for the query protocol. // You'd better update this union according to the agreement of the version you are using. // The keyword '__pack' indicates that data is tightly packed typedef union Type_Rx_Data{ __packed struct{ unsigned char hand0; unsigned char hand1; unsigned char hand2; unsigned short int p00_FIL_SC_H; unsigned short int p01_FIL_OI_H; unsigned short int p02_PREP_EN_STAT; unsigned short int p03_DRV_EN_STAT; unsigned short int p04_KV_OV; unsigned short int p05_mA_OI; unsigned short int p06_RI_OI; unsigned short int p07_ARC; unsigned short int p08_STARTER_ERR; unsigned short int p09_STARTER_HEAT; unsigned short int p0A_CONTATOR_STAT; unsigned short int p0B_BEAMFAULT; unsigned short int p0C_EXP_DUTY_STAT; unsigned short int p0D_DC_BUS; unsigned short int p0E_KV_FB; unsigned short int p0F_mA_FB; unsigned short int p10_FIL_FB; unsigned short int p11_TIME_FB_low; unsigned short int p12_TIME_FB_high; unsigned short int p13_TEMP_INV; unsigned short int p14_TEMP_TANK; unsigned short int p15_WORK_MODE_FB; unsigned short int p16_DEV_ID0_High; unsigned short int p17_DEV_ID0_Low; unsigned short int p18_LASER_CM; unsigned short int p19_ExpTimesSumH; unsigned short int p1A_ExpTimesSumL; unsigned short int p1B_ExpTimeSum; unsigned short int p1C_Power_FB; unsigned short int p1D_Keep_For_System; unsigned short int p1E_Keep_For_System; unsigned short int p1F_Keep_For_System; unsigned short int p20_Keep_For_System; unsigned short int p21_INV_DRV_EN; unsigned short int p22_FIL_DRV_EN; unsigned short int p23_HV_RST; unsigned short int p24_KV_REF; unsigned short int p25_mA_REF; unsigned short int p26_FIL_REF; unsigned short int p27_TIME_REF_low; unsigned short int p28_TIME_REF_high; unsigned short int p29_UART_PARA_SEL; unsigned short int p2A_CONTACTOR_ON; unsigned short int p2B_FPGA_FIL_SEL; unsigned short int p2C_FIL_CTRL_EN; unsigned short int p2D_P_FIL; unsigned short int p2E_I_FIL; unsigned short int p2F_D_FIL; unsigned short int p30_KV_CTRL_EN; unsigned short int p31_P_KV; unsigned short int p32_I_KV; unsigned short int p33_D_KV; unsigned short int p34_mA_CTRL_EN; unsigned short int p35_P_mA; unsigned short int p36_I_mA; unsigned short int p37_D_mA; unsigned short int p38_Keep_For_System; unsigned short int p39_Keep_For_System; unsigned short int p3A_LIGHT_ON; unsigned short int p3B_Laser_ON; unsigned short int p3C_Max_Power; unsigned short int p3D_Delay_ExpTimes; unsigned short int p3E_Keep_For_System; unsigned short int p3F_Keep_For_System; unsigned char CRCL; unsigned char CRCH; }val; unsigned char data[133]; }Rx_Data_t; // You can use a FSM to obtain all 133 pieces of data // This is the interrupt function for UART1 // Directly received data for Set data unsigned char Dev_UsartData[500] = {0x00}; // Receive Data Buffer for Set data unsigned char Dev_UsartData_buf[500] = {0x00}; // Directly received data for Get data Rx_Data_t Rx_Data; // Receive Data Buffer for Get data Rx_Data_t Rx_Data1; // Data Receiving Status unsigned char Rx_State = 0x00; // Number of valid data already received unsigned char Rx_Wei = 3; void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1, USART_IT_RXNE) == SET) USART_ClearITPendingBit(USART1, USART_IT_RXNE); // Obtain the data received this time Dev_UsartData[Dev_len] = USART_ReceiveData(USART1); // Select according to the current reception status for Get data switch(Rx_State) { // No valid data received case 0x00: { // Received the first valid data, exit the loop if(Dev_UsartData[Dev_len] == 0x02) Rx_State = 0x01; break; } // A valid data has already been received case 0x01: { // Received the second valid data, exit the loop if(Dev_UsartData[Dev_len] == 0x03) Rx_State = 0x02; // Otherwise, the data is invalid else Rx_State = 0x00; break; } // Packet header data is valid, ready to receive case 0x02: { // Number of data received if(Dev_UsartData[Dev_len] == 0x80) { // Assign values to the data packet header of the data structure // and prepare to receive the valid data section Rx_State = 0x03; Rx_Data.data[0] = 0x02; Rx_Data.data[1] = 0x03; Rx_Data.data[2] = 0x80; Rx_Wei = 3; } // Otherwise, the data is invalid else Rx_State = 0x00; break; } // Receive valid data case 0x03: { // Write valid data one after another Rx_Data.data[Rx_Wei] = Dev_UsartData[Dev_len]; Rx_Wei++; // Data reception complete, updated to cache if(Rx_Wei >= 134) { Rx_Wei = 3; Rx_State = 0x00; memcpy(Get_Data_Deal.Arr,Rx_Data.data,133); memcpy(Rx_Data1.data,Rx_Data.data,133); } break; } } // Ensure that the setting data reception is not affected if(Dev_len < 450) Dev_len ++; } // Macro for fetching data // Choose according to your device situation // Little-endian #define Get_RX(data_x) (((Rx_Data1.val.data_x&0xFF00)>>8)|((Rx_Data1.val.data_x&0x00FF)<<8)) // Big-endian #define Get_RX(data_x) Rx_Data1.val.data_x // You can read the data of FIL_SC_H in the following way unsigned short int FIL_SC_H = Get_RX(p00_FIL_SC_H);
04
文件修正记录
| 版本 | 生效日期 | 修订部门 | 修订人 | 修订说明 |
|---|---|---|---|---|
| V1.0 | 2023.11.05 | 研发部 | Homer | 创建 |
| V1.1 | 2025.11.03 | 研发部 | XiaoFei | 修改 |
| V1.4 | 2025.11.29 | 研发部 | XiaoFei | 修改 |
| V1.6 | 2026.05.13 | 研发部 | XiaoFei | 修改 |