c++ - 通过串行读取字符串
问题描述
我想通过蓝牙(串行)模块从安卓应用程序中读取一个字符串到我的板上。该字符串由滑块确定,并且应该具有来自 的值-30 to 30
。
使用 MIT 应用程序生成器,变量的输出类型不清楚:
它说send text
,所以我假设这是一个字符串。我想在我的代码中读取这个字符串(使用mbed
)。
使用:
#include "mbed.h"
#include <string>
#include <sstream>
Serial bluetooth (PTC17, PTC16);
Serial pc(USBTX, USBRX);
void ReadSerial (void);
volatile char Slider;
int main()
{
bluetooth.baud(38400);
bluetooth.attach(&ReadSerial);
}
void ReadSerial()
{
Slider = bluetooth.getc();
pc.printf("got string\n");
pc.printf("string is %c\n", Slider);
}
打印到串行终端时给了我string is x
或其他奇怪的符号。.string is £
我知道从字符串到字符的转换一定会出错,但我一直在寻找解决方案。为什么会发生这种情况,我怎样才能将此字符串直接写入我的代码中?
注意我也尝试使用bluetooth.gets()
, 并printf("", stringname.c_str())
达到相同的效果。
解决方案
推荐阅读
- spring - Websockets ExecutorSubscribableChannel 类每 15 秒发送一次心跳
- angular - 使用单元测试在 RxJS 管道中执行逻辑
- airflow - XCOM 和 BashOperators 的气流依赖
- mysql - 修改 MySQL 语句以允许更新
- sql - SQL Server 部分数据透视
- abap - 如何检查客户系统是否为 S/4 HANA Essentials(多租户)
- reactjs - 使用 typescript 模拟 forwardRef 组件 jest mockImplementation
- c++ - 使美元和插入符号仅在字符串的开头/结尾匹配,而不是在嵌入换行符之前/之后
- r - 在 Ubuntu 20.04 上安装 biomaRt R 包时出现 CURL_OPENSSL_3 问题
- java - Java 文件复制到非空目标文件夹