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