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

📄 comportrdlg.cpp

📁 串口通信,R232.使用VC++ 编写.非常难得。欢迎大家传播下载
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

BOOL CComPortRDlg::OpenCom(int i, CString ComName)
{

	return true;
}

void CComPortRDlg::OnReadportinf() 
{
	// TODO: Add your control notification handler code here
	int j=0, k=0, nColumn=0, SmNumber=0;
	CString strTemp;
	nColumn = m_List.GetItemCount();
	m_List.InsertItem(nColumn,"PortAddress");
	
	for(int i=0; i<SmCounter;i++)
	{
		k = mySmSetInf[i].PortId;
		strTemp.Format("%d", k);
		CString strSQL="select * from PortConfigTable where PortId = ";
		strSQL = strSQL+strTemp;
		if(!OpenComPort(m_pComPort,strSQL))
			AfxMessageBox("端口配置表打开失败:("); 
		else m_pComPort->MoveFirst();
		while(!m_pComPort->adoEOF)
		{
			AlarmPort[i].PortAddress = (long)m_pComPort->GetCollect("PortAddress");
			
			int iTemp,m_nColumn;
			CString strTemp;
			m_nColumn = m_List.GetItemCount();
			iTemp = m_nColumn+1;
			strTemp.Format("%d", AlarmPort[i].PortAddress);
			m_List.InsertItem(m_nColumn,strTemp);
			m_pComPort->MoveNext();
		}
	}
	
}

void CComPortRDlg::OnStartalarm() 
{
	// TODO: Add your control notification handler code here
	int iTemp;
	CString strTemp;
	for(int i=0; i<SmCounter;i++)
	{
		iTemp = mySmSetInf[i].PortId;
		for(int j=0; j<ComCounter; j++)
		{
			if(ComPortInfN[j].PortID == iTemp)
			{	
				switch(ComPortInfN[j].PortAddress) 
				{
				case 1:
					{
						myICM30.SendData[3] = 0x01;
						myArray.RemoveAll();
						myArray.SetSize(myICM30.SendDataNumber);
						for(int k=0; k<myICM30.SendDataNumber; k++)
						{
							myArray.SetAt(k,myICM30.SendData[k]);
						}
						
						m_myCom1.SetOutput(COleVariant(myArray));
//						SetTimer(11,200,NULL);
						SetTimer(12,5000,NULL);
						break;
					}
				case 2:
					{
						myICM30.SendData[3] = 0x01;
						myArray.RemoveAll();
						myArray.SetSize(myICM30.SendDataNumber);
						for(int k=0; k<myICM30.SendDataNumber; k++)
						{
							myArray.SetAt(k,myICM30.SendData[k]);
						}
						
						m_myCom2.SetOutput(COleVariant(myArray));
						//SetTimer(21,200,NULL);
						SetTimer(22,5000,NULL);
						break;
					}
				case 3:
					{
						myICM30.SendData[3] = 0x01;
						myArray.RemoveAll();
						myArray.SetSize(myICM30.SendDataNumber);
						for(int k=0; k<myICM30.SendDataNumber; k++)
						{
							myArray.SetAt(k,myICM30.SendData[k]);
						}
						
						m_myCom3.SetOutput(COleVariant(myArray));
//						SetTimer(31,200,NULL);
						SetTimer(32,5000,NULL);
						break;
					}
				case 4:
					{
						myICM30.SendData[3] = 0x01;
						myArray.RemoveAll();
						myArray.SetSize(myICM30.SendDataNumber);
						for(int k=0; k<myICM30.SendDataNumber; k++)
						{
							myArray.SetAt(k,myICM30.SendData[k]);
						}
						
						m_myCom4.SetOutput(COleVariant(myArray));
						SetTimer(41,200,NULL);
						SetTimer(42,5000,NULL);
						break;
					}
				case 5:
					{
						myICM30.SendData[3] = 0x05;
						break;
					}
				case 6:
					{
						myICM30.SendData[3] = 0x06;
						break;
					}
				case 7:
					{
						myICM30.SendData[3] = 0x07;
						break;
					}
				case 8:
					{
						myICM30.SendData[3] = 0x08;
						break;
					}
				default:
					;
				}
			}
		}
	}
}

void CComPortRDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	switch(nIDEvent) 
	{
	case 11:
		{
			KillTimer(11);                     //关闭超时定时器
			AfxMessageBox("超时!");
			SetTimer(1,200,NULL);
			break;
		}
	case 12:
		{
			KillTimer(12);                     //关闭超时定时器
			for(int k=0; k<myICM30.SendDataNumber; k++)
			{
				myArray.SetAt(k,myICM30.SendData[k]);
			}
			
			m_myCom1.SetOutput(COleVariant(myArray));
			
			SetTimer(2,5000,NULL);
			break;
		}
	case 3:
		{
			KillTimer(3);
//			AlarmPro->ShowWindow(false);
			break;
		}
	case 21:
		{
			KillTimer(21);                     //关闭超时定时器
			AfxMessageBox("超时!");
			SetTimer(1,200,NULL);
			break;
		}
	case 22:
		{
			KillTimer(22);                     //关闭超时定时器
			for(int k=0; k<myICM30.SendDataNumber; k++)
			{
				myArray.SetAt(k,myICM30.SendData[k]);
			}
			
			m_myCom2.SetOutput(COleVariant(myArray));
			
			SetTimer(2,5000,NULL);
			break;
		}
	case 31:
		{
			KillTimer(31);                     //关闭超时定时器
			AfxMessageBox("超时!");
			SetTimer(1,200,NULL);
			break;
		}
	case 32:
		{
			KillTimer(32);                     //关闭超时定时器
//			AfxMessageBox("超时32!");
			for(int k=0; k<myICM30.SendDataNumber; k++)
			{
				myArray.SetAt(k,myICM30.SendData[k]);
			}
			
			m_myCom3.SetOutput(COleVariant(myArray));
			
			SetTimer(32,5000,NULL);
			break;
		}
	case 41:
		{
			KillTimer(41);                     //关闭超时定时器
			AfxMessageBox("超时!");
			SetTimer(41,200,NULL);
			break;
		}
	case 42:
		{
			KillTimer(42);                     //关闭超时定时器
			AfxMessageBox("超时!");
			for(int k=0; k<myICM30.SendDataNumber; k++)
			{
				myArray.SetAt(k,myICM30.SendData[k]);
			}
			
			m_myCom4.SetOutput(COleVariant(myArray));
			
			SetTimer(42,5000,NULL);
			break;
		}
	default:	;
	}

	CDialog::OnTimer(nIDEvent);
}

BEGIN_EVENTSINK_MAP(CComPortRDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CComPortRDlg)
	ON_EVENT(CComPortRDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CComPortRDlg::OnOnCommMscomm1() 
{
	// TODO: Add your control notification handler code here
	switch(m_myCom1.GetCommEvent())
	{
	case 2:
		{
			int i;
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
	switch(m_myCom2.GetCommEvent())
	{
	case 2:
		{
			int i;
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
	switch(m_myCom3.GetCommEvent())
	{
	case 2:
		{
			KillTimer(31); 
			int i;
			AfxMessageBox("超时接收!");
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
	switch(m_myCom4.GetCommEvent())
	{
	case 2:
		{
			int i;
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
	switch(m_myCom5.GetCommEvent())
	{
	case 2:
		{
			int i;
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
	switch(m_myCom6.GetCommEvent())
	{
	case 2:
		{
			int i;
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
	switch(m_myCom7.GetCommEvent())
	{
	case 2:
		{
			int i;
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
	switch(m_myCom8.GetCommEvent())
	{
	case 2:
		{
			int i;
			break;
		}
	case 1:
		{
			MessageBox("1");
			break;
		}
	case 1008:
		{
			MessageBox("1008");
			break;
		}
	case 1010:
		{
			MessageBox("1010");
			break;
		}
	default:
		{
			
		}
	}
}



















void CComPortRDlg::OnChangeAlarmdisplay() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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