高分求改一段代码 把控制台程序改为winform
下面的代码有1个线程接受控制台程序屏幕输入,现要改为winform就没有屏幕输入,所以就接受textbox输入就可以,把控制台程序屏幕输出改为textbox输出。using System;
using System.IO;
using System.Threading;
using LoMaN.IO;
namespace SerialStreamReader {
class App {
// The main serial stream
static SerialStream ss;
[STAThread]
static void Main(string[] args) {
// Create a serial port
ss = new SerialStream();
try {
ss.Open("COM1");
}
catch (Exception e) {
Console.WriteLine("Error: " + e.Message);
return;
}
// Set port settings
ss.SetPortSettings(9600);
// Set timeout so read ends after 20ms of silence after a response
ss.SetTimeouts(20, 0, 0, 0, 0);
// Create the StreamWriter used to send commands
StreamWriter sw = new StreamWriter(ss, System.Text.Encoding.ASCII);
// Create the Thread used to read responses
Thread responseReaderThread = new Thread(new ThreadStart(ReadResponseThread));
responseReaderThread.Start();
// Read all returned lines
for (;;) {
// Read command from console
string command = Console.ReadLine();
// Check for exit command
if (command.Trim().ToLower() == "exit") {
responseReaderThread.Abort();
break;
}
// Write command to modem
sw.WriteLine(command);
sw.Flush();
}
}
// Main loop for reading responses
static void ReadResponseThread() {
StreamReader sr = new StreamReader(ss, System.Text.Encoding.ASCII);
try {
for (;;) {
// Read response from modem
string response = sr.ReadLine();
Console.WriteLine("Response: " + response);
}
}
catch (ThreadAbortException) {
}
}
}
}
--------------------编程问答-------------------- 不难的啊
Console.ReadLine() 修改成从缓存行读入
缓存行来自textboxin就可以了
Console.WriteLine() 改成textboxout的文本显示
lz自己多想想 --------------------编程问答-------------------- 新建一个winform的项目,再相应改改就好。 --------------------编程问答-------------------- 自力更生,丰衣足食
补充:.NET技术 , C#