Browse Source

added try catch to cpp project to hopefully handle not connected motors when trying to initialize

Vincenz Mechler 5 years ago
parent
commit
4856b1bdaa

+ 9 - 4
SketchAssistant/StaticLib1/ArmbandInterface.cpp

@@ -122,8 +122,7 @@ extern "C" {
 			return 8;
 		}
 		//initialize the BodyActuator instance
-		setupMotors();
-		return -1;
+		return setupMotors();
 	}
 
 	/*
@@ -202,10 +201,16 @@ extern "C" {
 /*
 internal method to initialize the BodyActuator object (and handle the memory allocation involved)
 */
-void ArmbandInterface::setupMotors() {
+int ArmbandInterface::setupMotors() {
 	 char* port = (char*) "COM5";//malloc(7);
 	 armband = (BodyActuator*) malloc(sizeof(BodyActuator*));
 	 //strcpy_s(port, "COM5");
-	(initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, port, 8);
+	 try {
+		 (initFunctionHandle)(armband, BODYACTUATOR_TYPE_EAI, port, 8);
+		 return -1;
+	 }
+	 catch (...) {
+		 return -99;
+	 }
 	//printf("armband initialized");
 }

+ 1 - 1
SketchAssistant/StaticLib1/ArmbandInterface.h

@@ -76,5 +76,5 @@ class ArmbandInterface
 		/*
 		internal method to initialize the BodyActuator object (and handle the memory allocation involved)
 		*/
-		void setupMotors();
+		int setupMotors();
 };