C# Tutorials - Serial Port Communication In C# | DreamInCode.net

C# Tutorials - Serial Port Communication In C# | DreamInCode.net
C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Home
Forums
Programming
Programming Help
C and C++
VB6
Java
VB.NET
C#
Web Development
Tutorials
Snippets
ColdFusion
Perl and Python
Ruby
Freelance
Jobs
Login
Lounge
Join for Free!
Search Updated! w00t
Dream.In.Code > Programming Tutorials > C# Tutorials
Over 509,000 Pages!
Welcome to Dream.In.Code
Go
Become a C# Expert!
???????? ????
How Smart Are You?
Looking to prove your programming intelligence?
See how you compare.
www.cambriancode.com
Advanced Forum Search
Join 289,290 C# Programmers for FREE!
Live C# Help!
Get instant access to thousands
of C# experts, tutorials, code
ASP.NET
PHP
Blogs
C# Code Library
Open Source Code Snippet Library. Free
Community for Developers.
snippets, and more! There are
www.daniweb.com/code
Registration is fast and
Databases
Free C# Component
Free .NET security component for user mgmt and
access control.
Other Languages
www.PortSight.com/SecureAccess
3,285 people online right now.
FREE... Join Now!
Chat LIVE With a C# Expert
Game Programming
Be Social
Mobile Development
Software Development
Computer Science
Industry News
Serial Port Communication in C#
2 Pages
1
2
>
Serial Port Communication in C#
Options
Serial Port Communication in
C#
Get Help With Programming, Math, Science, or English Homework!
Basic Client/Server Chat
Application in C#
Web Development
Web Development
C# Tutorials
PsychoCoder
HTML & CSS
C# Basics Quick Reference
(Cheat Sheet)
JavaScript
Create an AutoComplete
TextBox Control in C#
Graphic Design
Flash & ActionScript
20 Oct, 2007 - 07:09 PM
Post #1
Deploying a C# application
(Visual Studio Setup Project)
5
Cross Thread Communication
in C#
Welcome to my tutorial on Serial Port Communication in C#. Lately Ive seen a
Blogging
lot of questions on how to send and receive data through a serial port, so I
SEO & Advertising
thought it was time to write on the topic. Back in the days of Visual Basic 6.0,
Web Servers & Hosting
you had to use the MSComm Control that was shipped with VB6, the only
Basic Calculator in C#
Site Check
problem with this method was you needed to make sure you included that
SQL Basics in C#
control in your installation package, not really that big of a deal. The control did
Read config file in Class
Library
exactly what was needed for the task.
114 More C# Tutorials...
0
We were then introduced to .Net 1.1, VB programmers loved the fact that Visual Basic
C# - Reading each character
of a string
Reference Sheets
had finally evolved to an OO language. It was soon discovered that, with all it's OO
abilities, the ability to communicate via a serial port wasn't available, so once again
VB developers were forced to rely on the MSComm Control from previous versions of
Visual Basic, still not that big of a deal, but some were upset that an intrinsic way of
serial port communication wasn't offered with the .net Framework. Worse yet, C#
developers had to rely on a Visual Basic control and Namespace if they wanted to
communicate via serial port.
C# Snippets
Then along comes .Net 2.0, and this time Microsoft added the System.IO.Ports
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
Get connection string from the
web.config
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
Namespace, and within that was the SerialPort Class. DotNet developers finally had an
intrinsic way of serial port communication, without having to deal with the
Read value from Resource file
in C#
complexities of interoping with an old legacy ActiveX OCX control. One of the most
Populating Tree View nodes
from sql server 2000
useful methods in the SerialPort class is the GetPortNames Method. This allows you
to retrieve a list of available ports (COM1,COM2,etc.) available for the computer the
Validate IP address with
Regular Expression
application is running on.
Search Text file for String
Kill a process if its running
Now that we have that out of the way, lets move on to programming our application.
As with all application I create, I keep functionality separated from presentation, I do
this by creating Manager classes that manage the functionality for a given process.
What we will be looking at is the code in my CommunicationManager class. As with
anything you write in .Net you need to add the references to the Namespace's you'll
be using:
TreeView Drag n Drop
Check if a process is running
Get checked item in gridView
(ASP.Net) and store in
session
Find all classes within a
Namespace
400 More C# Snippets...
DIC Chatroom
CODE
What's Here?
Bye Bye Ads
Members: 289,290
using System;
Replies: 800,057
using System.Text;
Topics: 132,216
Snippets: 4,328
Join our IRC Chat
using System.Drawing;
Monthly Drawing
using System.IO.Ports;
Tutorials: 1,119
Total Online: 3,285
Members: 155
Guests: 3,130
In this application I wanted to give the user the option of what format they wanted to
send the message in, either string or binary, so we have an enumeration for that, and
Top Contributors
Top 10 Kudos This Month
gabehabe (250)
an enumerations for the type of message i.e; Incoming, Outgoing, Error, etc. The
jinnyishere (125)
main purpose of this enumeration is for changing the color of the text displayed to the
macosxnerd101 (125)
user according to message type. Here are the enumerations:
gbertoli3 (125)
noorahmad (125)
Rickster0 (100)
CODE
olibenu (100)
japanir (100)
kewlkreator (75)
#region Manager Enums
VB.Terry (50)
/// <summary>
/// enumeration to hold our transmission types
/// </summary>
public enum TransmissionType { Text, Hex }
Select
Language
Select
Language
Powered by
/// <summary>
/// enumeration to hold our message types
/// </summary>
public enum MessageType { Incoming, Outgoing, Normal, Warning,
#endregion
Next we have our variable list, 6 of them are for populating our class Properties, the
other 2 are access throughout the class so they needed to be made global:
CODE
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
Translate
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
#region Manager Variables
//property variables
private string _baudRate = string.Empty;
private string _parity = string.Empty;
private string _stopBits = string.Empty;
private string _dataBits = string.Empty;
private string _portName = string.Empty;
private TransmissionType _transType;
private RichTextBox _displayWindow;
//global manager variables
private Color[] MessageColor = { Color.Blue, Color.Green, Col
private SerialPort comPort = new SerialPort();
#endregion
NOTE:I always separate my code into sections using the #region ... #endregion to
make it easier when scanning my code. It is a design choice so it's not necessary if
you don't want to do it.
Now we need to create our class properties. All the properties in this class are public
read/write properties. We have properties for the following items of the Serial Port:
Baud Rate: A measure of the speed of serial communication, roughly equivalent
to bits per second.
Parity: The even or odd quality of the number of 1's or 0's in a binary code,
often used to determine the integrity of data especially after transmission.
Stop Bits: A bit that signals the end of a transmission unit
Data Bits: The number of bits used to represent one character of data.
Port Name: The port with which we're communicating through, i.e; COM1,
COM2, etc.
We also have 2 properties that aren't related to the port itself, but with where the
data will be displayed, and what transmission type to use:
CODE
#region Manager Properties
/// <summary>
/// Property to hold the BaudRate
/// of our manager class
/// </summary>
public string BaudRate
{
get { return _baudRate; }
set { _baudRate = value; }
}
/// <summary>
/// property to hold the Parity
/// of our manager class
/// </summary>
public string Parity
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
{
get { return _parity; }
set { _parity = value; }
}
To be able to instantiate any class object we create we need Constructors.
Constructors are the entry point to your class, and is the first code executed when
instantiating a class object. We have 2 constructors for our manager class, one that
sets our properties to a specified value, and one that sets our properties to an empty
value, thus initializing the variables preventing a NullReferenceException from
occurring. We also add an EventHandler in the constructor, the event will be executed
whenever there's data waiting in the buffer:
CODE
#region Manager Constructors
/// <summary>
/// Constructor to set the properties of our Manager Class
/// </summary>
/// <param name="baud">Desired BaudRate</param>
/// <param name="par">Desired Parity</param>
/// <param name="sBits">Desired StopBits</param>
/// <param name="dBits">Desired DataBits</param>
/// <param name="name">Desired PortName</param>
public CommunicationManager(string baud, string par, string sB
{
_baudRate = baud;
_parity = par;
_stopBits = sBits;
_dataBits = dBits;
_portName = name;
_displayWindow = rtb;
//now add an event handler
comPort.DataReceived += new SerialDataReceivedEventHandler
The first think you need to know about serial port communication is writing data to
the port. The first thing we do in our WriteData method is to check what
transmission mode the user has selected, since binary data needs to be converted into
binary, then back to string for displaying to the user. Next we need to make sure the
port is open, for this we use the IsOpen Property of the SerialPort Class. If the port
isn't open we open it by calling the Open Method of the SerialPort Class. For writing to
the port we use the Write Method:
CODE
#region WriteData
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
public void WriteData(string msg)
{
switch (CurrentTransmissionType)
{
case TransmissionType.Text:
//first make sure the port is open
//if its not open then open it
if (!(comPort.IsOpen == true)) comPort.Open();
//send the message to the port
comPort.Write(msg);
//display the message
DisplayData(MessageType.Outgoing, msg + "\n");
break;
case TransmissionType.Hex:
try
{
//convert the message to byte array
byte[] newMsg = HexToByte(msg);
//send the message to the port
You will notice in this method we call three methods:
HexToByte
ByteToHex
DisplayData
These methods are required for this manager. The HexToByte method converts the
data provided to binary format, then the ByteToHex converts it back to hex format
for displaying. The last one, DisplayData is where we marshal a call to the thread
that created the control for displaying the data, since UI controls can only be accessed
by the thread that created them. First we'll look at converting the string provided to
binary format:
CODE
#region HexToByte
/// <summary>
/// method to convert hex string into a byte array
/// </summary>
/// <param name="msg">string to convert</param>
/// <returns>a byte array</returns>
private byte[] HexToByte(string msg)
{
//remove any spaces from the string
msg = msg.Replace(" ", "");
//create a byte array the length of the
//string divided by 2
byte[] comBuffer = new byte[msg.Length / 2];
//loop through the length of the provided string
for (int i = 0; i < msg.Length; i += 2)
//convert each set of 2 characters to a byte
//and add to the array
comBuffer[i / 2] = (
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
)Convert.ToByte(msg.Substring
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
byte
//return the array
return comBuffer;
Here we convert the provided string to a byte array, then the WriteData method
sends it out the port. For displaying we need to convert it back into string format, so
we use the ByteToHex method we created:
CODE
#region ByteToHex
/// <summary>
/// method to convert a byte array into a hex string
/// </summary>
/// <param name="comByte">byte array to convert</param>
/// <returns>a hex string</returns>
private string ByteToHex(byte[] comByte)
{
//create a new StringBuilder object
StringBuilder builder = new StringBuilder(comByte.Length *
//loop through each byte in the array
foreach (byte data in comByte)
//convert the byte to a string and add to the stringbu
builder.Append(Convert.ToString(data, 16).PadLeft(2,
//return the converted value
return builder.ToString().ToUpper();
}
#endregion
The last method that WriteData depends on is the DisplayData method. Here we
use the Invoke Method of our RichTextBox, the control used to display the data, to
create a new EventHandler which creates a new Delegate for setting the properties we
wish for our message, then appending it to the value already displayed:
CODE
#region DisplayData
/// <summary>
/// method to display the data to & from the port
/// on the screen
/// </summary>
/// <param name="type">MessageType of the message</param>
/// <param name="msg">Message to display</param>
[STAThread]
private void DisplayData(MessageType type, string msg)
{
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
_displayWindow.Invoke(new EventHandler(delegate
{
_displayWindow.SelectedText = string.Empty;
_displayWindow.SelectionFont = new Font(_displayWindow.Selec
_displayWindow.SelectionColor = MessageColor[(int)type];
_displayWindow.AppendText(msg);
_displayWindow.ScrollToCaret();
}));
}
#endregion
NOTE: You will notice that we hyave added the STAThread Attribute to our method.
This is used when a single thread apartment is required by a control, like the
RichTextBox.
The next method we will look at it used when we need to open the port initially. Here
we set the BaudRate, Parity, StopBits, DataBits and PortName Properties of the
SerialPort Class:
CODE
#region OpenPort
public bool OpenPort()
{
try
{
//first check if the port is already open
//if its open then close it
if (comPort.IsOpen == true) comPort.Close();
//set the properties of our SerialPort Object
comPort.BaudRate = int.Parse(_baudRate);
//BaudRate
comPort.DataBits = int.Parse(_dataBits);
//DataBits
comPort.StopBits = (StopBits)Enum.Parse(typeof(StopBit
comPort.Parity = (Parity)Enum.Parse(typeof(Parity),_p
comPort.PortName = _portName;
//PortName
//now open the port
O
()
Next lets take a look at our event handler. This event will be executed whenever
there's data waiting in the buffer. This method looks identical to our WriteData
method, because it has to do the same exact work:
CODE
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
#region comPort_DataReceived
/// <summary>
/// method that will be called when theres data waiting in the
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void comPort_DataReceived(object sender, SerialDataReceivedEve
{
//determine the mode the user selected (binary/string)
switch (CurrentTransmissionType)
{
//user chose string
case TransmissionType.Text:
//read data waiting in the buffer
string msg = comPort.ReadExisting();
//display the data to the user
DisplayData(MessageType.Incoming, msg + "\n");
break;
//user chose binary
We have 3 small methods left, and these are actually optional, for the lack of a better
word. These methods are used to populate my ComboBox's on my UI with the port
names available on the computer, Parity values and Stop Bit values. The Parity and
Stop Bits are available in enumerations included with the .Net Framework 2.0:
Parity Enumeration
StopBits Enumeration
CODE
#region SetParityValues
public void SetParityValues(object obj)
{
foreach (string str in Enum.GetNames(typeof(Parity)))
{
((ComboBox)obj).Items.Add(str);
}
}
#endregion
#region SetStopBitValues
public void SetStopBitValues(object obj)
{
foreach (string str in Enum.GetNames(typeof(StopBits)))
{
((ComboBox)obj).Items.Add(str);
}
}
#endregion
#region SetPortNameValues
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
That is how you do Serial Port Communication in C#. Microsoft finally gave us intrinsic
tools to perform this task, no more relying on legacy objects. I am providing this class
and a sample application to show how to implement what we just learned. What I am
providing is under the GNU General Public License meaning you can modify and
distribute how you see fit, but the license header must stay in tact. I hope you found
this tutorial useful and informative, thank you for reading.
Happy Coding
SerialPortCommunication.zip ( 101.85k )
Number of downloads: 39986
This post has been edited by PsychoCoder: 12 Nov, 2007 - 10:58 PM
Register to Make This Ad Go Away!
Louisda16th
20 Oct, 2007 - 09:57 PM
Post #2
Nice tutorial! Thanx
ecsv8agb
28 Dec, 2007 - 11:38 PM
QUOTE(Louisda16th @ 20 Oct, 2007 - 10:57 PM)
Nice tutorial! Thanx
This code can not be use ! no react of the application
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
Post #3
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
PsychoCoder
9 Feb, 2008 - 05:33 AM
Post #4
Well it does work, it was tested many many times before I posted it, and when I
wrote it I had no problems with it not receiving and sending data. In fact I still have
the application on my machine, I just loaded it up and it worked fine, and its the same
application I posted here.
Can you be a little more specific about the problem you're having?
erik006
23 Feb, 2008 - 01:09 PM
Post #5
I've been trying to use this code (as is - from zip file) to communication with an
embedded target. The target is connected with to the computer using a usb<->serial
adapter. I'm sending data from the target to the computer every second (ascii data).
However, even though opening the port seems to be successful, i never receive any
data.
I know my setup is functional since I can communicate with the target using Realterm,
and i'm receiving the data properly. What could the problem be?
Erik
th4k1dd
20 Mar, 2008 - 05:46 AM
Post #6
Hello, I was so excited to find this post and can't wait to play. I did run into one
problem I am having with the code. I went ahead and threw it into C# and compiled.
The program detects my one and only COM port, COM12 and adds it to the port drop
down box like it should.
However, when I hit the Open Port button, it throws up an error in the Rich Text Box
which says that COM1 does not exist. Of course that was not a mistype. I select
COM12 and yet it tries to connect to COM1.
I took a look at the code and followed the _portName variable but was unable to see
why it would cut off the 2 in 12. It would seem it should not as the variable is setup
as a string.
Quick Info:
Windows Vista Business
Microsoft .Net Visual Studio 2008 Express
Arduino USB Microcontroller Card
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
Port Settings (should be): COM12, 9600, None, 1, 8
Programs Receiving COM12: Arduino Software, Putty, & Realterm
Am I missing something? You help is greatly appreciated.
One thing I noticed...I went into Device Manager and changed the USB Virtual COM
port to use COM1 and for some reason the program works fine. Also works great if
changed to COM2 in Device Manager.
Any ideas?
* Needs to read up on variable tracing *
kingmighty_spades
29 Mar, 2008 - 08:21 AM
Post #7
Nice tutorial! Thanx
This post has been edited by kingmighty_spades: 29 Mar, 2008 - 08:22 AM
PsychoCoder
29 Mar, 2008 - 12:18 PM
Post #8
No problem, thanks for the compliment
**silver**
29 Apr, 2008 - 01:05 AM
Post #9
Nice tutorial ,But i have a problem , when I hit the Open Port button, it throws up an
error in the Rich Text Box which says that "Access to the port COM1 is denied". Iam
using Windows XP and i use this Serialcommunicator program to communicate with
my mouse which i plug it to COM1 at the same time, can anybody help me ???
But when I take off the my Serial Mouse , Program work correctly. Waht can i do? I
have a project , taking serial mouse data and display them on the screen.
This post has been edited by **silver**: 29 Apr, 2008 - 01:57 AM
Pirmin
30 Apr, 2008 - 09:18 PM
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
Post #10
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
Hi
It's nice code indeed, but has at least one small fault which has made problems to
some people and also to me now.
The code will run correctly as long as you are working with COM1 (Default).
For working with any other Com-Port you need to amend the Method cmdOpen_Click,
adding (insert before comm.OpenPort()) the line
CODE
comm.PortName = cboPort.Text;
With this correction done, the desired port opens, but I'm still having problems
receiving data.
But I think my new problem could be particular to my device and therefore I'm
assuming, the code is fine now.
Regards
Pirmin
This post has been edited by Pirmin: 30 Apr, 2008 - 09:44 PM
talk2vachan
7 May, 2008 - 11:33 PM
Post #11
Hello All,
I am having configuration Windows XP. I had default 2 COM port are working. I had
configured Null Modem and activate 2 new ports COM3 and COM4.
Now. i am opening two instance of our application and try to open individual ports
COM3 and COM4 with same configuration settings.
But when I send any text information it will shows this text into same text area part.
But it will not send whole text to another PORT. Only first character is shown. Other
are junk characters.
I do not know how it works .. Can any one give me workaround for this.
Thanking you in Advance.
ABNcoder
22 Jul, 2008 - 07:22 AM
Post #12
This is great code. I've studied it thoroughly and have a learned a lot from it. I'm
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
using it to interface with portable devices. Is there a way to speed up the
displaydata(). If I'm downloading 5,000 lines, I notice a 30 second difference in the
time the device loads, and when the display catches up. Thanks in advance!
Christianne
4 Nov, 2008 - 01:19 AM
Post #13
Has anyone noticed in Task Manager that this app eats up alot of CPU memory and
keeps expanding? I think its related to the string.Replace() which is eating up the
memory.
Does anyone else notice this????
moallen
21 Dec, 2008 - 09:32 AM
Post #14
Thanks for a great little program. Besides trying to learn everything I can about it,
I've been using it to control an Insteon PowerLinc Modem. This is a programable
device that can send X10 codes through the power lines. This program works great
with the PLM by sending house/unit codes in hex, turning remote X10 modules on &
off, etc. I especially like the way the PLM acknowledgement comes back and shows in
the program's receive data window.
I do have a couple questions perhaps someone can answer. The PLM requires the
baud rate set to 19200, but that isn't a choice in the drop down list of baud rates. I
do have my computer's COM1 port set to 19200. I did discover I could change this
line in the Main Form to cboBaud.SelectedText = "19200"; to set the proper baud rate
for my PLM. But I still didn't find anyplace in the program to make 19200 an option.
Is this a value that should have been reported back with string str in
SerialPort.GetPortNames() ?
One other issue - I get a warning in my Visual C# 2008 Express Edition that I have an
"unreachable Code Detected" in the CommunicationManager line 213 col 21. That's
with or without changing the default baud rate to 19200. Any ideas what that's about?
It doesn't seem to affect the program's operation.
TenRC
14 Jan, 2009 - 12:34 PM
Post #15
The downloaded file is corrupt or incomplete. Please test and verify. I have uploaded
what I received.
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
This post has been edited by TenRC : 14 Jan, 2009 - 12:38 PM
Attached File(s)
SerialPortCommunication.zip ( 93.92k ) Number of downloads: 408
jay543_uk
19 Jan, 2009 - 01:31 PM
Post #16
QUOTE(TenRC @ 14 Jan, 2009 - 12:34 PM)
The downloaded file is corrupt or incomplete. Please test and verify. I have uploaded what I received.
hi all, im just starting out with visual studio 2008 c# and want to learn about serial
com, i need to download this files too to learn about it but its not working for me, can
someone test the file is ok as it could just be me or its corrupt
thanks for anyones help
jason
kovacp1
10 Feb, 2009 - 01:53 PM
Post #17
The zip file is corrupt.
Your code sounds great, so could you please e-mail me the code?
if you zip it, will you please encode and password protect it with a password of 'zip' as
our silly system requires zip files to be encoded
THANK YOU IN ADVANCE !!!!
RandyPerson
3 Mar, 2009 - 02:37 PM
Post #18
Code looks great. The download file appears to be corrupt. Can you email a zipped
copy of it? Thank You
jano_rajmond
23 Mar, 2009 - 10:51 AM
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
Post #19
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
Hy!
I have uploaded the zip file to http://uploaded.to/?id=zr771n for those who could not
download it. I have also attached it to this reply.
Also, I have a question. I have compiled the code under VS 2008 and it works. But
there is one problem: upon reception in inserts a couple or more new lines in the
message.
It's not the reception itself that is the problem, as if you test it with another terminal
app it works fine.
I this that the reception thread may be interrupted by something. I modified the code
in order to use separate windows for Tx and Rx and also took down the RichtextBoxes
and replaced the with Normal TextBoxes, but the same thing happens..
Any ideea?
Attached File(s)
SerialPortCommunication.zip ( 101.85k ) Number of downloads: 562
lufc2684
27 Mar, 2009 - 06:11 AM
Post #20
Hi
The zip file seems to be corrupt, any ideas?
Thanks
Enter Keywords
2 Pages
1
Search Topic
2
« Next Oldest · C# Tutorials · Next Newest »
>
7 User(s) are reading this topic (7 Guests and 0 Anonymous Users)
0 Members:
|-C#Tutorials
Tutorials
|-- C#
Go
???????? ????
Serial Port Source Code
Simplify .NET serial port communications in VB,
C#, C++
www.scientificcomponent.com
Send Mail from ASP / .NET
AspEmail supports Unicode, HTML, encryption,
message queuing, etc.
www.aspemail.com
PDF SDK-COM C++ .NET Java
Quick & easy way to support PDF. Append,
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬
C# Tutorials - Serial Port Communication In C# | DreamInCode.net
encrypt, sign, email +more
www.pdfmachine.com/pdfservmachine/
Lo-Fi Version
Time is now: 10/15/09 09:08AM
Invision Power Board v2.1.7 © 2009 IPS, Inc.
Licensed to: MediaGroup1
Advertising
| Terms of Use | Privacy Policy | About Us | Site Map
Forum Index: Programming Help | C and C++ | VB6 | Java | VB.NET | C# | ASP.NET |
PHP | ColdFusion | Perl and Python | Ruby | Databases | Other Languages | Game
Programming | Mobile Development | Software Development | Computer Science |
Industry News | Programming Tutorials | C++ Tutorials | Visual Basic Tutorials | Java
Tutorials | VB.NET Tutorials | C# Tutorials | Linux Tutorials | PHP Tutorials | ColdFusion
Tutorials | Windows Tutorials | HTML/JavaScript Tutorials | CSS Tutorials | Flash
Tutorials | Web Promotion Tutorials | Graphic Design & Photoshop Tutorials | Software
Development Tutorials | Database Tutorials | Other Language Tutorials | ASP.NET Tutorials | Game Programming
Tutorials | WPF & Silverlight Tutorials |
Copyright 2001-2008 MediaGroup1 LLC, All Rights Reserved
A MediaGroup1 LLC Production - Version 6.0.2.1.36
Server: secure2
http://www.dreamincode.net/forums/showtopic35775.htm[2009/10/15 08:46:01 ‫ﺏ‬.‫]ﻅ‬