From 839d90c4ab6734907515b12ed6fd0ad3ab91f799 Mon Sep 17 00:00:00 2001 From: Thomas Timm Andersen Date: Wed, 28 Oct 2015 11:25:59 +0100 Subject: [PATCH] Added a check to see that the robot is connected before attempting to write to the socket. Fixes #11 --- src/ur_realtime_communication.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ur_realtime_communication.cpp b/src/ur_realtime_communication.cpp index 62724bb..c4881c0 100644 --- a/src/ur_realtime_communication.cpp +++ b/src/ur_realtime_communication.cpp @@ -89,7 +89,10 @@ void UrRealtimeCommunication::addCommandToQueue(std::string inp) { if (inp.back() != '\n') { inp.append("\n"); } - bytes_written = write(sockfd_, inp.c_str(), inp.length()); + if (connected_) + bytes_written = write(sockfd_, inp.c_str(), inp.length()); + else + print_error("Could not send command \"" +inp + "\". The robot is not connected! Command is discarded" ); } void UrRealtimeCommunication::setSpeed(double q0, double q1, double q2,