EDN Admin
Well-known member
Hi everyone,
Im trying to use C# to control a command line application background, which can be downloaded here:
http://www.ti.com/litv/zip/spmc015b http://www.ti.com/litv/zip/spmc015b
This is an app for motor voltage control, when I enter the app, like "b.exe -c 1", the console seems a kind of blocking model. Every command in this app begins with "#" symbol. See pics below:
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/99424
What Im trying to do is, use StandardInput.WriteLine("stat vout"); to measure the voltage. This will send a "stat vout" command to the console background and ideally return a voltage value. In this pic, it return some help hints. Duing all this time,
it still in the blocking mode.
I want to get the return message with StandardOutput.ReadLine(); but failed. If ReadToEnd() then my program is freezed because this app never return to standard console, which is blocking.
When I tried BeginOutputReadLine(); OutputDataReceived event can truly obtain the message return from the console, like in the pics of "stat [vout|vbus|fault". But it limited in my single thread program.
My current situation is that, I use System.Timers.Timers in WinForms and every second will send a "stat vout2" command to read the voltage, and hopefully get the return value.
However, the System.Timers.Timers is asynchronous, so when I called BeginOutputReadLine() in this Timers thread, it prompted "An async read operation has already been started on the stream." In the meantime, as Ive demonstrated above, I cannot use synchronous
methods like ReadLine() to get the value.
So what should I do now? I truly need to run this command line app in multi-threading mode.
Thanks so much and wish everybody has a nice weekend.
View the full article
Im trying to use C# to control a command line application background, which can be downloaded here:
http://www.ti.com/litv/zip/spmc015b http://www.ti.com/litv/zip/spmc015b
This is an app for motor voltage control, when I enter the app, like "b.exe -c 1", the console seems a kind of blocking model. Every command in this app begins with "#" symbol. See pics below:
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/99424
What Im trying to do is, use StandardInput.WriteLine("stat vout"); to measure the voltage. This will send a "stat vout" command to the console background and ideally return a voltage value. In this pic, it return some help hints. Duing all this time,
it still in the blocking mode.
I want to get the return message with StandardOutput.ReadLine(); but failed. If ReadToEnd() then my program is freezed because this app never return to standard console, which is blocking.
When I tried BeginOutputReadLine(); OutputDataReceived event can truly obtain the message return from the console, like in the pics of "stat [vout|vbus|fault". But it limited in my single thread program.
My current situation is that, I use System.Timers.Timers in WinForms and every second will send a "stat vout2" command to read the voltage, and hopefully get the return value.
However, the System.Timers.Timers is asynchronous, so when I called BeginOutputReadLine() in this Timers thread, it prompted "An async read operation has already been started on the stream." In the meantime, as Ive demonstrated above, I cannot use synchronous
methods like ReadLine() to get the value.
So what should I do now? I truly need to run this command line app in multi-threading mode.
Thanks so much and wish everybody has a nice weekend.
View the full article