HarvestX Serial Device Interface Package.
ROS2 Distro | Build status |
---|---|
humble |
- ROS 2
- Ubuntu20 : Galactic Geochelone
- Ubuntu22 : Humble Hawksbill
mkdir -p ~/ws_ros2/src
cd ~/ws_ros2/src
git clone [email protected]:HarvestX/h6x_serial_interface.git
rosdep install -r -y -i --from-paths . --rosdistro $ROS_DISTRO
Open new terminal and type followings.
source /opt/ros/$ROS_DISTRO/setup.bash
cd ~/ws_ros2
colcon build
dev
: Path of the devicebaudrate
: Baudrate
ros2 run h6x_serial_interface_example simple_read_node_exec \
--ros-args \
-p dev:=/dev/ttyUSB0 -p baudrate:=115200
dev
: Path of the devicebaudrate
: Baudrate
The sample send Hello World
as ASCII string.
ros2 run h6x_serial_interface_example simple_write_node_exec \
--ros-args \
-p dev:=/dev/ttyUSB0 -p baudrate:=115200
You can implement your own serial interface by using port_handler
.
// Header
#include <h6x_serial_interface/h6x_serial_interface.hpp>
// - Source code --------------------------------------------------------
std::string dev = "/dev/ttyUSB0";
int baudrate = 115200;
const auto port_handler = std::make_unique<h6x_serial_interface::PortHandler>(dev, baudrate);
// Open port
port_handler->openPort();
// Get available bytes
ssize_t available_bytes = port_handler->getBytesAvailable();
// Read serial packet into read_buf
char read_buf[128];
port_handler->readPort(read_buf, sizeof(read_buf));
// Write serial packet
char write_buf[] = "Hello World";
port_handler->writePort(write_buf, strlen(write_buf))
// Close port
port_handler->closePort();
// ----------------------------------------------------------------------