1

我正在尝试使用 boost/asio 与串行端口通信。这是我的代码。

调用函数头文件包含以下内容:

    QserialPort *SerialPort;

调用函数:

    std::string port = "com1";
    SerialPort = new QserialPort(port);

类头文件包含以下代码:

    /* 
    * File:   QserialPort.h
    *
    * Created on December 13, 2012, 9:01 PM
    */

    #ifndef QSERIALPORT_H
    #define QSERIALPORT_H

    #include "global_variables.h"
    #include <windows.h>
    #include <winbase.h>
    #include <winsock2.h>
    #include <boost/system/error_code.hpp>
    #include <boost/system/system_error.hpp>
    #include <boost/asio.hpp>
    #include <boost/asio/serial_port.hpp>
    #include <QString>

    #define rcvBufSize 512
    #define xmtBufSize 512

    class QserialPort {
    public:
        QserialPort(std::string comPort);
        virtual ~QserialPort();
    private:
        // variables
        int m_a;
        double m_b;
        const char* m_c;
        boost::asio::io_service m_io;
        boost::asio::serial_port m_serialPort;
        char m_rcvMsg[rcvBufSize];
        char m_xmtMsg[xmtBufSize];

        // functions

    };

    #endif   /* QSERIALPORT_H */

类源代码有这个构造函数:

    QserialPort::QserialPort(std::string comPort) :
    m_io(),
    m_serialPort(m_io, comPort)
    {
        QString msg;
        char buf[100];
        sprintf(buf, "Serial port is on %s", comPort);
        msg.append(buf);
        QMessageBox::information(NULL, "debug", msg);
    }

该程序编译正常,但是当我尝试运行它时,我在弹出窗口中收到此错误:

This application has requested the Runtime to teminate it in an unusual way.
Please contact the application's support team for more information.

这是 netbeans 的运行输出选项卡中的内容:

terminate called after throwing an instance of 
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector
<boost::system::system_error> >'
  what():  open: The system cannot find the file specified
Unable to open SCSI controller 0:[\] , error code: 0x5
Unable to open SCSI controller 1:[\] , error code: 0x5

RUN FAILED (exit value 3, total time: 15s)

这些是我正在关注的示例:

我的系统:

Windows Vista Home Premium Service Pack 2
Netbeans 7.2.1
QtSDK 1.2.1
Boost 1.52.0

我需要做什么才能让它运行。

4

0 回答 0