Now that we have created our SerialPort object, we need to open the port using the Open() method.
You can find the full list of constructors in the link in the intro. There are several constructors to choose from to specify different frame formats but in general the easiest to use is the following: SerialPort(string portName, int baudRate) An example of this would be: SerialPort mySerialPort = new SerialPort( “COM3”, 9600) Here I am using COM3 at 9600 baud. We need to include two namespaces in order to use the SerialPort class: using System.IO.Ports using System.IO We now need to instantiate a SerialPort object. Feel free to post questions or feedback! I am always happy to hear constructive comments so I can make improvements.
Check it out if you get stuck with any odd errors.
I also found a great article explaining how to fix several common bugs relating to serial ports. Since we are mainly going to be using the System.IO.Ports.SerialPort class, HERE is a link to the full documentation by MSDN if you want to check out the rest of the class. This tutorial assumes that you have a very basic understanding of object oriented programing, and whatever language you choose to program in. The code examples in this tutorial are in C#, but can be easily transferred to Visual Basic, or Visual C++. In this tutorial, I will walk you through how to interface to a serial port on the computer side of things, using Microsoft's. Many times you may want your project to communicate with your computer in order to have a cool interactive output, a neat sensor that passes data to your computer, or anything else you could possibly dream up. Many platforms such as Arduino have built in serial communication so they are really easy to set up and use. They are relatively simple to use and are very common among peripherals and especially DIY projects.
Serial ports provide an easy way to communicate between many types of hardware and your computer.