!7 cmodule RunVectorSDK > DynPrintLogAndEnabled { transient Process process; transient PrintStream out; S toSay; start-thread { dm_reloadOnFieldChange enabled(); if (!enabled) ret; //File script = userDir("vector-sdk/cam-stream-to-stdout.py"); File script = userDir("vector-sdk/control-from-java-v2.py"); assertFileExists(script); makeExecutable(script); print("Calling " + script); process = Runtime.getRuntime().exec(platformQuoteOpt(script)); print("SDK process started"); print("PID: " + getOpt(process, "pid")); drainErrorStreamToConsole(process, line -> enabled, lambda0 enter); out = new PrintStream(process.getOutputStream()); DataInputStream in = new(process.getInputStream()); S line; while ((line = in.readLine()) != null) { if (enabled) print("Got line: " + takeFirst(100, line)); } } void cleanMeUp_process { if (process != null) { print("Stopping SDK process"); process.destroy/*Forcibly*/(); print("Stopped SDK process, hopefully"); } } visual centerAndSouthWithMargin(super, withMargin( dm_textFieldAndSubmit_q toSay(r { say(toSay) }, buttonText := "Say"))); // API void eval(S pythonCode) { if (empty(pythonCode)) ret; out.println(jsonEncode(pythonCode)); out.flush(); } // returns true if (probably) successful bool say(S s) { if (out == null) false; s = newLinesToSpaces_trim(s); if (empty(s)) true; print("Making Vector say: " + s); // with release_control, there is "unknown error" after first utterance eval(linesLL(//"try:", " robot.conn.request_control(timeout=5.0)", " robot.behavior.say_text(" + pythonQuote(s) + ")", //"finally:", //" robot.conn.release_control()" )); true; } }