尝试将 SerialPort 输入打印到控制台
Attempting to print SerialPort inputs to the console
首先是我的代码:
#include <iostream>
#include <thread>
#using <System.dll>
using namespace System;
using namespace System::IO::Ports;
using namespace System::Threading;
int main()
{
SerialPort^ mySerialPort = gcnew SerialPort("COM5");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake = Handshake::None;
mySerialPort->RtsEnable = true;
while (1)
{
Console::WriteLine(Console::ReadLine());
}
}
我的想法是从 SerialPort 读取并写入控制台。 Source
本来我打算用:
std::cout << Console::ReadLine() << '\n';
但是,它有一个错误(ReadLine 输出 String^ 而不是 String,我不知道有什么区别),我希望可以编译一些东西。
使用上面的代码我收到了错误:
C++/CLI 不支持两阶段名称查找 ... 使用 /Zc:twoPhase-
错误建议我使用 /Zc:twoPhase- 这是 compiler option。所以我启用它并得到错误:
元素具有无效值“Yes(/permissive-) /Zc:twoPhase-”
我不太确定如何从这里开始。
抱歉,我是一个初学者,我已经不知所措了。任何帮助,将不胜感激!
注意:我包含了线程,我知道这段代码不会使用它,但我打算稍后使用它。
根据“元素具有无效值”Yes(/permissive-) /Zc:twoPhase-“”判断,您已将此编译器选项放在它不属于的位置。确保你知道它应该去哪里。例如。
没有解决办法。我收到“无法打开文件 'MSCOREE.lib'”错误。该文件似乎不再存在于 Windows 中,我不知道如何获取它。所以我用了 Visual Studio Windows Form App.
编辑:eXCore 关于 .NET 框架的评论解决了它。
首先是我的代码:
#include <iostream>
#include <thread>
#using <System.dll>
using namespace System;
using namespace System::IO::Ports;
using namespace System::Threading;
int main()
{
SerialPort^ mySerialPort = gcnew SerialPort("COM5");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake = Handshake::None;
mySerialPort->RtsEnable = true;
while (1)
{
Console::WriteLine(Console::ReadLine());
}
}
我的想法是从 SerialPort 读取并写入控制台。 Source
本来我打算用:
std::cout << Console::ReadLine() << '\n';
但是,它有一个错误(ReadLine 输出 String^ 而不是 String,我不知道有什么区别),我希望可以编译一些东西。
使用上面的代码我收到了错误: C++/CLI 不支持两阶段名称查找 ... 使用 /Zc:twoPhase-
错误建议我使用 /Zc:twoPhase- 这是 compiler option。所以我启用它并得到错误: 元素具有无效值“Yes(/permissive-) /Zc:twoPhase-”
我不太确定如何从这里开始。
抱歉,我是一个初学者,我已经不知所措了。任何帮助,将不胜感激! 注意:我包含了线程,我知道这段代码不会使用它,但我打算稍后使用它。
根据“元素具有无效值”Yes(/permissive-) /Zc:twoPhase-“”判断,您已将此编译器选项放在它不属于的位置。确保你知道它应该去哪里。例如。
没有解决办法。我收到“无法打开文件 'MSCOREE.lib'”错误。该文件似乎不再存在于 Windows 中,我不知道如何获取它。所以我用了 Visual Studio Windows Form App.
编辑:eXCore 关于 .NET 框架的评论解决了它。