From ec4f9b4a0e349a8d019ad79d1954aebe370188ab Mon Sep 17 00:00:00 2001 From: Wessel Tip Date: Tue, 2 Jul 2024 23:44:22 +0200 Subject: [PATCH] fix: Meer fixes --- src/Client/RobotController/newControl.cs | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Client/RobotController/newControl.cs diff --git a/src/Client/RobotController/newControl.cs b/src/Client/RobotController/newControl.cs new file mode 100644 index 0000000..404a01f --- /dev/null +++ b/src/Client/RobotController/newControl.cs @@ -0,0 +1,49 @@ +using System.Diagnostics; +using System.Text; + +namespace MotorController; + +class ChildProcess { + StringBuilder outputBuilder = new(); + ProcessStartInfo processStartInfo; + Process process; + + void Spawn() { + // Spawn a new ChildProcess + processStartInfo = new ProcessStartInfo { + CreateNoWindow = true, + RedirectStandardOutput = true, + RedirectStandardInput = true, + UseShellExecute = false, + Arguments = "./stepper.py drive", + FileName = "/usr/bin/python3" + }; + + process = new Process { + StartInfo = processStartInfo, + // enable raising events because Process does not raise events by default + EnableRaisingEvents = true + }; + + // attach the event handler for OutputDataReceived before starting the process + process.OutputDataReceived += new DataReceivedEventHandler( + delegate (object sender, DataReceivedEventArgs e) { + // append the new data to the data already read-in + outputBuilder.Append(e.Data); + } + ); + + // start the process + // then begin asynchronously reading the output + // then wait for the process to exit + // then cancel asynchronously reading the output + process.Start(); + process.BeginOutputReadLine(); + process.WaitForExit(); + process.CancelOutputRead(); + + // use the output + string output = outputBuilder.ToString(); + + } +}