This is a yet another alternative application for Windows HyperTerminal and a C#.NET Version of Serial Port Interfacing with VB.net 2010.
With this application/s, it allows you to sniff/trace/monitor all the received and transmitted data through serial port and saves you time to debug your programs. It also enables you to temporarily emulate such devices with certain Serial Protocol by sending series of Data through it.
This article will give you an overview how to make your own Serial Terminal with C#.NET using Visual C#.NET 2010 Express Edition.

- From Visual C#.NET window, create a new project/solution. File > Project > Windows >Windows Form Application.
- Named the Project as PhilRoboticsTerminal, and press OK.
- Right click on Form1.cs and rename it to Main.cs.
- Click on the Form1 and go to Properties Window, look for the (Name) field (See View and Click Properties Window just in case the window haven’t shown yet). Named it as fclsMain, fcls short for Form Class and Main indicates that, this is the Main Form of this Project.
- From the Properties window, you can change its properties to anything that you would want for your project, in our case, we have changed the following:
- FormBorderStyle = Fixed3D
- MaximizeButton = false
- ShowIcon = false
- StartPosition = CenterScreen
- Text = PhilRobotics Serial Terminal

- Next we will add all the needed components for our Project, from the Toolbox, drag and drop items, 1 Menu Strip, 1 CheckBox(inside of MenuStrip), 7 Buttons, 3 label, 1 linklabel, 4 TextField and 1 StatusStrip, place them according to your desire and rename each items to:
- MenuStrip = menuTerminal
- Buttons = btnRefresh, btnASCII, btnHEX, btnSend1, btnSend2, btnSend3, btnClear
- Labels = lblTransmit, lblReceived, lblStatus,
- LinkLabel = lnkStatus
- CheckBox = chkConnect
- Lastly, we will add the most important component of our Project, the SerialPort Class and name it MySerial

- Now all the needed items/components were placed, we will now modify their properties according to our needs, first in our menuTerminal, click on the DropDownArrow and add two DropDownBox and name it as follows:
- ComboBox = cobCOMPort, cobBaudRate
- Place the CheckBox along with the ComboBox in our MenuStrip, Change its Appearance into Button and its Text to &Connect.
- Click on txtReceived textbox and set its MultiLine Property to True.
- Rename all the Text of each items according to your desire.
- You may consider to follow the arrangements and Text based on the Picture posted above.
- Now We are ready to Hard Code our preferences in Code View(hit F7 at Design View).

To Complete the code Copy and Paste the following in Code View:
/////////////////////////////////////////////////////////////////////////////////
// PhilRobotics(http://philrobotics.com);
// ElectronicsLab Philippines(http://electronicslab.ph/forum)
//
// Project Name: PhilRobotics Serial Terminal
//
// November 18, 2010
//
// Programmer: Giancarlo Acelajado
//
/////////////////////////////////////////////////////////////////////////////////
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.Diagnostics;
using System.IO.Ports;namespace PhilRoboticsTerminal
{
public partial class frmMain : Form
{
private static bool blASCII = false;
StringBuilder MyStrBld = new StringBuilder();public frmMain()
{
InitializeComponent();}
private void GetCOMPorts()
{
string[] ListCom = SerialPort.GetPortNames();cobCOMPort.Items.Clear();
foreach (string str in ListCom)
{
cobCOMPort.Items.Add(str);
}
}private void btnRefresh_Click(object sender, EventArgs e)
{
GetCOMPorts();
}private void chkConnect_CheckedChanged(object sender, EventArgs e)
{
if (chkConnect.Checked)
{
MySerial.BaudRate = Convert.ToInt16(cobBaudrate.Text);
MySerial.PortName = cobCOMPort.Text;MySerial.Open();
txtSend1.Enabled = true;
txtSend2.Enabled = true;
txtSend3.Enabled = true;btnSend1.Enabled = true;
btnSend2.Enabled = true;
btnSend3.Enabled = true;btnRefresh.Enabled = false;
cobBaudrate.Enabled = false;
cobCOMPort.Enabled = false;chkConnect.Text = “&Disconnect”;
StatLabel.Text = “Connected at ” + cobCOMPort.SelectedItem.ToString();
}
else
{
MySerial.Close();
MySerial.Dispose();txtSend1.Enabled = false;
txtSend2.Enabled = false;
txtSend3.Enabled = false;btnSend1.Enabled = false;
btnSend2.Enabled = false;
btnSend3.Enabled = false;btnRefresh.Enabled = true;
cobBaudrate.Enabled = true;
cobCOMPort.Enabled = true;chkConnect.Text = “&Connect”;
StatLabel.Text = “Disconnected at ” + cobCOMPort.SelectedItem.ToString();
}
}private void frmMain_Load(object sender, EventArgs e)
{
txtSend1.Enabled = false;
txtSend2.Enabled = false;
txtSend3.Enabled = false;btnSend1.Enabled = false;
btnSend2.Enabled = false;
btnSend3.Enabled = false;btnRefresh.Enabled = true;
//Get All COM Ports Available
GetCOMPorts();
cobCOMPort.SelectedIndex = 0;cobBaudrate.SelectedIndex = 3;
blASCII = true;
btnASCII.Enabled = false;
btnHEX.Enabled = true;
}private void btnASCII_Click(object sender, EventArgs e)
{
btnASCII.Enabled = false;
btnHEX.Enabled = true;blASCII = true;
}private void btnHEX_Click(object sender, EventArgs e)
{
btnHEX.Enabled = false;
btnASCII.Enabled = true;blASCII = false;
}private void btnSend1_Click(object sender, EventArgs e)
{
List<string> lstData = new List<string>();
if (txtSend1.Text != “”)
{
if (!blASCII)
{
foreach (char chr in txtSend1.Text)
{
//lstData.Add(Convert.ToByte(chr).ToString(“x”));
MySerial.Write(Convert.ToByte(chr).ToString(“x”) + ” “);
}
//MySerial.Write(lstData.ToString());
MySerial.Write(“\r\n”);
}
else
MySerial.Write(txtSend1.Text + “\r\n”);
}
}private void btnSend2_Click(object sender, EventArgs e)
{
List<string> lstData = new List<string>();if (txtSend2.Text != “”)
{
if (!blASCII)
{
foreach (char chr in txtSend2.Text)
{
//lstData.Add(Convert.ToByte(chr).ToString(“x”));
MySerial.Write(Convert.ToByte(chr).ToString(“x”) + ” “);
}
//MySerial.Write(lstData.ToString());
MySerial.Write(“\r\n”);}
else
MySerial.Write(txtSend2.Text + “\r\n”);
}
}private void btnSend3_Click(object sender, EventArgs e)
{
List<string> lstData = new List<string>();
if (txtSend3.Text != “”)
{
if (!blASCII)
{
foreach (char chr in txtSend3.Text)
{
//lstData.Add(Convert.ToByte(chr).ToString(“x”));
MySerial.Write(Convert.ToByte(chr).ToString(“x”) + ” “);
}
//MySerial.Write(lstData.ToString());
MySerial.Write(“\r\n”);}
else
MySerial.Write(txtSend3.Text + “\r\n”);
}
}private void PrintMe(object sender, EventArgs e)
{
txtReceived.Text = MyStrBld.ToString();
//MyStrBld.Remove(0, MyStrBld.Length);
}private void MySerial_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
//MessageBox.Show(MySerial.ReadChar().ToString());
if (blASCII)
{
MyStrBld.Append(MySerial.ReadTo(“\r\n”).ToString());
}
else
{
MyStrBld.Append(MySerial.ReadTo(“\r\n”).ToString());}
MyStrBld.AppendLine();
this.Invoke(new EventHandler(PrintMe));
//MyStrBld.Remove(0,MyStrBld.Length);
}private void btnClear_Click(object sender, EventArgs e)
{
txtReceived.Text = “”;
MyStrBld.Remove(0, MyStrBld.Length);
}private void linkPhilRobotics_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(“http://philrobotics.com”);
}}
}
To test the Program, Plug your Serial Device in your Serial Port or just short the TX and RX pin of your Serial Port to loop it back.
- Run the application or from Visual C# Express Edition window, hit F5 for start the Debugging.
- The Application will automatically get all the available COM ports in your System and will add it to the Combo Box (in my case it is in Port number 2), if not Hit the Refresh button in the Application.
Download the Full Detailed Project Source Code here.
Note: Transmitting and Receiving data were always appended by CRLF(CarriageReturn+LineFeed), to by pass this limit use “Serial.ReadLine(), Serial.ReadExisting() or Serial.Read()” instead of “Serial.ReadTo(“\r\n”).


January 15, 2011 at 1:38 am
ayos! may c# version na, next para sa telemetry ni Pbot
January 15, 2011 at 10:28 am
^
hehe medjo nagpahinga ko from office work kahapon, then nakita ko yan sa desktop ko at naalala ko di pa pala tapos idebug hehe.
di pa optimized ang code pero ok na..
goodluck sir sa P-Bot Telemetry mo =)
will try to develop a software para sa mga robot..=) right now, im developing something to be posted in our project section soon=)
more power philrobotics!=)
January 27, 2011 at 8:12 am
dapat pala ito ang ginamit ko pang test kay pbot
February 18, 2013 at 7:06 am
Looks good though the link for, Full Detailed Project Source Code here, does not seem to work. It says the page is invalid.