⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ascend_smsdlg.cpp

📁 GSM 模块软件开发包 开发包说明 开发包基于GSM模块开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					if(strcmp(Tmp,"")!=0){
					   pDlg->AddtoReceiveList(Tmp);
					}
				}
				UnSendNum = GetUnSendCount(OpenPortNum);	//Retreive the number of message remained
				sprintf(TmpStr,"%d",UnSendNum);
				pDlg->m_Num.SetWindowText(TmpStr);
				break ;
			}
			case WAIT_ABANDONED:
				Sleep(1);
				break ;
		}
	}
}

//OnBtnOpen, Functions:Open the module on the comm port.
void CAscend_SMSDlg::OnBtnOpen() 
{
	// TODO: Add your control notification handler code here
	char str[64];memset(str,0x00,64);	
	char SerialNo[20]; memset(SerialNo,0x00,20);
	DWORD dwWaitResult ;

	if(PortNum==0)
		m_Status.SetWindowText("Select a Serial Com Number!");
	else if(PortIsOpened)
		m_Status.SetWindowText("Module already opened,please close it first!");
	else
	{
		IRtn = OpenComm(PortNum);	//Open Module
		GetSerialNo(PortNum,SerialNo);
		if(IRtn!=0){
			memset(str,0x00,64);

			if(IRtn==-5){
				sprintf(str,"GSM module register error!SN:%s",SerialNo);
			}else if(IRtn==-6){
				sprintf(str,"COM port open error!SN:%s",SerialNo);
			}else if(IRtn==-9){
				sprintf(str,"No GSM module found!SN:%s",SerialNo);
			}else if(IRtn==-10){
				sprintf(str,"Setup moduel parameters fail!SN:%s",SerialNo);
			}else if(IRtn==-11){
				sprintf(str,"Save module parameters fail!SN:%s",SerialNo);
			}
			m_Status.SetWindowText(str);
		}
		else{
			OpenPortNum=PortNum;
			PortIsOpened=true;
			memset(str,0x00,64);

			sprintf(str,"Module on port %d opened success!SN:%s",OpenPortNum,SerialNo);
			m_Status.SetWindowText(str);
			dwWaitResult = WaitForSingleObject(hMutex , INFINITE);

	   		AfxBeginThread(RcvMsg,"" );		//Start receiving thread
		}
	}
}

//OnOK, Send message
void CAscend_SMSDlg::OnOK() 
{
	// TODO: Add extra validation here
	CString str;static bool IsFirst=true;
	char TStr[24]; char TMsg[256];
	memset(TStr,0x00,24);memset(TMsg,0x00,256);

    m_Phone.GetWindowText(str);
	strcpy(TStr,(LPCTSTR)str);
    m_Msg.GetWindowText(str);
	strcpy(TMsg,(LPCTSTR)str);

	if(PortIsOpened){
		if((CodeMode==CM_Chinese)||(CodeMode==CM_Unicode))
			IRtn = SendMsg(OpenPortNum,TMsg,TStr,1,true);	//Send Chinese message
		else if((CodeMode==CM_English)||(CodeMode==CM_Bit7))
			IRtn = SendMsg(OpenPortNum,TMsg,TStr,1,false);	//Send English message
		else {
			MessageBox("Please open module first!",NULL,MB_OK);
			return;
		}
		switch( IRtn ){
			case  0 :
				m_Status.SetWindowText("Send message success!");
				break;
			case -2 :
					m_Status.SetWindowText("Too long a message! Send fail!");
					break;
			case -3 :
					m_Status.SetWindowText("Error with mobile number! Send fail!");
					break;
			case -4 :
					m_Status.SetWindowText("Error with Send buffer full! Send fail!");
					break;
			case -8 :
					m_Status.SetWindowText("Error with unopen module! Send fail!");
					break;
			default :
					m_Status.SetWindowText("Other error! Send fail!");
					break;
		}

	}
	else
		MessageBox("Please open module first!",NULL,MB_OK);
}

void CAscend_SMSDlg::OnCancel()
{
	// TODO: Add extra cleanup here
	CDialog::OnCancel();
}

//Close Module
void CAscend_SMSDlg::OnBtnClose() 
{
	// TODO: Add your control notification handler code here
	int UnSendNum = 0;
	if(PortIsOpened){
		UnSendNum = GetUnSendCount(OpenPortNum); 
		if(UnSendNum!=0){
			MessageBox("Undeal message still in list. Please close later!",NULL,MB_OK);
		}
		else{
			ReleaseMutex(hMutex);
			Sleep(700);
			IRtn = CloseComm(OpenPortNum);		//Close module
			if(IRtn==0){
				m_Status.SetWindowText("Module closed success!");
			}
			else 
				m_Status.SetWindowText("Close Module fail!");
			PortIsOpened=false;
		}
	}
	else
		m_Status.SetWindowText("None Module is opened! Close fail!");
}

void CAscend_SMSDlg::OnEditchangeCmbSerial() 
{
	// TODO: Add your control notification handler code here
}

void CAscend_SMSDlg::OnSelchangeCmbSerial() 
{
	// TODO: Add your control notification handler code here
	PortNum = m_PortNum.GetCurSel() +1;
}

//Testing, Test the module on port
UINT Testing(LPVOID)
{
	char str[128];memset(str,0x00,128);
	int Rtn; int PortN = 0 ; bool FindModule = false;
	int UnSendNum = 0;

	if(PortNum==0)
	{
		sprintf(str,"Select a Serial Com Number!");
		pDlg->m_Status.SetWindowText(str);
		AfxEndThread(2);
		return 0;
	}
	else if(PortIsOpened)
	{
		sprintf(str,"Close the open module then test again!");
		pDlg->m_Status.SetWindowText(str);
		AfxEndThread(2);
		return 0;
	}
	else
	{
		PortN = PortNum ;
		sprintf(str,"Please wait while testing......");
		pDlg->m_Status.SetWindowText(str);

		Rtn = OpenComm(PortN);
		if(Rtn==0){
			while(true){
				Sleep(1000);
				UnSendNum = GetUnSendCount(PortN); 
				if(UnSendNum==0)
					break;
			}
			Rtn = CloseComm(PortN);
			if(Rtn==0){
				FindModule = true ;
				sprintf(str,"Success! GSM module is connected on the Com %d!",PortN);
				pDlg->m_Status.SetWindowText(str);
			}
		}
		if(!FindModule){
			sprintf(str,"Fail! Make sure that the module is connected OK!",PortN);
			pDlg->m_Status.SetWindowText(str);
		}
	}
	AfxEndThread(2);
	return 0;
}

void CAscend_SMSDlg::OnBtnTest() 
{
	// TODO: Add your control notification handler code here
	AfxBeginThread(Testing,"" ); 
}

//Configure the SMCA(Short Message Center Address)
void CAscend_SMSDlg::OnBtnSet() 
{
	// TODO: Add your control notification handler code here
	char str[64];memset(str,0x00,64); bool rtn_bool;
	m_CenterNum.GetWindowText(str,24);
	if(PortIsOpened){
		rtn_bool = SetSCA(OpenPortNum,str);		//Setup the SMCA
		if(rtn_bool)
			m_Status.SetWindowText("Set SMSC number success!");
		else
			m_Status.SetWindowText("Set SMSC number fail!");
	}
	else
		MessageBox("Please open module first!",NULL,MB_OK);
}

//Retreive the SMCA
void CAscend_SMSDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here

	char str[64];memset(str,0x00,64);
	if(PortIsOpened){
		bool rtn = GetSCA(OpenPortNum,str);		//Get the SMCA
		if(!rtn)
			MessageBox("Fail! Module busy!",NULL,MB_OK);

		m_CenterNum.SetWindowText(str);
	}
	else
		MessageBox("Please open module first!",NULL,MB_OK);
}

void CAscend_SMSDlg::OnSelchangeCmbCodeMode() 
{
	// TODO: Add your control notification handler code here
	CodeMode = m_CodeMode.GetCurSel();
}
//Ascend End

void CAscend_SMSDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add extra validation here
	CString str;static bool IsFirst=true;
	char TStr[24]; char TMsg[256];
	memset(TStr,0x00,24);memset(TMsg,0x00,256);

    m_Phone.GetWindowText(str);
	strcpy(TStr,(LPCTSTR)str);
    m_Msg.GetWindowText(str);
	strcpy(TMsg,(LPCTSTR)str);

	TMsg[0]=(char)0x01;	TMsg[1]=(char)0x34;
	TMsg[2]=(char)0x03;	TMsg[3]=(char)0x31;
	TMsg[4]=(char)0x61;	TMsg[5]=(char)0x94;

	if(PortIsOpened){
		IRtn = SendMsg(OpenPortNum,TMsg,TStr,6,1);	
		switch( IRtn ){
			case  0 :
				m_Status.SetWindowText("Send message success!");
				break;
			case -2 :
					m_Status.SetWindowText("Too long a message! Send fail!");
					break;
			case -3 :
					m_Status.SetWindowText("Error with mobile number! Send fail!");
					break;
			case -4 :
					m_Status.SetWindowText("Error with Send buffer full! Send fail!");
					break;
			case -8 :
					m_Status.SetWindowText("Error with unopen module! Send fail!");
					break;
			default :
					m_Status.SetWindowText("Other error! Send fail!");
					break;
		}

	}
	else
		MessageBox("Please open module first!",NULL,MB_OK);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -