]> Git Repo - serial.git/blame - serial/src/test_serial.cpp
Simple sync read working.
[serial.git] / serial / src / test_serial.cpp
CommitLineData
7587b16f
WW
1#include "ros/ros.h"
2
3#include <string>
4#include <iostream>
5
6#include "serial.h"
7
8Serial *serial;
9
10std::string toHex(std::string input) {
11 std::stringstream ss;
12 for(int i = 0; i != input.length(); i++) {
13 char temp[4];
14 sprintf(temp, "%.2X", input[i]);
15 ss << " ";
16 if(input[i] == 0x0A)
17 ss << "LF";
18 else if(input[i] == 0x0D)
19 ss << "NL";
20 else
21 ss << input[i];
22 ss << " " << std::hex << temp;
23 }
24 return ss.str();
25};
26
27int main(int argc, char **argv)
28{
29 ros::init(argc, argv, "serial_test_node");
30
31 ros::NodeHandle n;
32
33 std::string port("/dev/tty.usbserial-A900cfJA");
34
35 serial = new Serial(port);
36
37 ros::Rate loop_rate(10);
38
39 while (ros::ok()) {
40 std::string result = serial->read(1);
41
42 ROS_INFO("%d,%s", result.length(), toHex(result).c_str());
43
44 ros::spinOnce();
45
46 loop_rate.sleep();
47 }
48
49 return 0;
50}
This page took 0.025139 seconds and 4 git commands to generate.