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

📄 serialdlg.cpp

📁 华中科技大学计算机学院接口课程设计.vc制作,上位机下位机模拟商场贵宾卡系统.使用access数据库.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		Sleep (DELAY1_8251);
		//往8251写方式命令字
		//复位命令之后一定是跟方式命令
		outportb (CTRL_8251, iModal_8251) ;
		Sleep (DELAY1_8251);
		
		//往8251写工作命令字
		outportb(CTRL_8251, iOperating_8251);
		Sleep(DELAY1_8251);

		//outportb(0x303,0
	

	outportb(0x303,0x0c);//  关声音clock

	outportb (TIMER2_8253, iTimeLow ) ;	//装计数初值低字节
	outportb (TIMER2_8253, iTimeHigh ) ;	//装计数初值高字节
	outportb(0x303,0x0d);//  开声音clock

	outportb(0x301,0xff);//
//结束声音
	}
	else{
	m_strMessage.Insert(m_IndexNum, tchReceive);
	m_IndexNum ++ ;
	}
	if (chReceive == 'b') 
		{
		for(int j=0;j<6;j++)
		{	
			tempreceive = inportb(DATA_8251);
			tchReceive = _T(tempreceive);
			moneyreceive[j]=tempreceive;
			m_strMessage.Insert(m_IndexNum, tchReceive);
			m_IndexNum ++ ;
			Sleep(50);
		}	
	}

	/* (chReceive == 'f') {
		//MessageBox("服务器已经计算并保存好金钱数据"); 
		for(int j=0;j<6;j++){
			tempreceive = inportb(DATA_8251);
			tchReceive = _T(tempreceive);
			m_strMessage.Insert(m_IndexNum, tchReceive);
			m_IndexNum ++ ;
			moneyreceive[j]=tempreceive;
			Sleep(50);
		}

	}*/
	// display the text
	pWndReceive->SetWindowText(m_strMessage);
    pWndReceive->LineScroll(255,0);
	return ;
}


void CSerialDlg::OnChangeEditSend() 
{
	pWndSend = GetDlgItem(IDC_EDIT_SEND);
	
	// get input text
	pWndSend->GetWindowText(m_strSend);
	
	iTextLengthNew = m_strSend.GetLength() ;
	if (iTextLengthNew > iTextLengthOld ) {
		// CString to TCHAR
		tchSend = m_strSend.GetAt(iTextLengthNew - 1) ;
		
		// TCHAR to CHAR
		//chSend = tchSend & 0x00FF ;	//method 1
		//chSend = char(tchSend) ;	//method 2
		chSend = (char)tchSend ;	//method 3
		
		//判断待发字符种类
		//if (! iscntrl (chSend ) ) {//如果chSend是
		// Waiting for TxRDY on
		time (&tFirst) ;	//取当前时间(以秒为单位)
		do {
			time (&tSecond) ;	//再次取当前时间(以秒为单位)
			if(difftime(tSecond,tFirst) > 1 )
			{  
				//TxRDY missing, can't send.
				MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
				return ;
			}
		} while(! (inportb(CTRL_8251) & 0x01) );
		
		// send to 8251
		outportb (DATA_8251, chSend ) ;
		Sleep (5) ;
		//}
	}
	iTextLengthOld = iTextLengthNew ;
}


void CSerialDlg::OnButton() 
{ 
//开始声音
	iTime = (CLK_8253 / iBaudrate ) / FACTOR16_BAUDRATE_8251 ;
	iTimeHigh = (iTime>>8) & 0x00FF ;
	iTimeLow  = iTime & 0x00FF ;
	
	//初始化8255、8253、8251
	
		//设置8255工作方式
		//置PC6为输出以控制8251 GATE2
		outportb(CTRL_8255, 0x80 );

		outportb(0x301,0xff);//LED全灭   ////8255控制
		outportb(0x303,0x0c);//关闭SPK
		
		outportb(0x303,0x01); //PC0置1

		Sleep(DELAY1_8251);
		
		//设置8253工作方式
		//通道2;
		//读/写2个字节,先是低字节,后是高字节;
		//3方式;
		//二进制码计数。
		outportb (CTRL_8253, 0xB6) ;	//10110110B,8253工作方式命令字
		Sleep (DELAY1_8251) ;
		
		//往8253送计时常数

		//outportb (TIMER2_8253, iTimeLow ) ;	//装计数初值低字节
		//outportb (TIMER2_8253, iTimeHigh ) ;	//装计数初值高字节

		outportb (TIMER2_8253, 0xff);
		outportb (TIMER2_8253, 0x00);

		Sleep (DELAY1_8251) ;
		
		//置8255 PC6=1,PC6与8253 GATE2相连,即允许8253通道2计数
		outportb (CTRL_8255, 0x0D ) ;	//00001101B  //开喇叭

		outportb (0x301, 0xcc);//灯亮

		Sleep (DELAY1_8251) ;
		
		//空操作,向8251命令口写任意数
		for(int j=0; j<REPEATS2_8251; j++)
		{
			outportb (CTRL_8251, 0x00 ) ;
			Sleep (DELAY2_8251) ;
		}
		//8251内部复位
		//置8251 D6=1,使其内部复位
		//发方式命令之前一定要先进行内部复位
		outportb (CTRL_8251, 0x40) ;
		Sleep (DELAY1_8251);
		//往8251写方式命令字
		//复位命令之后一定是跟方式命令
		outportb (CTRL_8251, iModal_8251) ;
		Sleep (DELAY1_8251);
		
		//往8251写工作命令字
		outportb(CTRL_8251, iOperating_8251);
		Sleep(DELAY1_8251);

		//outportb(0x303,0
	

	outportb(0x303,0x0c);//  关声音clock

	outportb (TIMER2_8253, iTimeLow ) ;	//装计数初值低字节
	outportb (TIMER2_8253, iTimeHigh ) ;	//装计数初值高字节
	outportb(0x303,0x0d);//  开声音clock

	outportb(0x301,0xff);//
//结束声音
	
	

	ifcardin=false;

	SetTimer(0,999,NULL);

	m_idbutton.EnableWindow(false);
	m_idout.EnableWindow(true);

	m_1.EnableWindow(true);
	m_2.EnableWindow(true);
	m_3.EnableWindow(true);
	m_4.EnableWindow(true);
	m_5.EnableWindow(true);
	m_6.EnableWindow(true);
	m_7.EnableWindow(true);
	m_8.EnableWindow(true);
	m_9.EnableWindow(true);
	m_0.EnableWindow(true);
	m_add.EnableWindow(true);
	m_sub.EnableWindow(true);
	m_clear.EnableWindow(true);
	m_point.EnableWindow(true);

	pWndSend = GetDlgItem(IDC_EDIT_SEND);
	
	// get input text
	pWndSend->GetWindowText(m_strSend);
	
	CString str="";
	UpdateData(true);
	str=m_mony;
	if (m_mony.GetLength()!=6) MessageBox("必须6位");
		else {
		for(int jj=0;jj<6;jj++) idstring[jj]=str.GetAt(jj);	
		
		
		
		iTextLengthNew = m_strSend.GetLength() ;
		//if (iTextLengthNew > iTextLengthOld ) {
		// CString to TCHAR
		//tchSend = m_strSend.GetAt(iTextLengthNew - 1) ;
		
		// TCHAR to CHAR
		//chSend = tchSend & 0x00FF ;	//method 1
		//chSend = char(tchSend) ;	//method 2
		chSend = (char)tchSend ;	//method 3
		//	m_strSend+=13;
		//	m_strSend+='\n';		
		
		m_strSend+='a';  //显示
		
		//	m_strSend+=13; 
		//	m_strSend+='\n';
		UpdateData(false);
		
		tchSend = m_strSend.GetAt(iTextLengthNew) ;
		CEdit*	pWndReceive =(CEdit*) GetDlgItem(IDC_EDIT_SEND);
		
		//判断待发字符种类
		//if (! iscntrl (chSend ) ) {//如果chSend是
		// Waiting for TxRDY on
		time (&tFirst) ;	//取当前时间(以秒为单位)
		do {
			time (&tSecond) ;	//再次取当前时间(以秒为单位)
			if(difftime(tSecond,tFirst) > 1 )
			{  
				//TxRDY missing, can't send.
				MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
				return ;
			}
		} while(! (inportb(CTRL_8251) & 0x01) );
		
		// send to 8251
		outportb (DATA_8251, 'a' ) ;//发送 我要插卡了!!!
		outportb(0x301,'a'); //led灯亮控制11111111
		Sleep(40);
		//}
		//}
		iTextLengthOld = iTextLengthNew ;	
		pWndReceive->LineScroll(255,0);
		
		
		int i;
		for(i=0;i<6;i++) {
			pWndSend = GetDlgItem(IDC_EDIT_SEND);
			
			// get input text
			pWndSend->GetWindowText(m_strSend);
			
			iTextLengthNew = m_strSend.GetLength() ;
			
			chSend = (char)tchSend ;	//method 3
			m_strSend+=idstring[i];  //显示
			
			UpdateData(false);
			tchSend = m_strSend.GetAt(iTextLengthNew) ;
			CEdit*	pWndReceive =(CEdit*) GetDlgItem(IDC_EDIT_SEND);
			time (&tFirst) ;	//取当前时间(以秒为单位)
			do {
				time (&tSecond) ;	//再次取当前时间(以秒为单位)
				if(difftime(tSecond,tFirst) > 1 )
				{  
					//TxRDY missing, can't send.
					MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
					return ;
				}
			} while(! (inportb(CTRL_8251) & 0x01) );
			outportb (DATA_8251, idstring[i]) ;//发送 我插卡id!!!
			outportb(0x301,0xff-idstring[i]); //led灯亮控制11111111
			Sleep (50) ;
			iTextLengthOld = iTextLengthNew ;	
			pWndReceive->LineScroll(255,0);
		}
		}

}

void CSerialDlg::OnIDout() 
{//开始声音


	iTime = (CLK_8253 / iBaudrate ) / FACTOR16_BAUDRATE_8251 ;
	iTimeHigh = (iTime>>8) & 0x00FF ;
	iTimeLow  = iTime & 0x00FF ;
	
	//初始化8255、8253、8251
	
		//设置8255工作方式
		//置PC6为输出以控制8251 GATE2
		outportb(CTRL_8255, 0x80 );

		outportb(0x301,0xff);//LED全灭   ////8255控制
		outportb(0x303,0x0c);//关闭SPK
		
		outportb(0x303,0x01); //PC0置1

		Sleep(DELAY1_8251);
		
		//设置8253工作方式
		//通道2;
		//读/写2个字节,先是低字节,后是高字节;
		//3方式;
		//二进制码计数。
		outportb (CTRL_8253, 0xB6) ;	//10110110B,8253工作方式命令字
		Sleep (DELAY1_8251) ;
		
		//往8253送计时常数

		//outportb (TIMER2_8253, iTimeLow ) ;	//装计数初值低字节
		//outportb (TIMER2_8253, iTimeHigh ) ;	//装计数初值高字节

		outportb (TIMER2_8253, 0xff);
		outportb (TIMER2_8253, 0x00);

		Sleep (DELAY1_8251) ;
		
		//置8255 PC6=1,PC6与8253 GATE2相连,即允许8253通道2计数
		outportb (CTRL_8255, 0x0D ) ;	//00001101B  //开喇叭

		outportb (0x301, 0xcc);//灯亮

		Sleep (DELAY1_8251) ;
		
		//空操作,向8251命令口写任意数
		for(int j=0; j<REPEATS2_8251; j++)
		{
			outportb (CTRL_8251, 0x00 ) ;
			Sleep (DELAY2_8251) ;
		}
		//8251内部复位
		//置8251 D6=1,使其内部复位
		//发方式命令之前一定要先进行内部复位
		outportb (CTRL_8251, 0x40) ;
		Sleep (DELAY1_8251);
		//往8251写方式命令字
		//复位命令之后一定是跟方式命令
		outportb (CTRL_8251, iModal_8251) ;
		Sleep (DELAY1_8251);
		
		//往8251写工作命令字
		outportb(CTRL_8251, iOperating_8251);
		Sleep(DELAY1_8251);

		//outportb(0x303,0
	

	outportb(0x303,0x0c);//  关声音clock

	outportb (TIMER2_8253, iTimeLow ) ;	//装计数初值低字节
	outportb (TIMER2_8253, iTimeHigh ) ;	//装计数初值高字节
	outportb(0x303,0x0d);//  开声音clock

	outportb(0x301,0xff);//
//结束声音

//	ifcardin==false;
	m_mony="";
	UpdateData(false);
	m_idbutton.EnableWindow(true);
	m_idout.EnableWindow(false);

	m_1.EnableWindow(false);
	m_2.EnableWindow(false);
	m_3.EnableWindow(false);
	m_4.EnableWindow(false);
	m_5.EnableWindow(false);
	m_6.EnableWindow(false);
	m_7.EnableWindow(false);
	m_8.EnableWindow(false);
	m_9.EnableWindow(false);
	m_0.EnableWindow(false);
	m_add.EnableWindow(false);
	m_sub.EnableWindow(false);
	m_clear.EnableWindow(false);
	m_point.EnableWindow(false);

	pWndSend = GetDlgItem(IDC_EDIT_SEND);
	
	// get input text
	pWndSend->GetWindowText(m_strSend);
	
	iTextLengthNew = m_strSend.GetLength() ;
	//if (iTextLengthNew > iTextLengthOld ) {
	// CString to TCHAR
	//tchSend = m_strSend.GetAt(iTextLengthNew - 1) ;
	
	// TCHAR to CHAR
	//chSend = tchSend & 0x00FF ;	//method 1
	//chSend = char(tchSend) ;	//method 2
	chSend = (char)tchSend ;	//method 3
	
	m_strSend+='e';  //显示
	//	m_strSend+=13;
	//	m_strSend+='\n';
	
	UpdateData(false);
	tchSend = m_strSend.GetAt(iTextLengthNew) ;
	CEdit*	pWndReceive =(CEdit*) GetDlgItem(IDC_EDIT_SEND);
	
	//判断待发字符种类
	//if (! iscntrl (chSend ) ) {//如果chSend是
	// Waiting for TxRDY on
	time (&tFirst) ;	//取当前时间(以秒为单位)
	do {
		time (&tSecond) ;	//再次取当前时间(以秒为单位)
		if(difftime(tSecond,tFirst) > 1 )
		{  
			//TxRDY missing, can't send.
			MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
			return ;
		}
	} while(! (inportb(CTRL_8251) & 0x01) );
	
	// send to 8251
	outportb (DATA_8251, 'e' ) ;//发送 我要拔卡了
	outportb(0x301,'e'); 
	Sleep (5) ;
	
	iTextLengthOld = iTextLengthNew ;	
	pWndReceive->LineScroll(255,0);
	
	for(int i=0;i<6;i++) substring[i]='0';//初始化substring
	ifpoint=false;
	//m_point.EnableWindow(true);
	nowat=3;
	m_disp=substring;
	UpdateData(false);
	outportb(0x301,0xff);
}

//**加法
void CSerialDlg::Onadd() 
{	//开始声音
	iTime = (CLK_8253 / iBaudrate ) / FACTOR16_BAUDRATE_8251 ;
	iTimeHigh = (iTime>>8) & 0x00FF ;
	iTimeLow  = iTime & 0x00FF ;
	
	//初始化8255、8253、8251
	
		//设置8255工作方式
		//置PC6为输出以控制8251 GATE2
		outportb(CTRL_8255, 0x80 );

		outportb(0x301,0xff);//LED全灭   ////8255控制
		outportb(0x303,0x0c);//关闭SPK
		
		outportb(0x303,0x01); //PC0置1

		Sleep(DELAY1_8251);
		
		//设置8253工作方式
		//通道2;
		//读/写2个字节,先是低字节,后是高字节;
		//3方式;
		//二进制码计数。
		outportb (CTRL_8253, 0xB6) ;	//10110110B,8253工作方式命令字
		Sleep (DELAY1_8251) ;
		
		//往8253送计时常数

		//outportb (TIMER2_8253, iTimeLow ) ;	//装计数初值低字节
		//outportb (TIMER2_8253, iTimeHigh ) ;	//装计数初值高字节

		outportb (TIMER2_8253, 0xff);
		outportb (TIMER2_8253, 0x00);

		Sleep (DELAY1_8251) ;
		
		//置8255 PC6=1,PC6与8253 GATE2相连,即允许8253通道2计数
		outportb (CTRL_8255, 0x0D ) ;	//00001101B  //开喇叭

		outportb (0x301, 0xcc);//灯亮

		Sleep (DELAY1_8251) ;
		
		//空操作,向8251命令口写任意数
		for(int j=0; j<REPEATS2_8251; j++)
		{
			outportb (CTRL_8251, 0x00 ) ;
			Sleep (DELAY2_8251) ;
		}
		//8251内部复位
		//置8251 D6=1,使其内部复位
		//发方式命令之前一定要先进行内部复位
		outportb (CTRL_8251, 0x40) ;
		Sleep (DELAY1_8251);
		//往8251写方式命令字
		//复位命令之后一定是跟方式命令
		outportb (CTRL_8251, iModal_8251) ;
		Sleep (DELAY1_8251);
		
		//往8251写工作命令字
		outportb(CTRL_8251, iOperating_8251);
		Sleep(DELAY1_8251);

		//outportb(0x303,0
	

	outportb(0x303,0x0c);//  关声音clock

	outportb (TIMER2_8253, iTimeLow ) ;	//装计数初值低字节
	outportb (TIMER2_8253, iTimeHigh ) ;	//装计数初值高字节
	outportb(0x303,0x0d);//  开声音clock

	outportb(0x301,0xff);//
//结束声音

	ifcardin=false;
	SetTimer(0,999,NULL);
	//MessageBox(substring);
	pWndSend = GetDlgItem(IDC_EDIT_SEND);
	// get input text
	pWndSend->GetWindowText(m_strSend);
	
	iTextLengthNew = m_strSend.GetLength() ;
	//if (iTextLengthNew > iTextLengthOld ) {
	// CString to TCHAR
	//tchSend = m_strSend.GetAt(iTextLengthNew - 1) ;
	
	// TCHAR to CHAR
	//chSend = tchSend & 0x00FF ;	//method 1
	//chSend = char(tchSend) ;	//method 2
	chSend = (char)tchSend ;	//method 3
	
	m_strSend+='c';  //显示
//	m_strSend+=13;
//	m_strSend+='\n';
	
	UpdateData(false);
	tchSend = m_strSend.GetAt(iTextLengthNew) ;
	CEdit*	pWndReceive =(CEdit*) GetDlgItem(IDC_EDIT_SEND);
	
	//判断待发字符种类
	//if (! iscntrl (chSend ) ) {//如果chSend是
	// Waiting for TxRDY on
	time (&tFirst) ;	//取当前时间(以秒为单位)
	do {
		time (&tSecond) ;	//再次取当前时间(以秒为单位)
		if(difftime(tSecond,tFirst) > 1 )
		{  
			//TxRDY missing, can't send.

⌨️ 快捷键说明

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