Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
41Activity
0 of .
Results for:
No results containing your search query
P. 1
Serial Port Communication in C#

Serial Port Communication in C#

Ratings:

4.67

(6)
|Views: 17,337 |Likes:
Published by Ionela
The serial port is a serial communication interface through which information transfers in or out one bit at a time.
A quick search on Google reveals that there are a lot of free serial port monitor applications available for PC users.
The serial port is a serial communication interface through which information transfers in or out one bit at a time.
A quick search on Google reveals that there are a lot of free serial port monitor applications available for PC users.

More info:

Published by: Ionela on Sep 23, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/10/2013

pdf

text

original

 
Serial Port Communication in C#http://dev.emcelettronica.com/print/519471 din 422.09.2008 09:13
Your Electronics Open Source
(http://dev.emcelettronica.com)
Home > Blog > brumbarchris's blog > Contenuti
Serial Port Communication in C#
By brumbarchrisCreated 09/05/2008 - 21:02
Programming C# serial port serial port communicationThe serial port is a serial communication interface through which information transfers in orout one bit at a time.A quick search on Google reveals that there are a lot of free serial port monitor applicationsavailable for PC users. However, what these applications lack, is the possibility of controllingthe serial port in a direct manner. They are generally good “sniffers” but they do not allow theuser to actually write to the serial port or control any device attached to it. The applicationswith the write capability encapsulated are not for free, and the cheapest costs about 50 Euro – a great deal of money taking into account how easy it is to make a personalized application.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.For the example application, I have used the SharpDevelop development environment whichincludes a C# compiler. This is an open source IDE which takes up very little space on yourhard drive and can be a good alternative to users who do not want to install the gigabytes ofVisual Studio on their PCs for a simple serial port application.Once you have downloaded and installed the SharpDevelop environment, create a WindowsApplication project (solution) called SerialPort:
 
Serial Port Communication in C#http://dev.emcelettronica.com/print/519472 din 422.09.2008 09:13
 Once you have created the application, display the windows form that was automaticallycreated (by clicking on the “Design” button at the bottom of the screen) and unroll the menuavailable under “Components” available on the left-hand menu: You will notice that one of the components available here is the one called “SerialPort”. Pickthat component and drag&drop it over the surface of the form on the right. This will add thecomponent to your project. The object that is created is called “serialPort1” and it will be usedto access the serial port. To be able to use this component, however, you need to add at thebeginning of your code the directive for using the System.IO.Ports namespace, as this is not
 
Serial Port Communication in C#http://dev.emcelettronica.com/print/519473 din 422.09.2008 09:13
added by default when you create the solution:
using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;using System.IO.Ports;
Once this is done, create a regular button on the surface of the form, call it “button1” andchange its label to “Write”. Then double click on it in order to create the function that will beexecuted when the button is clicked.In this function we will perform several tasks. The first one is to configure the baud rate, COMport, number of data bits, parity and stop bits of the communication:
//configuring the serial portserialPort1.PortName="COM1";serialPort1.BaudRate=9600;serialPort1.DataBits=8;serialPort1.Parity=Parity.None;serialPort1.StopBits= StopBits.One;
Next, before writing to the port, it needs to be opened:
//opening the serial portserialPort1.Open();
Please note that if the COM1 port is already used by an application, you will get an errormessage when this instruction is executed. Alternatively, if you open the COM1 port with yourC# application and then fail to close it, any other application trying to use it will not be able todo that.OK, it is now time to write to the serial port:

Activity (41)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
munhkbayar liked this
Teddy Augustus liked this
Arjun Janardanan liked this
talkboard liked this
Salmal Bandara liked this
Mark Collins liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->