串行端口通信 - PuTTY 仿真
Serial Port communication - PuTTY emulation
我正在编写一个简单的用户界面来与在线串行编程器进行通信。目的是消除最终用户通过PuTTY键入十几个神秘命令的需要,实际上完全消除打字的需要,因为用户不可避免地戴着键盘不友好的手套。该过程需要与用户交互,因此简单的批处理脚本不可行。
我可以找到正确的COM端口并成功打开它。我可以发送数据,但响应只相当于"未知命令"。
我将避免发布整个代码,因为没有人能够重现我的情况。但是,如有必要,我可以随时添加所有内容。
我使用CreateFile()
打开通信,并使用WriteFile()
或ReadFile()
进行通信。例如:
if (!WriteFile(hSerial, "r rc.allrn", 10, &bytesRead, NULL))
cout << "Error sending message (" << GetLastError() << ")" << endl;
if (!ReadFile(hSerial, msgBuffer, 15, &bytesRead, NULL))
cout << "No message received" << endl
else
{
cout << "Bytes rcvd = " << bytesRead << endl;
for (int x=0; x<bytesRead; x++)
cout << (unsigned int) msgBuffer[x] << " ";
}
无论我发送什么消息("r rc.all"或"foobar"),我总是得到相同的响应:
Bytes rcvd = 3
62 13 10
这是>rn
.我尝试减慢字符的发送速度以模拟它们被键入,但这会调用 ICSP 的相同响应:
bool serialSend(LPCSTR MESSAGE, PHANDLE hSERIAL)
{
DWORD bytesWritten;
char writeBuff[2];
writeBuff[1] = ' ';
for (UINT x = 0; x <= strnlen(MESSAGE, 64); x++)
{
cout << MESSAGE[x];
writeBuff[0] = MESSAGE[x];
if (!WriteFile(*hSERIAL, writeBuff, 1, &bytesWritten, NULL))
cout << "ttERROR! (character '" << MESSAGE[x] << "', error " << GetLastError() << ")" << endl;
Sleep(100);
}
writeBuff[0] = 'n';
if (!WriteFile(*hSERIAL, writeBuff, 1, &bytesWritten, NULL))
cout << "ttERROR! (character 'LF', error " << GetLastError() << ")" << endl;
Sleep(100);
writeBuff[0] = 'r';
if (!WriteFile(*hSERIAL, writeBuff, 1, &bytesWritten, NULL))
cout << "ttERROR! (character 'CR', error " << GetLastError() << ")" << endl;
cout << endl;
return true;
}
我已经设置了串行连接的参数以匹配 PuTTY 中的设置 - 字节长度、停止位、奇偶校验、流量控制等。我得到回应的事实表明连接没有错。
怎么了?
问题原来是消息末尾发送的rn
组合。
仅发送r
或仅发送n
不起作用。但是,发送(char) 13
确实如此 - 即使这应该与r
相同。
每个字符的发送之间还需要有一个暂停;1ms就足够了。
相关文章:
- 有没有办法实现 fmu 导出到基于 c++ 的仿真软件以使用 fmi?
- 与QSerialPort配合使用的串行端口仿真
- 通过管道与 PuTTY 通信
- 动态车辆建模和仿真启动条件
- 在putty上使用g++编译器进行编译会将我的代码传递到linux服务器吗
- 使用UTF-8和Putty时,Ncurses边界打印为Q,X
- 使用QT的仿真循环
- 离散事件仿真算法调试
- 无法编译 T1 架构和仿真建模工具
- 编译器警告(CodeBlocks/wxwidget):您的编译器似乎不支持64位整数,而是使用仿真类
- 试图在Visual Studio 6.0上编译PuTTY PSCP(适用于Windows)时出现C++错误RC2104
- C 服务器 - 客户lient FTP仿真
- 我无法使用位置选项仿真子命令,然后再进行Unregistered_options
- SystemC - 测量并在系统C仿真中包括文件解析时间
- Web浏览器控件仿真问题(FEATURE_browser_emulation)
- C/C++中的6502仿真器:如何将寻址模式代码与实际指令代码分离
- C/C++ 到 C# 转换器或仿真器
- 从仿真数据构建非常大的马尔可夫链的最佳/最快方法是什么?
- 串行端口通信 - PuTTY 仿真
- 为 WIN CE 仿真器 5.0 开发的应用程序不适用于 WIN CE 设备 6.0