【问题标题】:How to write c++ dll function to get com port Reading如何编写c++ dll函数来获取com端口阅读
【发布时间】:2012-08-29 15:19:12
【问题描述】:

我是 c++ 新手,我试图从 c++ 中的函数读取 COM 端口 以下是代码说明,有人可以帮我完成吗? 该函数应获取评论的值,请帮助我 谢谢你

int ComPortReading( short, wchar_t * Data[], wchar_t **Output, SIZE_T *OutputSize )
{
int result = 1;
if( Data[0] )
{
    *OutputSize = 50;
    *Output = (wchar_t *) CoTaskMemAlloc(*OutputSize);

    if( *Output )
    {
        wchar_t *EndPtr;

        double v11 = wcstod(Data[0], &EndPtr);  // Port Name
        double v12 = wcstod(Data[1], &EndPtr);  // Baud Rate
        double v13 = wcstod(Data[2], &EndPtr);  // Data Bits
        double v14 = wcstod(Data[3], &EndPtr);  // Stop Bits
        double v15 = wcstod(Data[4], &EndPtr);  // Parity

 // Need to write code here to read COM port
       // Com port settings can be taken from the above v11 - v15 values

        swprintf(*Output, L"%.10lf", v11);
        result = 0;
    }
}

return result;
}

【问题讨论】:

  • 我没有看到任何实际从 COM 端口读取字节的代码,所以您实际上是在询问有关 C++ 字符串处理的问题。
  • C++ Communication via COM Port 的可能重复项

标签: c++ function dll


【解决方案1】:

我建议使用一个库,它封装了困难的东西。例如this library on CodeProject 或来自Boost.Asio 的实现。

【讨论】:

  • 先生,请问您能完成这个功能吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 1970-01-01
  • 1970-01-01
  • 2019-05-29
  • 2013-06-29
相关资源
最近更新 更多