-
Notifications
You must be signed in to change notification settings - Fork 0
/
rawdata.cpp
37 lines (33 loc) · 1.16 KB
/
rawdata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <QCoreApplication>
#include "bcf.h"
using namespace std;
/**
* @file : rawdata.cpp
* @brief : 演示bcf如何不使用协议model进行通信,而是使用原始数据裸流进行通信
*/
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
std::shared_ptr<bcf::IChannel> tmpChannel;
auto requestPtr = bcf::RequestHandlerBuilder()
.withChannel([&tmpChannel]() {
tmpChannel = std::make_shared<bcf::SerialChannel_QT>("COM2"); //使用bcf内部的串口通道类
tmpChannel->setRawDataCallback([](std::shared_ptr<bb::ByteBuffer> bb) {
bb->data();
bb->printHex();
});
return tmpChannel;
})
.withFailedCallback([]() {
std::cerr << "withFailedCallback" << std::endl;
})
.withConnectionCompletedCallback([](std::shared_ptr<bcf::IChannel> channel) {
std::cout << "withConnectionCompletedCallback channelID:" << channel->channelID();
})
.build();
requestPtr->connect();
assert(tmpChannel != nullptr);
std::string str("this is 1 times request");
tmpChannel->send(str.data(), str.length());
return app.exec();
}