I am very new to streaming. Hope someone can give me an example.
I try to start a thread when the user clicks the start button and performs the following process:
private void btnStart_Click(object sender, RoutedEventArgs e) { if (serialPort.IsOpen) serialPort.Close(); try { //To set all the parameters for Serial Comm serialPort.PortName = "COM14"; serialPort.BaudRate = int.Parse("38400"); serialPort.Parity = Parity.None; serialPort.DataBits = 8; serialPort.StopBits = StopBits.One; serialPort.Encoding = System.Text.Encoding.ASCII; serialPort.DataReceived += new SerialDataReceivedEventHandler(GotRawData); serialPort.Open(); //To show that Com Port is Opened txtboxOutput.AppendText(DateTime.Now.ToString("hh:mm:ss tt") + " - COM14 is opened." + Environment.NewLine); txtboxOutput.ScrollToEnd(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
private void GotRawData () is a method in which I do something to get raw data from hardware.
source share