ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What you're asking isn't really ROS-related. Go read a systems programming textbook or find a sockets tutorial online if you want more details.

Use the socket() and connect() system calls to set up your socket. Once you have a file descriptor, you can use the write() system call to send data on that socket. Data is data; it doesn't matter if you represent it as decimal, binary, hex, or ascii; to the computer it's all just data.

A very short snippet to construct a buffer and write it to a socket is:

uint8_t buffer[] = { 0x00, 0x84, 0x00, 0x00, 0x00, 0x06, 0x54, 0x03, 0x00, 0x01, 0x00, 0x04 };
int err = write(socket_file_descriptor, buffer, 12);

and don't forget to check the return code! The return code from write will tell you if you've lost the network connection to your device, and a variety of other useful things that will help you debug future issues.