Skip to content

Commit 4ba1b18

Browse files
committed
add delay after transmit
1 parent a943aa5 commit 4ba1b18

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

c++/src/dynamixel_sdk/port_handler_mac.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,18 @@ int PortHandlerMac::readPort(uint8_t *packet, int length)
122122

123123
int PortHandlerMac::writePort(uint8_t *packet, int length)
124124
{
125-
return write(socket_fd_, packet, length);
125+
int result = write(socket_fd_, packet, length);
126+
127+
// Wait Tx Done
128+
int unsent = 1;
129+
while (unsent > 0) {
130+
ioctl(socket_fd_, TIOCOUTQ, &unsent);
131+
}
132+
unsigned int tx_time = ((float)(length * 10) / baudrate_) * 1000000000;
133+
struct timespec delay = {0, tx_time};
134+
nanosleep(&delay, NULL);
135+
136+
return result;
126137
}
127138

128139
void PortHandlerMac::setPacketTimeout(uint16_t packet_length)

0 commit comments

Comments
 (0)