代码拉取完成,页面将自动刷新
同步操作将从 liushuai/SmartSerial 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "SmartSerial.h"
#include "log.h"
static void listPort() {
auto ports = serial::list_ports();
if (ports.empty()) {
LOGI("No Any Port!");
}
for (const auto& info : ports) {
static int count;
LOG("list port [%d]:", count++);
// Port
// macOS: /dev/cu.usbmodem8D8842A649551
// Linux: /dev/ttyACM0
// Windows: COM6
LOG("port:%s", info.port.c_str());
// Description
// macOS: Scope STM32 Virtual ComPort
// Linux: Scope STM32 Virtual ComPort 8D8842A64955
// Windows: USB 串行设备 (COM6)
LOG("description:%s", info.description.c_str());
// ID
// mac: USB VID:PID=1234:5740 SNR=8D8842A64955
// lin: USB VID:PID=1234:5740 SNR=8D8842A64955
// win: USB\VID_1234&PID_5740&REV_0200
LOG("hardware_id:%s", info.hardware_id.c_str());
}
}
int main(int argc, char **argv) {
std::string portName = argc >= 2 ? argv[1] : "/dev/tty.usbserial-1460";
listPort();
SmartSerial smartSerial(portName, 115200, [](bool isOpen) {
// handle very likely on other thread
LOGI("on open handle: %d", isOpen);
});
// handle will on other thread
smartSerial.setOnReadHandle([&](const uint8_t* data, size_t size) {
static int count = 0;
auto str = std::string((char*)data, size);
LOGI("on read handle: size:%zu, data:%s, count=%d", size, str.c_str(), count++);
});
int count = 0;
for(;;) {
std::this_thread::sleep_for(std::chrono::seconds(1));
smartSerial.write("hello world");
LOG("write count: %d", ++count);
if (count == 3) {
smartSerial.open();
} else if (count == 6) {
smartSerial.close();
} else if (count == 8) {
break;
}
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。