编程

当前位置:澳门新莆京娱乐官网 > 编程 > MFC串口自动应答

MFC串口自动应答

来源:http://www.drgigabytes.com 作者:澳门新莆京娱乐官网 时间:2019-12-25 16:57
LPARAMCToolDlg::OnReceiveData(WPARAMch,LPARAMport){UpdateData(true);m_uReceiveBytes++;CStringstrTemp,iTemp;//BYTEiTemp=0;strTemp.Format("%d",m_uReceiveBytes);m_StrReceiveBytes=strTemp;if(m_bHexReceive){iTemp=DevideHexChar(ch);m_StrReceiveData+=iTemp+_T("");}elsem_StrReceiveData+=char(ch);UpdateData(false);((CEdit*)GetDlgItem(IDC_EDIT_RECEIVE_DATA))-LineScroll(m_StrReceiveData.GetLength()/(((CEdit*)GetDlgItem(IDC_EDIT_RECEIVE_DATA))-LineLength()));m_Wireless_BUFFER[m_bRevComm]=ch;//从下面开始解析串口传送过来的数据帧if((m_Wireless_BUFFER[0]==RF_Synchronization_Frame))//发现同步帧开始接受否则继续监听m_bRevComm++;else{Comm_Wireless_Modify.Clear_RxBuffer(m_Wireless_BUFFER,m_bRevComm);m_bRevComm=0;}if(m_bRevComm==2)//第二个字节不是RF_STX清除缓存{if(m_Wireless_BUFFER[1]!=RF_STX){Comm_Wireless_Modify.Clear_RxBuffer(m_Wireless_BUFFER,m_bRevComm);}}if(m_bRevComm2){if((m_bRevComm==(m_Wireless_BUFFER[2]+3))(m_Wireless_BUFFER[m_bRevComm-1]==0x03)){if((m_Wireless_BUFFER[3]==RF_RECEIVED_FRAME_ACK_CMD)(m_Wireless_BUFFER[7]==0x1f)){}Comm_Wireless_Modify.m_nCRC_Result=Comm_Wireless_Modify.CRC_New((m_Wireless_BUFFER[2])-2,(m_Wireless_BUFFER[2]));if(((Comm_Wireless_Modify.m_nCRC_Result8)==m_Wireless_BUFFER[m_bRevComm-2])((Comm_Wireless_Modify.m_nCRC_Result0xFF)==m_Wireless_BUFFER[m_bRevComm-3])){m_SerialPort.InitPort(this,MAX_SERIAL_PORT_NUM-1);switch(m_Wireless_BUFFER[3]){caseRF_ACK_CMD:break;caseRF_NACK_CMD:break;caseRF_RES_FW_VERSION_CMD:Comm_Wireless_Modify.Ack_NAck_All_Group_Fun(RF_ACK_CMD,AON_ACK_Length);break;caseRF_RECEIVED_FRAME_CMD:Comm_Wireless_Modify.Ack_NAck_All_Group_Fun(RF_ACK_CMD,AON_ACK_Length);switch(m_Wireless_BUFFER[10]){case0x12://读取实时温度,加含时间戳break;//读取实时温度信息case0x13:break;//读取实时温度信息case0x14:break;case0x15:break;case0x16:break;case0x17:break;//矫正0温度点default:break;}break;caseRF_RECEIVED_FRAME_ACK_CMD:Comm_Wireless_Modify.Ack_NAck_All_Group_Fun(RF_ACK_CMD,AON_ACK_Length);break;caseRF_ACK_SEND_CMD:Comm_Wireless_Modify.Ack_NAck_All_Group_Fun(RF_ACK_CMD,AON_ACK_Length);break;default:break;}}else{Comm_Wireless_Modify.Ack_NAck_All_Group_Fun(RF_NACK_CMD,AON_ACK_Length);}Comm_Wireless_Modify.Clear_RxBuffer(m_Wireless_BUFFER,m_bRevComm);}}return0;}

第一次写上位机调试软件,还请大家指教

如题,使用的是CserialPort类制作的一个小的串口调试工具,需要工具在接收到数据帧的时候能后自动应答。现在数据是成功的接收到了,但是发送好像总是不成功,哪位大侠可以指教一下。下面是原码:

本文由澳门新莆京娱乐官网发布于编程,转载请注明出处:MFC串口自动应答

关键词: