标题:数据传输
取消只看楼主
气球
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-8-2
结帖率:0
已结贴  问题点数:0 回复次数:0 
数据传输
// sampleDlg.cpp : implementation file
//

#include "stdafx.h"
#include "sample.h"
#include "sampleDlg.h"
#include "HPVv200.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CSampleDlg dialog

CSampleDlg::CSampleDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CSampleDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CSampleDlg)
    m_maxvalue = 150.0f;
    m_minvalue = 0.0f;
    m_outvalue = 0.0f;
    m_add = 0;
    m_out2 = 0.0f;
    m_out3 = 0.0f;
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSampleDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CSampleDlg)
    DDX_Text(pDX, IDC_MAXVALUE, m_maxvalue);
    DDX_Text(pDX, IDC_MINVALUE, m_minvalue);
    DDX_Text(pDX, IDC_OUTVALUE, m_outvalue);
    DDX_Text(pDX, IDC_ADD, m_add);
    DDX_Text(pDX, IDC_OUTVALUE2, m_out2);
    DDX_Text(pDX, IDC_OUTVALUE3, m_out3);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSampleDlg, CDialog)
    //{{AFX_MSG_MAP(CSampleDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_INIT, OnInit)
    ON_BN_CLICKED(IDC_SEND, OnSend)
    ON_BN_CLICKED(IDC_ABOUT, OnAbout)
    ON_BN_CLICKED(IDC_CLEAR, OnClear)
    ON_BN_CLICKED(IDC_SEND2, OnSend2)
    ON_BN_CLICKED(IDC_CLEAR2, OnClear2)
    ON_BN_CLICKED(IDC_SEND3, OnSend3)
    ON_BN_CLICKED(IDC_CLEAR3, OnClear3)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSampleDlg message handlers

BOOL CSampleDlg::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
    InitParallel();/*并口初始化*/
m_add=0;m_outvalue=0;m_maxvalue=150;m_minvalue=0;

    /*GetDlgItem(IDC_OUTVALUE)->SetWindowText(0);
    GetDlgItem(IDC_OUTVALUE2)->SetWindowText(0);
    GetDlgItem(IDC_OUTVALUE3)->SetWindowText(0);*/


/*    m_str.AddString("1");
    m_str.AddString("2");
    m_str.AddString("3");
    m_str.SetCurSel(0);//组合框初始化
*/
   
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSampleDlg::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 CSampleDlg::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 CSampleDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CSampleDlg::OnInit()
{
    // TODO: Add your control notification handler code here

    InitParallel();
}


void CSampleDlg::OnSend()
{
    // TODO: Add your control notification handler code here
    UpdateData(true);
    if(m_add<0||m_add>255)
    {
       AfxMessageBox("地址号范围是0-255");
       return;
    }
    BOOL aa;
    int port=1;
    if(m_outvalue>m_maxvalue||m_outvalue<m_minvalue)
    {
        AfxMessageBox("输出电压超限");
        m_outvalue=0;
        UpdateData(false);
        return;
    }
    aa=SppOut(m_outvalue,m_add,port,m_maxvalue,m_minvalue,'B');
    if(aa)
    {
        AfxMessageBox("发送成功");
    }
    else
    {
       AfxMessageBox("发送失败");
    }
   
}

void CSampleDlg::OnAbout()
{
    // TODO: Add your control notification handler code here
    CAboutDlg dlg;
    dlg.DoModal ();
   
}

void CSampleDlg::OnClear()
{
    // TODO: Add your control notification handler code here
    int port=1;
    SppOut(0,m_add,port,m_maxvalue,m_minvalue,'B');
    m_outvalue=0;
    UpdateData(false);
   
}

void CSampleDlg::OnSend2()
{
    // TODO: Add your control notification handler code here
    UpdateData(true);
    if(m_add<0||m_add>255)
    {
        AfxMessageBox("地址号范围是0-255");
        return;
    }
    BOOL aa;
    int port=2;
    if(m_out2>m_maxvalue||m_out2<m_minvalue)
    {
        AfxMessageBox("输出电压超限");
        m_out2=0;
        UpdateData(false);
        return;
    }
    aa=SppOut(m_out2,m_add,port,m_maxvalue,m_minvalue,'B');
    if(aa)
    {
        AfxMessageBox("发送成功");
    }
    else
    {
        AfxMessageBox("发送失败");
    }
   
}

void CSampleDlg::OnClear2()
{
    // TODO: Add your control notification handler code here
    int port=2;
    SppOut(0,m_add,port,m_maxvalue,m_minvalue,'B');
    m_out2=0;
    UpdateData(false);
}

void CSampleDlg::OnSend3()
{
    // TODO: Add your control notification handler code here
    UpdateData(true);
    if(m_add<0||m_add>255)
    {
        AfxMessageBox("地址号范围是0-255");
        return;
    }
    BOOL aa;
    int port=3;
    if(m_out3>m_maxvalue||m_out3<m_minvalue)
    {
        AfxMessageBox("输出电压超限");
        m_out3=0;
        UpdateData(false);
        return;
    }
    aa=SppOut(m_out3,m_add,port,m_maxvalue,m_minvalue,'B');
    if(aa)
    {
        AfxMessageBox("发送成功");
    }
    else
    {
        AfxMessageBox("发送失败");
    }
   
}

void CSampleDlg::OnClear3()
{
    // TODO: Add your control notification handler code here
    int port=3;
    SppOut(0,m_add,port,m_maxvalue,m_minvalue,'B');
    m_out3=0;
    UpdateData(false);
}

这一段程序是用来发送数据的,但发送完毕后,关闭对话框时会出现错误。谁能帮忙看一下哪里出问题了。
搜索更多相关主题的帖子: file public include 
2011-08-21 11:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-348070-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.115962 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved