using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace Terminal
{
public partial class MainForm : Form
{
byte[] Receive_Buffer;
int a;
Use [CODE] tags It makes the code so much more readable. I notice that in your Form.Load event handler you're using Receive_Buffer without initializing it first. You probably want to initialize and read something into Receive_Buffer before you try to convert it to a string. Also, if you specify a newline character for the SerialPort.Newline property you can simply call the SerialPort.ReadLine() method and it will read a line of text from the port and return a string. No encoding conversion necessary on your part
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
It's pretty simple really. You configure the port using the SerialPort constructor, open it, then handle the DataReceived event. In that event handler, you read the port using either Read() or ReadLine() and process the data.
You don't even have to handle the DataReceived event. You can simply poll the port to see if there is data to read and if there is, read it. But in a Windows forms app like yours, you will probably want to use the DataReceived event. Makes it a little easier
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
Bookmarks