может что-то типа:
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Windows.Forms;
namespace serialport_process
{
class Program
{
class OutputForm : Form
{
public RichTextBox richTextBox {get ;private set;}
public OutputForm()
{
WindowState = FormWindowState.Maximized;
richTextBox = new RichTextBox
{
Dock = DockStyle.Fill
};
}
}
static Encoding ENCODING = Encoding.ASCII;
const int BUFFER_SIZE = 4096;
static byte[] buffer = new byte[BUFFER_SIZE];
delegate void AppendText(string inText);
static void Main(string[] args)
{
var form = new OutputForm();
var task = new Task(() =>
{
var serialPort = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.Two);
serialPort.DataReceived += (sender, e) =>
{
var count = serialPort.BytesToRead;
while (count > 0)
{
var current_count = serialPort.Read(buffer, 0, count < BUFFER_SIZE ? count : BUFFER_SIZE);
var text = ENCODING.GetString(buffer, 0, current_count);
count -= current_count;
form.Invoke((AppendText)(txt => form.richTextBox.AppendText(txt)), text);
}
};
serialPort.Open();
while (true) ;
});
form.Load += (sender, e) => task.Start();
Application.Run(form);
}
}
}
не проверял, но начал бы с этого...