Control of Dynamixel MX28R via RS485
This certainly won't work:

int res = write(socket_fd_, packet, length);
// delay2
digitalWrite (RES_PIN, LOW); // &lt;&lt;&lt;&lt;


The reason is that write() is asynchronous, and just puts bytes into the outgoing serial port buffer; it does not wait for the data to finish sending.
You can use tcgetattr() followed by tcsetattr() with TCSADRAIN to make sure the output buffer gets fully flushed before you switch direction back.

#include &lt;termios.h&gt;

// call this after you've called write() for the data,
// before you attempt to switch direction again.
struct termios tio;
tcgetattr(fd, &amp;tio);
tcsetattr(fd, TCSADRAIN, &amp;tio);


Other than that, what does the oscilloscope or logic probe say about the three wires you're supposed to be changing from the Pi? (RX, TX, and DIR)