Serial Port Communication in C#
The serial port of the PC is a very important resource both in industrial environment and in home-made electronics, due to the wide popularity of the UART interface which is to be found on many microcontrollers or on many test and design instrumentation (programmable power supplies, multi-meters, oscilloscopes etc). Even if modern-day computers tend not to have a physical serial port anymore, this obstacle is overcome by the appearance on the market of USB to UART converters (like the FTDI chips for example) which can emulate serial ports. Thus, from a computer application point of view, writing to such a device is as easy as writing to a regular serial port.
The serial port is a serial communication interface through which information transfers in or out one bit at a time. This article will show how it is possible to build such an application using the C# environment. It is not intended to be a C# tutorial, but to teach a user who has basic knowledge of C or C# to integrate serial port control in one of his applications. A development environment which includes a C# compiler should be used. There are many open source IDE which takes up very little space on your hard drive and can be a good alternative to users who do not want to install the gigabytes of Visual Studio on their PCs for a simple serial port application.
2. Code Design
To be able to use “SerialPort” component is need to add at the beginning of your code the directive for using the System.IO.Ports namespace, as this is not added by default when you create the solution:
For more detail: Serial Port Communication in C#
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
Cheapest PCB Prototype: Only $2 for 10pcs 10×10cm PCBs, 24 hours Quick Turn, DHL Delivery in 3 Days