24小时热门版块排行榜    

CyRhmU.jpeg
查看: 2193  |  回复: 15
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

leafmavis

木虫 (文坛精英)

[求助] VC++中如何应用porttalk

有个实验,是控制一个电动台做旋转运动(这部分VC++源代码由产品的制造商提供),从而给实验动物刺激,同时采集动物的脑电。我们想在旋转运动的开始和结束的时候,分别给并口一秒钟的高电平,以便在脑电信号采集系统上打上同步标记。我们做了一个并口的流水灯以验证并口操作的可靠性。用C++bulider 6.0时,利用PortTalk能控制流水灯工作;但用VC++ 6.0时,报错。因电动台的源码是VC++ 6.0,所以想请教高手。谢谢!
     下面是单纯的并口操作验证:
1、用C++bulider时,在工程目录下拷进这两个文件:PortTalk.sys; PortTalk.h。在Form中添加一个按键(功能为:使并口输出脉宽为1秒的高电平),并在Form中添加了并口初始化(因为计算机开机时并口各数据位是高电平,初始化就是将所有数据位置低)。程序运行正常,流水灯的开闭正常。

2、用VC++时,操作同上,但编译时报错。想请问一下,在VC++下如何使用PortTalk ?网上没说PortTalk不能用于VC++呀

--------------------Configuration: fang1 - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
fang1.cpp
fang1Dlg.cpp
e:\work\vc\learn1\fang1\porttalk.h(41) : error C2065: 'ShowMessage' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(80) : error C2065: 'SC_HANDLE' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(80) : error C2146: syntax error : missing ';' before identifier 'SchSCManager'
e:\work\vc\learn1\fang1\porttalk.h(80) : error C2065: 'SchSCManager' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(81) : error C2146: syntax error : missing ';' before identifier 'schService'
e:\work\vc\learn1\fang1\porttalk.h(81) : error C2065: 'schService' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(85) : error C2065: 'OpenSCManager' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(85) : error C2065: 'SC_MANAGER_ALL_ACCESS' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(94) : error C2065: 'OpenService' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(94) : error C2065: 'SERVICE_ALL_ACCESS' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(110) : error C2065: 'StartService' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(112) : error C2065: 'CloseServiceHandle' : undeclared identifier
e:\work\vc\learn1\fang1\porttalk.h(118) : error C2146: syntax error : missing ';' before identifier 'SchSCManager'
e:\work\vc\learn1\fang1\porttalk.h(119) : error C2146: syntax error : missing ';' before identifier 'schService'
e:\work\vc\learn1\fang1\porttalk.h(129) : error C2065: 'CreateService' : undeclared identifier
Generating Code...
Error executing cl.exe.

fang1.exe - 15 error(s), 0 warning(s)
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

春如杯中水
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sudo

木虫 (正式写手)

【答案】应助回帖

★ ★
余泽成(金币+2): 辛苦了! 2011-05-04 22:54:12
不保证能用,把下面的代码贴到PortTalk.h里面的#include 那行的下面
CODE:
#include
#include

#ifdef _MFC_VER
#define ShowMessage MessageBox
#else
#define ShowMessage printf
#endif

你再编译看看有什么错误,大家再讨论~


【评论】

porttalk这个.h库写得很不好

如果在两个不同的.c/.cpp文件里面include的话,作为一个工程,会有重定义error的

不过先就这么地吧,等楼主以后熟悉编程之后,自己写都不是问题
8楼2011-05-04 14:56:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 16 个回答

yalefield

金虫 (文坛精英)

老汉一枚

【答案】应助回帖

★ ★
余泽成(金币+2): 谢谢参与应助! 2011-05-04 22:51:48
leafmavis(金币+2): 谢谢热情相助 2011-05-05 09:08:35
(1) 在您用到PortTalk中的函数时,首先要
#include "PortTalk.h"

(2) 等下一步您遇到更多错误时,再说咯。
2楼2011-05-04 08:42:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

leafmavis

木虫 (文坛精英)

谢谢您的回复,不过头文件是加上了的。附上C++源码,除 #include "PortTalk.h" 和最后面的按键响应函数,其他的都是自动生成的。请帮忙分析,谢谢!


// fang1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "fang1.h"
#include "fang1Dlg.h"
#include "PortTalk.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:oDataExchange(CDataExchange* pDX)
{
        CDialog:oDataExchange(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()

/////////////////////////////////////////////////////////////////////////////
// CFang1Dlg dialog

CFang1Dlg::CFang1Dlg(CWnd* pParent /*=NULL*/)
        : CDialog(CFang1Dlg::IDD, pParent)
{
        //{{AFX_DATA_INIT(CFang1Dlg)
                // NOTE: the ClassWizard will add member initialization here
        //}}AFX_DATA_INIT
        // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFang1Dlg:oDataExchange(CDataExchange* pDX)
{
        CDialog:oDataExchange(pDX);
        //{{AFX_DATA_MAP(CFang1Dlg)
                // NOTE: the ClassWizard will add DDX and DDV calls here
        //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFang1Dlg, CDialog)
        //{{AFX_MSG_MAP(CFang1Dlg)
        ON_WM_SYSCOMMAND()
        ON_WM_PAINT()
        ON_WM_QUERYDRAGICON()
        ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFang1Dlg message handlers

BOOL CFang1Dlg::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
       
        return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CFang1Dlg::OnButton1()
{
        // TODO: Add your control notification handler code here
        OpenPortTalk();  //打开地址操作
        outportb(0x378,0xFF);
        Sleep(1000);
        outportb(0x378,0x00);
        ClosePortTalk();  //关闭地址操作
}
春如杯中水
3楼2011-05-04 09:12:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sudo

木虫 (正式写手)

【答案】应助回帖

★ ★
余泽成(金币+2): 谢谢参与应助! 2011-05-04 22:52:12
leafmavis(金币+7): 谢谢热情相助,VS2010下编译通过的h文件,用C++6.0还有14个错误,我再仔细研究下,谢谢! 2011-05-05 09:12:29
界面的部分都没有问题(话说这么简单的东西直接用console application不好嘛)

于是楼主能不能贴一下PortTalk.h这个文件的内容呢?

看样子像是把函数定义放到.h文件里面了(不是类模板等特殊情况的话这么做其实不好的),恩,所以先看看吧

PS:
贴代码的时候,放到
CODE:
这个里面

会比较好看一点
4楼2011-05-04 10:27:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见