GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
serial_communication_thread.h
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#ifndef DESIGNLAB_SERIAL_COMMUNICATION_THREAD_H_
9#define DESIGNLAB_SERIAL_COMMUNICATION_THREAD_H_
10
11#include <Windows.h> // シリアル通信を行うために必要.
12
13#include <boost/thread.hpp>
14#include <string>
15#include <vector>
16
17namespace designlab {
18
20 public:
23
24 void Loop();
25
29 void SetWriteData(const std::string& str);
30
34 std::string GetTopReadData() const;
35
39 std::vector<std::string> GetAllReadData() const;
40
45 std::vector<std::string> GetReadData(const int num) const;
46
48 void EndThread() {
49 boost::mutex::scoped_lock lock(mutex_);
50 end_flag_ = true;
51 }
52
53 bool IsEnd() const {
54 boost::mutex::scoped_lock lock(mutex_);
55 return end_flag_;
56 }
57
58 private:
59 static constexpr float kThreadPeriod =
60 0.01f;
61 static constexpr int kBufferSize =
62 1024;
63 static constexpr int kComPortNumber = 3;
64
66 bool Initialize();
67
71 bool Read();
72
76 bool Write();
77
78 HANDLE serial_handle_{INVALID_HANDLE_VALUE};
79
80 std::vector<std::string> read_data_;
81 std::string write_data_;
82
83 bool end_flag_{false};
84
85 mutable boost::mutex mutex_;
86};
87
88} // namespace designlab
89
90#endif // DESIGNLAB_SERIAL_COMMUNICATION_THREAD_H_
void SetWriteData(const std::string &str)
指定した文字列をシリアル通信で送信する. この時,排他制御を行う.
void EndThread()
シリアル通信のスレッドを終了する.
std::string GetTopReadData() const
シリアル通信で受信した最新の文字列を取得する. この時,排他制御を行う.
std::vector< std::string > GetAllReadData() const
シリアル通信で受信した文字列を全て取得する. この時,排他制御を行う.
std::vector< std::string > GetReadData(const int num) const
シリアル通信で受信した文字列の中から指定した数だけ取得する. この時,排他制御を行う.