c++串口通信初始化不成功

#include "stdafx.h"
#include "SerialPort.h"
#include

using namespace std;
int main(int argc, char* argv[])
{
CSerialPort mySerialPort;

if (!mySerialPort.InitPort(2))
{
    cout << "initport fail !" <<endl;
}
else
{
    cout << "initport success !" <<endl;
}

if (!mySerialPort.OpenListenThread())
{
    cout << "open fail!"<<endl;
}
else
{
    cout <<"open success !"<<endl;
}
return 0;

}

串口通信协议用了现成的代码,但测试串口通信的时候监听现成开启成功,但是初始化化不成功,为什么?用串口助手测试过,通信连接没问题。
求大神们帮帮忙,万分感谢!

CSerialPort 的代码你不粘,没人能帮得了你。

初始化不成功,返回的什么错误码,是不是串口没打开

参考代码
https://github.com/707wk/MFC-Serial-Connection

这个问题楼主解决了吗??我现在也遇到了相同的问题。。。能告诉我解决方法吗??

if (!mySerialPort.InitPort(2))

把这条代码括号里的2改成自己的链接端口号即可