📄 airserverdlg.cpp
字号:
// airserverDlg.cpp : implementation file
//
#include "stdafx.h"
#include "airserver.h"
#include "airserverDlg.h"
#include "PortTalk.h"
#include "stdlib.h"
#include "String.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define _PCI9052 0X520110B5
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAirserverDlg dialog
CAirserverDlg::CAirserverDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAirserverDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAirserverDlg)
m_message = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAirserverDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAirserverDlg)
DDX_Control(pDX, IDC_COMBO3, m_airbottom);
DDX_Control(pDX, IDC_COMBO2, m_airtop);
DDX_Text(pDX, IDC_EDIT1, m_message);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAirserverDlg, CDialog)
//{{AFX_MSG_MAP(CAirserverDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_COMBO2, select_ait_top)
ON_CBN_SELCHANGE(IDC_COMBO3, select_air_bottom)
ON_BN_CLICKED(IDC_BUTTON1, start_watch)
ON_BN_CLICKED(IDC_BUTTON2, stop_watch)
ON_BN_CLICKED(IDC_BUTTON3, empty_data)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAirserverDlg message handlers
BOOL CAirserverDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
porttalk = new CPortTalk("MFADVWDM1");
top=190;
bottom=50;
detect=FALSE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CAirserverDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CAirserverDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CAirserverDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CAirserverDlg::SetIOBASE()
{
DWORD io_CF8;
DWORD io_CFC;
DWORD PCI_DeviceVendorID = _PCI9052;
io_CF8=0X80000000; //使能端为1
do {
porttalk->outportd(0XCF8, io_CF8);
io_CFC = porttalk->inportd(0XCFC);
io_CF8 += 0X800; //将设备功能号加1
} while((io_CFC != PCI_DeviceVendorID) && (io_CF8 < 0X80FFFF00)); //最大设备数
io_CF8 = io_CF8 - 0X800;
if(io_CFC!=PCI_DeviceVendorID)
return FALSE;
else{
porttalk->outportd(0Xcf8,io_CF8+4*7); //read IOBASE
io_Base= porttalk->inportd(0Xcfc)-1;
return TRUE;
}
}
//DEL void CAirserverDlg::Onselect_air_top()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
//DEL void CAirserverDlg::Onselect_air_botom()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
void CAirserverDlg::select_ait_top()
{
// TODO: Add your control notification handler code here
int i=m_airtop.GetCurSel();
// DWORD temp=m_airtop.GetItemData(i);
//j= temp & 0x000000FF;
//m_airtop.GetLBText(i,buf);
//itoa(temp,buf,10);
switch(i){
case 0: top=190; break;
case 1: top=200; break;
case 2: top=210; break;
case 3: top=220; break;
case 4: top=230; break;
default: top=190; break;
}
}
void CAirserverDlg::select_air_bottom()
{
// TODO: Add your control notification handler code here
// char buf[4];
int i=m_airbottom.GetCurSel();
switch(i){
case 0: bottom=100; break;
case 1: bottom=16; break;
case 2: bottom=32; break;
case 3: bottom=64; break;
case 4: bottom=80; break;
default: bottom=100; break;
}
}
void CAirserverDlg::start_watch()
{
// TODO: Add your control notification handler code here
//char buf[1024];
if(detect==FALSE){
open_com();
Sleep(100);
if(::WriteCommBlock(m_comstatus,"start",6)==FALSE){
m_message = "开启监控失败";
UpdateData(FALSE);
}
else{
detect=TRUE;
}
SetTimer(1 , 2000 , NULL);
}
}
void CAirserverDlg::stop_watch()
{
// TODO: Add your control notification handler code here
if(detect == TRUE){
if(::WriteCommBlock(m_comstatus,"stop",5)==FALSE){
m_message = "停止监控失败";
UpdateData(FALSE);
}
detect=FALSE;
KillTimer(1);
close_com();
porttalk->ClosePortTalk();
m_message += "\n\r数据采集已经停止!";
UpdateData(FALSE);
}
else {
m_message += "\n\r数据采集已经停止!";
UpdateData(FALSE);
}
}
void CAirserverDlg::empty_data()
{
// TODO: Add your control notification handler code here
m_message=" ";
UpdateData(false);
}
void CAirserverDlg::open_com()
{
if(porttalk->OpenPortTalk() ==-1 ){ //打开端口失败
m_message="加载驱动程序失败!";
UpdateData(false);
}//else{
// m_message="加载驱动程序成功!";
// UpdateData(false);
//}
Sleep(200); //延时
if(!SetIOBASE()){
AfxMessageBox("找不到PCI设备!",MB_ICONEXCLAMATION | MB_OK);
return;
}
m_comstatus.Set(1);
if(m_comstatus.OpenConnection()==FALSE){
m_message = "无法打开该串口!";
UpdateData(FALSE);
}
}
void CAirserverDlg::close_com()
{
m_comstatus.CloseConnection();
}
void CAirserverDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
char buf[128];
int n;
if( ( ::ReadCommBlock(m_comstatus,buf,128) ) !=0){
m_message += buf;
UpdateData(false);
m_message += " ";
UpdateData(false);
n=atoi(buf);
if(n>top ){
if(::WriteCommBlock(m_comstatus,"high",5)==FALSE){
m_message += "发送高压警报失败\r\n";
UpdateData(FALSE);
}
else{
m_message += "发送高压警报,并调整气压降低......\r\n";
UpdateData(FALSE);
Sleep(1000);
}
}
if(n<bottom){
if(::WriteCommBlock(m_comstatus,"low",4)==FALSE){
m_message += "发送低压警报失败\r\n";
UpdateData(FALSE);
}
else {
m_message += "发送低压警报,并调整气压升高......\r\n";
UpdateData(FALSE);
Sleep(1000);
}
}
}
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -