📄 serialport.cpp
字号:
WriteCom((char*)(Band_command+5),5); //band
//115200: Band_command+5
//460800: Band_command+0
else if(band_select==4)
WriteCom((char*)(Band_command+5),5); //band
//WriteCom((char*)(Band_command+0),5);
stase=4;
break;
}
else if((*cCha==0x00) && stase==4)
{ ////// check return:0xc0 00
band_select= 115200;
//band_select=band_select * 115200;
if(ResetComPort(band_select,8, 1, 0))
{
WriteCom((char*)(command+9),1);//e9
stase=5;
}
//zero=1;
break;
}
else if((*cCha==0xffffffca) && stase==5)
{
if(*cCha==0xffffffca)
{
WriteCom((char*)(command+1),1); //E1
stase=6;
break;
}
} ///////// ->e9, <-ca
else if((*cCha==0xffffffc0) && stase==6)
{
if(*cCha==0xffffffc0)
{
//m_File00.Read(TempData,29);
//WriteCom((char*)(TempData),29);
WriteCom((char*)(command+10),29);
stase=7;
zero=0;
// progress=100;
break;
}
} ///////// ->e1, <-c0
/**********************进入测试模式***************************************
***********************进入测试模式***************************************
***********************进入测试模式**************************************/
else if((*cCha==0x00) && stase==7)///BLOCK000000 地址
{
zero++;
if(zero==12)// 9@9c:12 530:12
{
zero=0;
if(type==355)
{
//command[39]~~~~command[52] :write
//EA ,00 02 00 00 ,00 36 00 00 [add] ,00 02 00 00 [size]
command[41]=0x01;
command[45]=0x56; //add: 00 00 00
command[48]=0x00;
command[49]=0x01;
//command[49]=0x01; //00 01 c7 00
//command[50]=0xc7;
WriteCom((char*)(command+39),13);
}
stase=8;
break;
}
break;
}
else if((*cCha==0xffffffcb) && stase==8)///BLOCK000000 DATA
{
if(type==355)//9@9c block00
{
m_File00.Seek(0x0,CFile::begin);
stase=13;
}
if(type==355)
for(int m=0;m<8;m++)//128k
{
SetCommTimeouts( m_hCom, &timeouts );
m_File00.Read(TempData,1024*8);
WriteCom((char*)TempData,1024*8);//8k
}
break;
}
else if(stase==9)///BLOCK 地址
{
zero++;
if(zero==5)
{
zero=0;
if(type==991)
{
//command[39]~~~~command[52] :write
//EA ,00 02 00 00 ,00 36 00 00 [add] ,00 02 00 00 [size]
command[41]=0x02;
command[45]=0x74; //add: 00 00 00
command[48]=0x00;
command[49]=0x02;
//command[49]=0x01; //00 01 c7 00
//command[50]=0xc7;
WriteCom((char*)(command+39),13);
}
else if(type==998)
{
//command[39]~~~~command[52] :write
//EA ,00 02 00 00 ,00 36 00 00 [add] ,00 02 00 00 [size]
command[41]=0x01;
command[45]=0x3B; //add: 00 00 00
command[48]=0x00;
command[49]=0x01;
//command[49]=0x01; //00 01 c7 00
//command[50]=0xc7;
WriteCom((char*)(command+39),13);
}
else if(type==992)
{
//command[39]~~~~command[52] :write
//EA ,00 02 00 00 ,00 36 00 00 [add] ,00 02 00 00 [size]
command[41]=0x02;
command[45]=0x36; //add: 00 00 00
command[48]=0x00;
command[49]=0x02;
//command[49]=0x01; //00 01 c7 00
//command[50]=0xc7;
WriteCom((char*)(command+39),13);
}
else if(type==760)
{
//command[39]~~~~command[52] :write
//EA ,00 02 00 00 ,00 36 00 00 [add] ,00 02 00 00 [size]
command[41]=0x02;
command[45]=0x36; //add: 00 00 00
command[48]=0x00;
command[49]=0x02;
//command[49]=0x01; //00 01 c7 00
//command[50]=0xc7;
WriteCom((char*)(command+39),13);
}
stase=10;
break;
}
}
else if((*cCha==0xffffffcb) && stase==10)///BLOCK24 DATA
{
if(type==998)//350 block24
{
m_File00.Seek(0x60000,CFile::begin);
stase=13;
}
else if(type==991)//355 block
{
m_File00.Seek(0x20000,CFile::begin);
stase=13;
}
else if(type==992)//355 block
{
m_File00.Seek(0x90000,CFile::begin);
stase=11;
}
else if(type==760)//355 block
{
m_File00.Seek(0x130000,CFile::begin);
stase=11;
}
if(type==998)
for(int m=0;m<8;m++)//64k
{
SetCommTimeouts( m_hCom, &timeouts );
m_File00.Read(TempData,1024*8);
WriteCom((char*)TempData,1024*8);//8k
}
else if(type==991||type==992||type==760)
for(int m=0;m<16;m++)//128k
{
SetCommTimeouts( m_hCom, &timeouts );
m_File00.Read(TempData,1024*8);
WriteCom((char*)TempData,1024*8);//8k
}
break;
}
else if(stase==11)/// 地址//
{
zero++;
if(zero==5)
{
zero=0;
if(type==992)
{
//command[39]~~~~command[52] :write
//EA ,00 02 00 00 ,00 36 00 00 [add] ,00 02 00 00 [size]
command[41]=0x02;
command[45]=0x78; //add: 00 00 00
command[48]=0x00;
command[49]=0x02;
//command[49]=0x01; //00 01 c7 00
//command[50]=0xc7;
WriteCom((char*)(command+39),13);
}
if(type==760)
{
//command[39]~~~~command[52] :write
//EA ,00 02 00 00 ,00 36 00 00 [add] ,00 02 00 00 [size]
command[41]=0x02;
command[45]=0x78; //add: 00 00 00
command[48]=0x00;
command[49]=0x02;
//command[49]=0x01; //00 01 c7 00
//command[50]=0xc7;
WriteCom((char*)(command+39),13);
}
stase=12;
break;
}
}
else if((*cCha==0xffffffcb) && stase==12)///BLOCK000000 DATA
{
if(type==992)//350 block56
{
m_File00.Seek(0xb0000,CFile::begin);
stase=13;
}
else if(type==760)//350 block56
{
m_File00.Seek(0x150000,CFile::begin);
stase=13;
}
if(type==350||type==355||type==639)
for(int m=0;m<8;m++)//64k
{
SetCommTimeouts( m_hCom, &timeouts );
m_File00.Read(TempData,1024*8);
WriteCom((char*)TempData,1024*8);//8k
}
else if(type==992||type==760)
for(int m=0;m<16;m++)//128k
{
SetCommTimeouts( m_hCom, &timeouts );
m_File00.Read(TempData,1024*8);
WriteCom((char*)TempData,1024*8);//8k
}
break;
}
else if(stase==13)///关机指令
{
zero++;
if(zero==5)
{
zero=0;
WriteCom((char*)command+8,1);
stase=14;
if(m_hCom != NULL)
{
PurgeComm(m_hCom, PURGE_TXCLEAR);
PurgeComm(m_hCom, PURGE_RXCLEAR);
CloseHandle(m_hCom);
m_hCom = NULL;
}
ClearBuff();
stase=1;
//UCHAR stase[30]="改号成功.... 串口以关闭." ;
MessageBox(NULL,"改号成功.... 串口以关闭","PHILIPS",MB_OK);
//sjj_mj.m_Stase.SetWindowText((char*)stase);
m_File00.Close();
////////////////////////////////////////
/////////////////////////////////////////////////////////
// MessageBox(NULL,"请先正确选择型号!","PHILIPS",MB_OK);
StopMonitor();
break;
}
}
cCha++;
}
//&cCh=cChb;
////////////////////SELF
EnterCriticalSection(&m_csComSync);
m_CharList.AddTail(*cChb);//*cChb
if(m_CharList.GetCount() > 2048)
{
m_CharList.RemoveHead();
}
LeaveCriticalSection(&m_csComSync);
SetEvent(m_hCanReadEvent);
return TRUE;
}
/********************************************************************/
/** 功能: 接收缓冲区是否为空 */
/** 参数: 无 */
/** TRUE--是 */
/** FALSE--否 */
/********************************************************************/
BOOL CSerialPort::IsRecvBuffEmpty()
{
int nCount=0;
EnterCriticalSection(&m_csComSync);
nCount = m_CharList.GetCount();
LeaveCriticalSection(&m_csComSync);
if(nCount > 0)
{
return FALSE;
}
else
{
return TRUE;
}
}
/********************************************************************/
/** 功能: 开始监视串口 */
/** 参数: 无 */
/** TRUE--成功 */
/** FALSE--失败 */
/********************************************************************/
BOOL CSerialPort::StartMonitor()
{
if(!m_bInitComOk || m_bMonitoring)
{
return FALSE;
}
m_bMonitoring = FALSE;
//创建并挂起线程
m_pThread = AfxBeginThread(CommProcThread, this, THREAD_PRIORITY_NORMAL,
0, CREATE_SUSPENDED, NULL);
if(m_pThread == NULL)
{
CloseHandle(m_hCom);
return FALSE;
}
else
{
PurgeComm(m_hCom, PURGE_TXCLEAR);
PurgeComm(m_hCom, PURGE_RXCLEAR);
ClearBuff();
m_bMonitoring = TRUE;
//恢复线程运行
m_pThread->ResumeThread();
}
return TRUE;
}
/********************************************************************/
/** 功能: 停止监视串口 */
/** 参数: 无 */
/** TRUE--成功 */
/** FALSE--失败 */
/********************************************************************/
BOOL CSerialPort::StopMonitor()
{
if(!m_bInitComOk)
{
return FALSE;
}
if(m_bMonitoring)
{
m_bMonitoring = FALSE;
//结束CommProc线程中WaitSingleObject函数的等待
SetEvent(m_hCanReadEvent);
//结束CommProc线程中WaitCommEvent的等待
SetCommMask(m_hCom, 0);
//等待辅助线程终止
WaitForSingleObject(m_pThread->m_hThread, INFINITE);
m_pThread = NULL;
}
return TRUE;
}
/********************************************************************/
/** 功能: 初始化串口是否成功 */
/** 参数: 无 */
/** TRUE--是 */
/** FALSE--否 */
/********************************************************************/
BOOL CSerialPort::IsInitComOk()
{
return m_bInitComOk;
}
/********************************************************************/
/** 功能: 是否处于监视串口的状态 */
/** 参数: 无 */
/** TRUE--是 */
/** FALSE--否 */
/********************************************************************/
BOOL CSerialPort::IsInMonitor()
{
return m_bMonitoring;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -