-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
44 lines (41 loc) · 1.32 KB
/
test.cpp
File metadata and controls
44 lines (41 loc) · 1.32 KB
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
38
39
40
41
42
43
44
// サンプルコード兼動作テスト用のコードのつもり
// 使い方 : makeでビルド出来ます. sudo ./testで実行
// 引数に送信したいid cmd dataを10進数で入れるとそれを送ります.
// 引数が足りないとid=1, cmd=2, data=255で通信を行います.
// 最初に送信するデータを表示し, 通信が終わると結果を表示します.
#include <iostream>
#include "RasPiMS.hpp"
using namespace std;
using namespace RPMS;
int main(int argc, char *argv[]) {
MotorSerial ms; // すべてデフォルト値でインスタンスを生成
ms.setTimeOut(1000); // 1秒のタイムアウトを設定
try {
ms.init(); // 初期化
}
catch(runtime_error exception) {
cout << "Setup Error" << endl;
return -1;
}
unsigned char id, cmd;
unsigned short data;
if (argc < 4) {
id = 1;
cmd = 2;
data = 255;
} else {
id = (unsigned char)stoi(argv[1]);
cmd = (unsigned char)stoi(argv[2]);
data = (short)stoi(argv[3]);
}
cout << (int)id << " " << (int)cmd << " " << (int)data << endl;
try {
cout << ms.send(id, cmd, data) << endl; // 同期モードで通信
}
catch(runtime_error exception) {
cout << "Communication Error." << endl;
return -1;
}
cout << (ms.sumCheckSuccess ? "Receive Success" : "Receive Failed") << endl; // 通信の成否を確認, 表示
return 0;
}