Comments

# coad said on April 14, 2004 6:10 AM:

Hi Noah,

Nice to see you bloging :)

# coad said on April 14, 2004 6:46 PM:

Great point. I think a log of people have forgotten that this capability exists in IE 5+. It's great for a quick display of data if you know the use will be using IE. I've used this even to dynamically add rows to the grid (without a postback) - with javascript. Great post.

# coad said on April 15, 2004 12:09 AM:

You're the first person I've heard of that actually used the basic HTML data binding in production. I'm glad to hear it worked so well. Thanks for the feedback Jeff.

Any other feedback on specific ways this has been useful would be appreciated from readers.

# TrackBack said on April 15, 2004 12:28 AM:

# TrackBack said on April 15, 2004 12:30 AM:

# TrackBack said on April 15, 2004 12:31 AM:

# coad said on April 15, 2004 5:32 AM:

I agree that the error message should be clearer, but may I ask why you are generating a feed that is over 400K? You realize that feeds are made to be downloaded over and over again, right? What could you possibly be syndicating that is worth downloading a 400K feed over and over again for a few changes?

FWIW, the average feed size is about 10-15K.

# coad said on April 15, 2004 10:40 AM:

Mark, your FEED Validator tool is a very useful program, thank you for making this available to the online community.

After several hours of trying to fix the RSS XML (due to Microsoft Word's copy/paste problem), it was frustrating to find out that the tool was reaching a limit without notification. I'm new to blogging and am trying to learn some best practices and have been very actively working on balancing all these elements.

Microsoft Word is embedding tons of seemingly unnecessary tags that are bloating the feed. I'm working on trying to find or create tools to clean this up. It is a process. I would very much like to get it down to around the average of 10-15K and agree that 400K is ridiculous for just a few posts.

# TrackBack said on April 15, 2004 11:16 AM:

# coad said on April 15, 2004 8:43 PM:

Great XML posts! I have used the IE xml data binding in an actual solution
for a client. It allowed several records to be added before posting back
the end result to the server. And this was with ASP 3.0. Pretty cool
feature. I think I have been a little intimidated with XSL, although I have
used it to convert xml to a different form (from attributes to elements). I
didn't know how much you were into XML!

# TrackBack said on April 16, 2004 7:06 PM:

Great XML DataBinding post

# coad said on April 18, 2004 5:23 AM:

Wow, great mug shot. You did a great job of stripping off that background and making it transparent!

# coad said on May 16, 2004 11:34 AM:

You might want to check out the free CodeHighlighter control. It even supports outlining! Here is a link:

http://www.codehighlighter.com/

# coad said on May 16, 2004 2:05 PM:

Thanks for the quick reply! Wow, someone out there actualy reads my posts. I'll be more careful when posting temp blog entries when testing my custom MetaBlogAPI interface between w:bloggar and the site.

Actipro Software makes great products! I've used their docking windows and wizard controls for about two years now. I wasn't aware of the highlighting control. I will definately check it out.

Thanks again!

# coad said on May 19, 2004 11:42 PM:

hi, Noah:

Search-engined my way to your blog entries on xml and databinding - those vocabulary files.

I must profess total aloofness (=ignorance) when it comes to seeing how your files work. I am a know-only-how-to-change-the-tire-and-sparkplugs kind of guy, so i am not sure how to activate the page, and get it to read the data.

I am wanting to build vocabulary lists for different languages, and i want it to be as simplified as possible (thus the use of .txt files or .xml files for the data) so that people everywhere can contribute to and build up the lists quickly.

I have had some success using .txt files and HTML databinding, but now i want to associate a sound file for each word and its sample sentences as part of the word database, and then have a kind of flash mx embed arrow button to quickly hear the word or the sentence. but the code for the flash sound file is rather extensive for each word
-----
<p align="right"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#3,0,0,0" width="20" height="20"> <param name="SRC" value="swf/thisisthesoundfile.swf"> <embed src="swf/thisisthesoundfile.swf" pluginspage="http://www.macromedia.com/shockwave/download/" type="application/x-shockwave-flash" width="20" height="20"> </embed> </object></p>

----

and if i want to do those for 1000s of words, it would be a very long piece of code.

If I juse use a href, it kicks in with my default audio player, which is not too bad, but i want to keep the student visitor focussed only on the one screen with all controls on it....

I probably haven't explained it very clearly, but you can see a bit of an example at
http://twohandsapproach.org/webside2/vocab/enmp108.htm

Any suggestions you can give would be greatly appreciated.

Steve Watson
English Instructor
Guangzhou Institute of Technology
Guangzhou, China

co-author The Two Hands Approach to the English Language

# coad said on May 24, 2004 7:28 PM:

Hi Noah,

Can you please do me a favor and help get the word out on your BLOG that we are making VistaDB 2.0 available to all TechEd 2004 attendees for only $99. They can just click here:
https://secure.vistadb.net/shop/shop.asp?promo=TECHED2004

Offer is good this week only.

Thanks!
Anthony Carrabino
www.vistadb.net.

# coad said on May 25, 2004 5:39 PM:

Congratulations on your graduation!!! Have you started at MS yet? I'm back at work. I made a new release of EZWeb at workspaces.gotdotnet.com/ezweb.

Let me know if you attend any really cool sessions, and I'll see if I can view the webcast. They've made the content really accessible for us who couldn't go.

# coad said on May 27, 2004 1:08 PM:

The validator tool has been fixed! It will now tell you if the feed is over its limit. Thanks Mark.

# coad said on May 27, 2004 1:54 PM:

Wowza, there is a trio I am afraid of!

# TrackBack said on May 27, 2004 3:45 PM:

# coad said on May 27, 2004 9:32 PM:

A hand full of shiny pens! Geesh!

# TrackBack said on June 5, 2004 4:21 AM:

# TrackBack said on June 7, 2004 9:09 PM:

# TrackBack said on June 7, 2004 9:09 PM:

# coad said on June 10, 2004 4:13 PM:

Do share!! Man, you are awesome!! Will you post this project on GotDotNet?

# TrackBack said on June 10, 2004 4:26 PM:

The next one-touch blog tool for .Text, NovaBlog - level 100

# coad said on June 13, 2004 9:35 AM:

Right. But this way you will also loose your posts history.
I think, with the "delete individual posts per feed" feature planned for the next major release of Bandit it should be much easier to handle such tasks.

# coad said on June 14, 2004 10:40 PM:

Hi Noah, You recently posted a comment on my blog about my "1000101 Dude!" shirt idea. I just realized we actually met at Tech-Ed. You sat with us to eat dinner. I was with Adam Kinney and Eric Porter.

# coad said on June 14, 2004 10:43 PM:

It's more difficult if you try to grab the TIF association, though. After some digging I had to change the Explorer FileExts key, but I'm still not sure I did it right.

# coad said on June 15, 2004 11:37 AM:

That is a great T-shirt by the way. http://haacked.com/archive/2004/06/09/565.aspx

I've been trying to find a pic so I can remember you as well. That is really cool though, what a small world. :)

Never know who you're going to meet where. Well after that t-shirt, I'm subscribed to your blog. :)

# coad said on June 15, 2004 3:00 PM:

You're too kind, Noah, thanks! It was great seeing you at TechEd :)

# coad said on June 16, 2004 10:21 AM:

Thanks Noah. Top of the list. Wow. Not sure I deserve that.

# TrackBack said on June 17, 2004 11:39 PM:

# TrackBack said on June 17, 2004 11:39 PM:

# TrackBack said on June 18, 2004 1:03 AM:

# TrackBack said on June 18, 2004 1:06 AM:

# TrackBack said on June 18, 2004 1:09 AM:

# TrackBack said on June 18, 2004 1:18 AM:

# coad said on June 18, 2004 1:20 AM:

jaybez [MS] talks about trying to reduce the amount of code to implement this pattern.
Properties as objects: http://weblogs.asp.net/jaybaz_ms/archive/2004/06/14/155452.aspx
Properties with events: another attempt: http://blogs.msdn.com/jaybaz_ms/archive/2004/06/16/157682.aspx

# coad said on June 18, 2004 9:29 AM:

I like the concept, but don't you think you should implement an event accessor instead of having a public event? It would offer a level of abstraction for doing something when an event is subscribed/unsubscribed. e.g.

private EventHandler m_devicePortChanged;
public event EventHandler DevicePortChanged
{
add{ m_devicePortChanged += value;}
remove{ devicePortChanged -= value;}
}

# coad said on June 18, 2004 10:56 AM:

Jeffrey: If you write an event with the field syntax, the compiler merely generates 'add' and 'remove' for you. There's a good reason to let it: your implementation has a bug. You didn't lock. Let the compiler do it for you, and you don't have to worry about it.

http://www.jaggersoft.com/csharp_standard/17.7.1.htm

# coad said on June 21, 2004 11:42 PM:

There have been over 400 downloads in the first four days and no one has left a comment yet. Come on dudes, share the experience!

# coad said on June 22, 2004 12:58 AM:

What an excellent article! In my humble and unbiased opinion, NovaBlog is one of the greatest creations I have seen (as it applies directly to many significant others out there). It relieves frustrations, and provides more opportunities for that ever so important quality time in greater quantities!
This program receives the girlfriend seal of approval. Five stars! *****

# TrackBack said on June 22, 2004 2:29 AM:

The tool has been mentioned on asp.net.

# TrackBack said on June 22, 2004 9:38 AM:

# TrackBack said on June 23, 2004 7:01 AM:

# coad said on June 23, 2004 7:38 AM:

I tried it yesterday with no problems. I forgot that you added a bunch of "usings" and I was surprised that the IDE didn't complain about my cut and pasted regex code. ReSharper doesn't like all of the unused "usings", though. It also took me a few mintues to figure out why I wasn't getting any console output - RTFM...

# TrackBack said on June 23, 2004 7:17 PM:

# coad said on June 24, 2004 9:25 AM:

I tried this for an application that has 5 (slow loading) frames. It appears that the frames are still serviced serially and not in parallel.

Does anyone know if anything needs to be changed in IE preferences to ensure that it will pick up the new connection limit?

Thanking you for any help,

Gavin

# coad said on June 25, 2004 2:46 PM:

A benefit would be to log the action of subscribing or unsubscribing to the event.

# coad said on June 29, 2004 1:17 PM:

When I run the installer it says "Visual Studio .NET 2003 is required".

From within MSStudio->Help->About it says "MS Developement Environment 2003" and "MS .NET Framework 1.1".

Any ideas?

# coad said on July 1, 2004 1:43 AM:

The installer requires that VS be installed in its default location (on drive C). This is due to a limitation of constraints in the VS setup creator. If someone would like to hook me up with InstallShield, I would gladly create a more dynamic setup procedure.

# TrackBack said on July 6, 2004 1:11 PM:

# TrackBack said on July 6, 2004 5:16 PM:

# TrackBack said on July 7, 2004 6:50 AM:

Noah Coad has LOST his C# MVP status!!!! - level 000

# coad said on July 21, 2004 5:17 AM:

Man Finally I found this. Thank you so much!

# coad said on July 25, 2004 11:40 PM:

Noah,

Congrats! I trust that you will be happy with this move. I hope to still you in the MVP newsgroups. Good luck to you and your girl.

Isaiah

# coad said on July 31, 2004 5:52 PM:

Wow great pictures! Hi, Dawn!

Even though you have been assimilated into the collective, I know that you will maintain the individuality you learned at A&M... oh wait... A&M is worse of a collective than Microsoft...

good luck, $employee_id$ of $num_employees%!

# coad said on August 2, 2004 5:34 AM:

Hey Noah, I'm the C# team, not the VS IDE. But thanks still :-)

# coad said on August 2, 2004 5:35 AM:

Cryus: Dang it, sorry dude, I'll fix that just as soon as I get my equipement back up and running from the move to MSFT.

# coad said on September 12, 2004 12:03 AM:

That's amusing.

# coad said on October 10, 2004 1:03 PM:

I am the luckiest woman in the world to be engaged to such a talented, loving, inteligent, and caring individual such as my Noah. When he asked me to marry him, I did not have to hesitate even one moment! I knew that we were made to be together. We compliment each others lives so perfectly, it could not be any other way. Noah is my loving counterpoint and partner to be in life. I love you sweetheart!

Your fiance - Dawn Melody

# coad said on October 10, 2004 2:36 PM:

Welcome back, Noah.

# coad said on October 10, 2004 2:37 PM:

Hey, congratulations!
Yes, you do look great together :-)

# coad said on October 10, 2004 4:12 PM:

Holy CRap!

I though you certainly were a gonner! No news for a while, nice to hear from you again.

# coad said on October 10, 2004 4:15 PM:

Swonderful,

(We need to have another JCody's run tho)

# coad said on October 10, 2004 11:34 PM:

Welcome back. My feed reader has been patiently poling your site every day during your absence.

Speaking of which... Microsoft is planning on including site syndication subscription (RSS, RDF, etc) in it's next version of Outlook & Outlook Express, right? I mean, right?

# coad said on October 11, 2004 12:07 PM:

Congrats, Noah!

# coad said on October 12, 2004 2:01 PM:

What a hottie!!! The girl is cute too.

# coad said on October 30, 2004 1:20 AM:

What a beautiful couple, inside and out! I am looking forward to having such a wonderful daughter-in-law. We are so blessed that you have found each other. Welcome to the family, Dawn!

# coad said on October 30, 2004 4:58 PM:

Hi Friend!

# coad said on October 30, 2004 9:47 PM:

A big "Howdy!" from Texas.

# coad said on November 1, 2004 8:59 AM:

Dawn wish you luck.
Hope all goes Good.
Noah looks 20? Well Dawn I know you well hope all goes veary well for you.

# coad said on November 1, 2004 3:44 PM:

Hi Noah! Been back to Sushi Land in Bellevue recently? :)

# coad said on November 5, 2004 11:41 AM:

Howdy.

# TrackBack said on November 8, 2004 11:11 AM:

# coad said on November 15, 2004 2:23 PM:

Worked like a champ for me. Thanks.

# coad said on December 5, 2004 8:52 PM:

Those are great pics. Congratulations!

# coad said on December 12, 2004 4:16 AM:

it works!
been wanting this for years
thanks

# coad said on December 14, 2004 7:43 AM:

Already on my calendar. Will you be on the chat?

# coad said on December 14, 2004 11:43 AM:

Yes, I'll definately be there, seeing that I'm orginizing the event. :)

# coad said on December 29, 2004 2:19 AM:

Is this feature available in other browsers like Opera or Mozilla? I made a quick search on their forums but found nothing.

# coad said on December 29, 2004 11:04 AM:

Don't know, but you can try it out and post back here whether it does or not. :)

# coad said on January 10, 2005 3:57 AM:

it's very helpful to me thank you :)

# TrackBack said on January 10, 2005 2:00 PM:

# TrackBack said on January 10, 2005 2:03 PM:

# coad said on January 10, 2005 6:24 PM:

Thank you for the invitation. I'm looking forward to the pres. It's not mentioned, but will any of the source control be covered?

# coad said on January 10, 2005 6:28 PM:

No, source control is part of Team Foundation, not Dev/Test. But Team Foundation is having chats later this month on Jan 26 & Jan 27. See http://msdn.microsoft.com/chats

# TrackBack said on January 10, 2005 7:21 PM:

# TrackBack said on January 11, 2005 12:06 AM:

# coad said on January 14, 2005 5:16 PM:

i am just starting.. i put this code into a .cs file and it did not work.
hmm

# coad said on January 14, 2005 9:57 PM:

That code is the heart of what is required. It takes putting it in the right place to "get it to work". Here is the code that will execute that above verbatim. You can put this in a .cs file, compile that file, and execute it from the command prompt to see the results.

Unforunately, when I post this, the blog removes the indentation. Please know that they are in here for good form. :)

The TraceToConsole class is added to the end to pass the Trace output from the example code above staight to the console. This way, if you had a GUI trace listening attached (like Visual Studio), you'll see the output there too (in VS' Output window). You can change the last line above from "Trace." to "Console." to send the output to the console directly.

=========================================

using System;
using System.Xml;
using System.Net;
using System.Text;
using System.Diagnostics;

namespace RullRSSFeed4Blog
{
class QuickTest
{
[STAThread]
public static void Main(string[] args)
{
Trace.Listeners.Add(new TraceToConsole());
Trace.Write("\n");
ExampleCode();
}

private static void ExampleCode()
{
// RSS XML Feed URL
string url = "http://msmvps.com/coad/rss.aspx";

// Create an interface to the web
WebClient c = new WebClient();

// Download the XML into a string
string xml = ASCIIEncoding.Default.GetString(c.DownloadData(url));

// Document to contain the feed
XmlDocument doc = new XmlDocument();

// Parse the xml
doc.LoadXml(xml);

// Display each article title
foreach (XmlNode node in doc.SelectNodes("/rss/channel/item/title"))
Trace.WriteLine(node.InnerText);
}
}

class TraceToConsole : TraceListener
{
public override void Write(string s)
{ Console.Write(s); }

public override void WriteLine(string s)
{ Console.WriteLine(s); }
}
}

# coad said on January 15, 2005 2:19 AM:

Thanks SOO much.

--mark

# coad said on January 22, 2005 3:33 PM:

I noticed on another web site (http://www.winguides.com/registry/display.php/733/) that they were adding a max connection setting at the following registry key:

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP]

How is this different from the settings you have suggested. What would happen if I added both?

# coad said on January 24, 2005 9:04 PM:

Good question! I don't know. But if you tried one method, then the other, then both, and reported your findings, it would be appreciated! :)

# coad said on February 3, 2005 7:29 AM:

Just wanna say THANX... ;-)

# coad said on February 15, 2005 11:27 AM:

Thx for the tip. I initially thought this was a hoax but I guess it actually works. Seems like there are discussions about some hard-coded limit coded into IIS, which is why you can't go over 40 connections.

# coad said on February 17, 2005 7:05 AM:

Hi Noah,

Cool idea.and it is a pitty that there are no such cradles...

# coad said on February 17, 2005 10:16 AM:

Hey! We were talk with you some time ago about where you can find useful stuff, remember it?
I forgot tell you about one cool site!
Look it: http://www.profigroup.com, here you can find anything: cheap pharmacy - tramadol, phentermine, fioricet, hydrocodone, viagra and many more!

You can find too finance stuff like loan, insurance, mortgage, credit cards and personal finance!

Write me back, I can't wait you.

Best regard, Mike

# coad said on February 19, 2005 10:25 PM:

Wow. thanks for all the comments.

# coad said on February 23, 2005 12:39 AM:

Hi Noah,
This is GREAT! It took me 32 years to get my first but you just got a jump-start! I am so glad we are able to share your first.
Congratulations! Keep it up!

# coad said on February 24, 2005 1:31 AM:

Congrats Noah!

# coad said on February 25, 2005 12:53 AM:

got here looking for 'rss feed validator' because feedvalidator.org seems to down temporarily.

how would any tags inserted by msword be acceptable other than those permitted by the specs/convention?

anyhooooo, very picky this rss thing. imagine not being able to validate because the xml tag is not the very first line even though it is the very first non blank line. a robust parser, not the validator, should be able to skip forward over whitespace until it encounters the first required line.

how do i know this? asp puts in a crlf for every break in the enclosing code tags. i won't type them here because i want to avoid causing any problems, but you know i mean the percent sign and angle bracket thing. so you have to run them together on the same line, and that's just butt ugly code formatting.

# coad said on February 26, 2005 5:02 PM:

Sharp has released the next model, the MM-20, with 512 MB RAM, a 20 GB hard drive, built in 802.11g, and an updated Transmeta processor.

http://www.sharpsystems.com/products/pc_notebooks/actius/mm/20/

# coad said on March 4, 2005 4:39 AM:

It saved a lot of person hour for us
Thank you very much

# coad said on March 7, 2005 12:15 AM:

There is a bubble tea place in the Crossroads Mall in Bellevue called Boba Express. They also serve bubble tea at the Pho Hoa Noodle place on NE 24th Street in Redmond.

# coad said on March 17, 2005 2:54 PM:

Yo tambien quiero decir GRACIAS!!!!!

# coad said on March 27, 2005 5:28 PM:

Nice!
And for devs searching for rs232 for the Compact Framework feel free to come here:
http://www.danielmoth.com/Blog/2004/09/serial-rs232-communications-in-net.html

# coad said on March 29, 2005 2:13 AM:

Shouldn't there be a lock in OnDevicePortChanged?

# coad said on March 31, 2005 11:31 AM:

i like bubble tea I live in Victoria

# coad said on April 5, 2005 3:03 AM:

Love to see this one, never seen the remix before!

# coad said on April 6, 2005 2:16 PM:

What pure sweetness you two are together! You both look ever so handsome. Noah, my dearest brother, I am so happy for you and thank you for picking out such a great gal to be my sister. I love you both! Congratulations!!!

# coad said on April 6, 2005 5:35 PM:

And at Saigon City in Redmond not to far from the Cross Roads Mall too.

# coad said on April 11, 2005 3:36 AM:

Love the http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/colors/colors.asp and the http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsgrpregexpsyntax.asp

# TrackBack said on April 15, 2005 12:25 PM:

^_^,Pretty Good!

# TrackBack said on April 15, 2005 12:26 PM:

^_^,Pretty Good!

# TrackBack said on April 16, 2005 7:21 PM:

# coad said on April 21, 2005 10:29 PM:

At the NC Dept. of Public Instruction, we use client-side databinding (IE only) to dynamically display from one to thousands of records, perform client-side sorting (using XSL), etc. This is within an HR management system used by all the public schools in NC. Our users are very pleased with the speed and flexibility of this approach.

When the user requests data or changes search conditions, the src of the data island is dynamically built. When the data is returned, record counts are displayed. The data sits in DB2, and a single Domino agent performs a query, based on the query id and lookup values presented in the URL. The recordset is wrapped in XML tags and returned to the browser by the agent. We currently have over 150 queries that are dynamically modified and submitted by the single agent.

For example, the agent can be called as follows:

../../getGeneric.xml?openagent&queryid=ApplicantsByPositionChoice&1=ELEMENTARY&2=01-01-2005

When the getGeneric.xml agent is called, it finds the ApplicantsByPositionChoice query, which might look like this...

select * from apps.applications
where position_choice = '$$1$'
and create_date >= '$$2$'

(The actual query will be more complex and the date format in the query above is probably wrong.)

The agent, after retriving the query, substitutes all the numbered values in the query ($$1$, $$2$, etc.) with the values found in the url (ELEMENTARY, 01-01-2005).

When the data is returned, the field names and values are read from the recordset and made into xml tags. In this way, a single agent (or servlet) can be used to perform nearly all the data service to the browser.

We use a similar solution for web reports, with XML/XSL, though the solution is more complex because it allows nesting of query data to produce a more complex XML document. As far as data binding is concerned, a "flat" XML file is all that's needed.

# TrackBack said on April 24, 2005 2:40 AM:

# TrackBack said on April 24, 2005 2:40 AM:

# coad said on April 24, 2005 10:29 PM:

Cool stuff.

# coad said on April 26, 2005 9:36 AM:

Good luck!

# coad said on April 30, 2005 11:25 AM:

Good luck from a fellow Ag and .NET geek!

# coad said on May 2, 2005 8:30 PM:

Congratulations! (from an Aggie who heard you speak at our .Net User's group meeting in College Station.

Guy

# coad said on May 3, 2005 2:22 AM:

Good luck and hope you got a butifull night ;)

# coad said on May 4, 2005 1:30 AM:

hey

i cant find the name space
using System.IO.Ports
there is nothing like Ports.
i'm using Visual Studio.net 2003
Please help me urgently
my email ID is arun5_appu@yahoo.com

# coad said on May 5, 2005 8:54 AM:

>I cant find the name space

Check this phrase near the start of this posting:

"the new SerialPort control that is part of .NET 2.0 (currently in Beta)"

# coad said on May 6, 2005 10:35 AM:

"... Working here at Microsoft, I'm amazed at how much the console is used..."

So one would assume that someone from Microsoft would actually write a USEFUL command prompt. I always assumed that you were a bit sadistic, and that you do this deliberately. Now why o why can't we do even simple things with this essential tool? Imagine Resizing the window without stipulating that it needs to be 123 char wide. Magic, isn't it?
So now I wonder if you are not a bit masochistic as well…

# coad said on May 7, 2005 3:17 PM:

Congrats! Hope you had a wonderful wedding. :)

# coad said on May 9, 2005 1:14 PM:

Sorry I'm a little behind, but I just wanted to say congrats and I hope it went really well! Take care! :)

# coad said on May 14, 2005 6:17 PM:

Congratulations Noah!

# TrackBack said on May 18, 2005 5:20 AM:

^_~,pretty good!csharpsseeoo

# TrackBack said on May 18, 2005 5:20 AM:

^_~,pretty good!csharpsseeoo

# TrackBack said on May 18, 2005 5:21 AM:

^_~,pretty good!csharpsseeoo

# TrackBack said on May 18, 2005 5:22 AM:

^_~,pretty good!csharpsseeoo

# TrackBack said on May 18, 2005 5:22 AM:

^_~,pretty good!csharpsseeoo

# TrackBack said on May 25, 2005 11:49 AM:

# coad said on May 29, 2005 5:40 PM:

Cool, I appreciate the simplicity of this very much : )

My Visual Studio 2003 claims that this method is obsolete:

xsl.Transform(xmlFileName, outputFileName);

...Any ideas how to comply with the suggested change?

# coad said on June 6, 2005 12:45 AM:

Hi,

I really thank you for being the only mangaed .Net source of seial comm.:)
I have .Net 2.0 Beta installed. And can compile your hello world! example. But when it tries to Open the port. Exception says there is no COM1 port.

Any Comments !

# coad said on June 6, 2005 12:57 AM:

You may not have a COM1 installed on your system, or it may already be in use.

# coad said on June 6, 2005 12:12 PM:

Mrs. Heussner Congratulations!!! or should I say Mrs. (insert last name) (sorry i dont know your new last name).Crystal and I miss you alot!!! Hope you have an awesome time with your husband!!!!
Please come back to visit someday!! we all want you to!
love, Cassy!! the only viola!!!!
Kookhead390@yahoo.com

# coad said on June 6, 2005 12:14 PM:

MRS.(insert last name) we miss you so much down here. Im glad that you found someone to love you as much as Noah does. Well i hope you enjoy your new life with Noah. We miss you tons.
love-
Crystal Gutierrez

p.s. if u can please email me at: monkiesrock1990@yahoo.com

# coad said on June 8, 2005 5:16 AM:

I'd really love to have these drugs *laughs*

# coad said on June 8, 2005 3:07 PM:

Nice Article..quite informative

# coad said on June 8, 2005 3:13 PM:

if I set the port.ReceivedBytesThreshold to 5 would the following event
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
be called after there is 5 bytes in the buffer...

Also can you show how to use port.Read(buff,0,5) where buff is defined as

byte buff = new byte[5];

I am calling the port.Read function after the event is called 5 times to make sure there are 5 bytes in the buffer but still it doesn't work.

# coad said on June 8, 2005 11:09 PM:

The method's parameters are port.Read(byte[], int, int), so the first parameter is a byte array (byte[]). Try: byte[] buf = new byte[5];

But I don't recommend reading a fixed # of bytes if possible since it is very easy to get one or two bytes off in the incoming buffer and hence not receive the data when expected or get unexpected results.

This is much preferred since it handles any amount of incoming data. Just process what ends up in the PortBuffer and remember to clean it out from time to time to prevent memory creep.

private List<byte> PortBuffer = new List<byte>();

private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port = (SerialPort)sender;

byte[] data = new byte[port.BytesToRead];

port.Read(data, 0, data.Length);

PortBuffer.AddRange(data);

ProcessIncomingData(PortBuffer);
}

private void ProcessIncomingData(List<byte> PortBuffer)
{
// Search through the bytes to find the data you want
// then remove the data from the list. It is good to
// clean up unused bytes (usually everything before
// what you're looking for)
}

# coad said on June 9, 2005 9:55 AM:

Thanks for your help man....

One question.... I have data coming through bus in sets of 5 bytes at a time at very high speeds...about 1.5ms delay. Is there anyway I can force the program to call SerialDataReceivedEventHandler after it gets 5 bytes of data.... by setting port.ReceivedBytesThreshold to 5 do it????

# coad said on June 9, 2005 1:51 PM:

I'd suppose so, have you tried it? I use the technique above so I've never tried triggering the event on x # of bytes. The purpose of changing the ReceivedBytesThreshold is not to capture little 'packets' like that, but to reduce the # of times the method is called if large amounts of data are streaming in.

# coad said on June 10, 2005 4:53 AM:

i cant find the name space
"System.IO.Ports"
i'm using Visual Studio.net 2003
Please help me, its urgent
my email ID is kapildvyas@yahoo.co.in

# coad said on June 10, 2005 11:51 AM:

thanks Noah... I'll try it if doesn't work i'll try the othe way ...

Kapil system.io.ports comes with visual studio 2005 beta version.

# coad said on June 11, 2005 6:24 PM:

I guess any client applications will need to upgrade to .net2.0 ? I am skeptical about this as .net is still in .net.

Can any one share any experience about this.

Seshagiri

# TrackBack said on June 14, 2005 12:16 AM:

Define 'Axiom Postulate Theorem Corollary Hypothesis'ooeess

# TrackBack said on June 14, 2005 12:54 AM:

Ballmer Dancing Developers Conference Videoooeess

# TrackBack said on June 14, 2005 12:58 AM:

Ballmer Sells Windows v1.0 TV Video Adooeess

# TrackBack said on June 14, 2005 1:22 AM:

Congrats to Jeffrey Palermo, MCADooeess

# TrackBack said on June 14, 2005 1:47 AM:

US Patent Plaqueooeess

# TrackBack said on June 14, 2005 2:01 AM:

Bubble Teaooeess

# TrackBack said on June 14, 2005 2:07 AM:

Microsoft Coding Guidelinesooeess

# coad said on June 14, 2005 2:55 PM:

What I was thinking was would client applications need to install .net 2.0 if I used the new feature in my application. If it is so, in that case is it recommendable as .net 2.0 is still in beta stage and there could be compatibility issues with the final release.

Seshagiri

# coad said on June 14, 2005 5:50 PM:

Seshagiri: Yes, clients must be running .NET 2.0. The deployment version from Beta2 will be different than that for RTM. VS05 Beta2 is not for public release yet, that's for when the product is finalized and released to market the second week of November. In the mean time, it is for testing and deployment to select targets (w/ a Go Live licence, see MSDN).

# coad said on June 21, 2005 10:31 AM:

Hi Noah!

I'm trying to send a simple "ati4" command to a modem and receive its response, but all I get back is whatever ati command I send.

If I Send: ati4

I Expect To Get Back:
USRobotics Sportster 28800 V.34 Fax Settings...

B0 E1 F1 M1 Q0 V1 X4 Y0
BAUD=38400 PARITY=N WORDLEN=8
DIAL=PULSE ON HOOK, etc..

But Instead I Get Back: ati4

I've tried both my own test application as well as the one you created. Any ideas? Thanks so much!

# coad said on June 22, 2005 12:13 AM:

Nice post, bookmarked it :)

# coad said on June 22, 2005 9:34 AM:

Update
------
Hi Noah!

After further debugging, I observe that the port_DataReceived function in your SerialPort Terminal example is never being called. I see the function being added as an EventHandler earlier:

comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

I can't figure for the life of me why it's never reaching the function though. All I know is this is why, for example, I only receive an echo of my "at" command and not the actual "ok" response I'm expecting. I didnt change any of the code, so why would this be happening?

Cheers!

# coad said on June 25, 2005 11:56 AM:

Thanks for the resource list. :)

# coad said on July 7, 2005 11:30 PM:

This is a reply to 'Nathan Ie' question about the ATI4 question.

I had the same problem and found out, that if you use WriteLine() method to write the "ATI4" string it will echo the sting back.

You have to use the Write() method and specify the file feed "\r". If you call method Write("ATI4\r") you will get the expected result. You can also change the SerialPort.NewLine Property from "\r\n" to "\r" to make it work.

Hope that helped

# TrackBack said on July 8, 2005 10:42 AM:

Windows XP isn't known for its powerful command line interface. Still, one of the first things I do on any fresh Windows install is set up the "Open Command Window Here" right click menu. And hoary old cmd.exe does...

# coad said on July 8, 2005 5:23 PM:

when i do "port.Open()", it says

UnauthorizedAccessException was unhandled.
Access to the port "COM1" is denied.
Make sure you have sufficient privileges to access this resource

I just put your code segment into a button1_Click handler. What should I do to make it work?

# coad said on July 8, 2005 5:44 PM:

Actually nevermind my previous post, i solved the problem. But i have a new question :)

How can I manually send bit signals to RTS & DTR?

I need to send something like "0110000011010000" to RTS and at the same time (synchronized) send its logic inverses to DTR.

I am a student from university of toronto and very new to serial programming. please help me!!

# coad said on July 12, 2005 2:05 PM:

I run your program on my desktop (Windows XP Professional with SP2 and Visual Studio.NET 2005 Beta 2), the port can't be opened. The IDE said that "Access to the port 'COM1' is denied." It is UnauthorizedAccessException. Please tell me how to solve the problem? Thank you very much!

# coad said on July 12, 2005 2:49 PM:

The port may not exist on your computer or may be in use by another application (like for a modem). Change "COM1" in the code to another port, like "COM2" and try that. You can also check to see what ports are avalible on your machine through the Device Manager (press Windows-Break, "Hardware" tab, "Device Manager" button, "Ports (COM & LPT)" node).

# coad said on July 14, 2005 11:34 AM:

You are right. I install ActiveSyn 4.0 which uses COM1. After I delete it, the program works very well. I have another question. I modify you program in DataReceive event handler:



void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int intBytes = serialPort.BytesToRead;
byte[] bytes = new byte[intBytes];
serialPort.Read(bytes, 0, intBytes);

tbReceive.Text += intBytes.ToString() + ";";
}
The tbReceive is a TextBox control. When the program excutes at the last line,

tbReceive.Text += intBytes.ToString() + ";";

there is an exception, System.InvalidOperationException was unhandled. The error message is "Cross-thread operation not valid: Control 'tbReceive' accessed from a thread other than the thread it was created on." Please tell me what's reason and how to solve it. Thanks!

# TrackBack said on July 15, 2005 2:02 PM:

# coad said on July 15, 2005 8:22 PM:

Noah, that looks sweet! Congrats on your new purchase!

# TrackBack said on July 16, 2005 1:38 AM:

Countdown to My Weddingooeess

# TrackBack said on July 16, 2005 1:58 AM:

Visual Studio 2005 (Whidbey) Beta2 is Here!ooeess

# TrackBack said on July 16, 2005 2:00 AM:

14 Days to I Doooeess

# TrackBack said on July 16, 2005 2:33 AM:

Define 'Axiom Postulate Theorem Corollary Hypothesis'ooeess

# TrackBack said on July 16, 2005 2:38 AM:

Ballmer Dancing Developers Conference Videoooeess

# TrackBack said on July 16, 2005 2:40 AM:

Ballmer Sells Windows v1.0 TV Video Adooeess

# TrackBack said on July 16, 2005 2:43 AM:

Congrats to Jeffrey Palermo, MCADooeess

# coad said on July 16, 2005 9:40 AM:

Hi Charlie!

int intBytes;
void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
intBytes = serialPort.BytesToRead;
byte[] bytes = new byte[intBytes];
serialPort.Read(bytes, 0, intBytes);

this.Invoke(new EventHandler(SetText));


}
void SetText()
{
tbReceive.Text += intBytes.ToString() + ";";
}

# TrackBack said on July 16, 2005 8:17 PM:

US Patent Plaqueooeess

# TrackBack said on July 16, 2005 8:20 PM:

Bubble Teaooeess

# coad said on July 23, 2005 6:47 AM:

That's why women come in handle, they sure do force the issue of furnishing very quickly.

# coad said on July 25, 2005 1:49 PM:

Well in our case, I was the one who really wanted to get new furniture. I've wanted a leather couch since starting college and I've been taking Dawn along to look at couches over the last few years, so she was very kind in letting me get just what I wanted. :) Thankfully, she has similar/the same taste and provided me with an "excuse" to have a nice place (sooner than later).

# coad said on July 25, 2005 2:00 PM:

Looks great Dawn and Noah! The first purchase is always a memorable one.....

# coad said on July 25, 2005 2:02 PM:

So guys when are we going to see some pictures (wedding or honeymoon??) Inquiring minds want to know (Nicki too!!)

# coad said on July 25, 2005 2:29 PM:

Good question! :) Just so busy... I really want to post some pics! Thanks for the vote, it'll make it happen sooner.

# coad said on July 25, 2005 5:40 PM:

Hi Noah,

I read your article on System.IO.Ports.SerialPort class of new
C# Express. I tried to achieve a basic communication between my pc and the lab instrument with the following code:

After the usual port initialization,

if (com.IsOpen) com.Close();
com.Open();

// send char 34,14,192,51,0,0
com.Write(new string(new char[] { (char)34, (char)14, (char)192, (char)51, (char)0, (char)0 }, 0, 6));

// for testing purposes I connected TX and RX pins of the port...

// receive routine:
private void com_DataReceived(object sender, SerialDataReceivedEventArgs e)
{

// This method will be called when there is data waiting in the port's buffer

// Obtain the number of bytes waiting in the port's buffer
bytes = com.BytesToRead;

// Create a byte array buffer to hold the incoming data
buffer = new char[bytes];

// Read the data from the port and store it in our buffer
com.Read(buffer, 0, bytes);

}

After I activate the send routine, 6 bytes of data is received by pc but with some difference to the originally sent data.

I receive : 34,14,63,51,0,0 everytime instead of 34,14,192,51,0,0

I tried to transmit 34,14,127,51,0,0 and received the same data sequence...

As I try to tranmit anything bigger than 127 I receive 63 instead of the original data...

Do you have any idea why this is happening consistently?

Regards,
Haluk Gokmen

# coad said on July 25, 2005 10:47 PM:

Haluk: Have you tried using a byte array instead of a character array?
byte[] buffer = new byte[com.BytesToRead];

# coad said on July 25, 2005 10:53 PM:

Green,
Thanks for the update to charlie's post. The reason for this is that WinForms controls' properties must be modified on the same thread that they were created on. By using this.Invoke (where "this" is the form the control is on), it asks the form to run another method on the same thread the form is on. serialPort_DataReceived could be triggered at anytime (not just when the form is avalible) since the SerialPort control runs outside of the form's thread. This is a big advantage in that it will always be responsive to incoming serial data even if the form is busy with an intensive redraw or update.

# TrackBack said on July 26, 2005 1:40 AM:

# TrackBack said on July 26, 2005 1:40 AM:

# TrackBack said on July 26, 2005 1:40 AM:

# TrackBack said on July 26, 2005 1:40 AM:

# coad said on July 26, 2005 2:44 AM:

Dear Noah,
I tried byte array on the receiving side without a difference on the result.

I was succeding on a similar operation in VS.NET by utilizing MSComm OCX as suggested in your article at www.devhood.com/tutorials/ tutorial_details.aspx?tutorial_id=320
The following is the code:

private byte[] recdata = new byte[40]; //received data array


public void InitComPort()
{

// Set the com port to be 1
com.CommPort = 1;

// This port is already open, close it to reset it.
if (com.PortOpen) com.PortOpen = false;

// Trigger the OnComm event whenever data is received
// Loop based receieve activated...
com.RThreshold = 0;

// Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)
com.Settings = "9600,n,8,1";

// Force the DTR line high, used sometimes to hang up modems
com.DTREnable = true;

// No handshaking is used
com.Handshaking = MSCommLib.HandshakeConstants.comNone;

// Don't mess with byte arrays, only works with simple data (characters A-Z and numbers)
com.InputMode = MSCommLib.InputModeConstants.comInputModeBinary;

// Use this line instead for byte array input, best for most communications
//com.InputMode = MSCommLib.InputModeConstants.comInputModeText;

// Read the entire waiting data when com.Input is used
com.InputLen = 0;

// Don't discard nulls, 0x00 is a useful byte
com.NullDiscard = false;

// Open the com port
com.PortOpen = true;
}

private void cmdRead_Start_Click(object sender, System.EventArgs e)
{
long TimeStamp = DateTime.Now.Ticks; // Time Stamp for Time-out
bool ElapsedTime;

com.Output = new string(new char[]{(char) 34, (char) 14, (char) 192, (char) 51, (char) 0, (char) 0});

// collect data during the first one second period...
do
{
// Dont lock up the entire application
// release control to process other messages.
System.Windows.Forms.Application.DoEvents();

// If there is data waiting, buffer it in our own byte array...
if (com.InBufferCount >= 34) recdata = (byte[])com.Input;

// Look for the Elapsed Time
ElapsedTime = DateTime.Now.Ticks - TimeStamp > TimeSpan.TicksPerSecond * 1;

// Keep waiting for 1 second before processing incoming data stream...
}
while (!ElapsedTime);

Global.samplescounter = recdata[27] * 100 + recdata[26];
lblRead_RecordNo.Text = Global.samplescounter.ToString();
.
.
.
}

My instrumentation which is target to this communication action is responding to data sent in char format. It doesnt respond to byte arrays.
This previous code is still working but I cant get the new one working.
Regards..

# coad said on July 26, 2005 7:47 PM:

N&D,

It brought tears to my eyes how beautiful your photographs are, not because they are well-taken but because of the love you share and the love I have for you.

AJ

# coad said on July 27, 2005 7:50 AM:

Briefly, I would like to transmit Unicode 192 (u\192) from the serial port and read it back again. How can I do this in C# 2005 Express?

# coad said on July 28, 2005 9:52 PM:

You're right.. it's much easier!

but i have a little problem

I get this from the serial port:

U001W1 N 1,852 kg
U001W1 N 1,852 kg
U001W1 N 1,852 kg
U001W1 N 1,852 kg
U001W1 N 1,852 kg

How can i fix it, that i just geht the "1,852" from it?

thanxx

# coad said on July 29, 2005 4:59 PM:

Hello Noah and every visitor. Thanks for the great introduction to the SerialPort.
I have written a simple code, and to test i have used a cross over cable from COM1 to COM2. If I run 2 instances of the code on the 2 ports it works (send and receive) perfectly. But if I use Hyper Terminal on one end (say for example Hyper terminal on COM2 and my code on COM1) my code can send and hyper terminal receives it but if hyper terminal sends my code do not see anything. The same thing happended when i used your sample code. But of course when i test two instances of hyper terminal can eailty talk to each other.
What am I missing here?

# coad said on July 30, 2005 7:42 AM:

I am trying to send a 6 byte char array from the serial port in new C# 2005
Express:
com.Write(new string(new char[] { (char)34, (char)14, (char)192, (char)51,
(char)0, (char)0 }, 0, 6));

I am receiving 34,14,63,51,0,0 from the port as I connected Tx and Rx pins
to each other by using the following code:

private void com_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
bytes = com.BytesToRead;
if (bytes >= 6)
com.Read(buffer, 0, bytes);
}

The hard thing to understand is: in this array if I replace 192 with 127 or
any number below I get the array back as it is. Any number above 127 is
received as 63.

Any ideas about the underlying reasons for this?

# TrackBack said on July 31, 2005 10:05 PM:

New Living Room w Couchesooeess

# TrackBack said on July 31, 2005 10:06 PM:

Countdown to My Weddingooeess

# TrackBack said on July 31, 2005 10:06 PM:

Visual Studio 2005 (Whidbey) Beta2 is Here!ooeess

# TrackBack said on July 31, 2005 10:06 PM:

14 Days to I Doooeess

# TrackBack said on July 31, 2005 10:06 PM:

Define 'Axiom Postulate Theorem Corollary Hypothesis'ooeess

# TrackBack said on July 31, 2005 10:06 PM:

Ballmer Dancing Developers Conference Videoooeess

# TrackBack said on July 31, 2005 10:06 PM:

Ballmer Sells Windows v1.0 TV Video Adooeess

# TrackBack said on July 31, 2005 10:06 PM:

Congrats to Jeffrey Palermo, MCADooeess

# TrackBack said on July 31, 2005 10:06 PM:

US Patent Plaqueooeess

# coad said on August 1, 2005 2:59 AM:

How do you set serial port encoding?

# coad said on August 1, 2005 9:46 AM:

Haluk,
Try using the SerialPort.Encoding property. For example: port.Encoding = System.Text.Encoding.UTF8;

# coad said on August 4, 2005 6:52 AM:

Great intro maan.

I tried reading from COM1 using VB.NET (2005 beta 2). I am not able to get the DataReceived event to get triggered. The data from a connected scale transmits whenever its weight is stable.

I coded this in a form. Does it have to be a console application instead ?
I am using ReadExisting(). Do you need to use ReadByte() ? If yes, does that code need to be in a thread to avoid sync/no-timeout ?

Thanks for any advice.

# coad said on September 1, 2005 7:42 AM:

I have written a program that sends commands to and receives the responses from a serial device. This work normaly. However the device is also outputing data every .x seconds. I am having a very difficult time receiving this data and getting it onto my form. Your suggestions and advice are greatly appreciated.


Private Sub Write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Write.Click

Dim gxTXDBuffer As String
Dim sInput As String

Dim lTimeout As Long
Dim Time As Long

'clear input buffer counter
AxMSComm1.InBufferCount = 0

'setup command to send
gxTXDBuffer = sendtext.Text & Chr(10)

'send command
AxMSComm1.Output = gxTXDBuffer

'-----------------------------------------------------------------------
'not sure how to get data when counting
'
'While sendtext.Text = "C"
' Microsoft.VisualBasic.Timer > lTimeout
'
'read in response
'sInput = AxMSComm1.Input
' receivetext.Text = sInput
' End While
'-----------------------------------------------------------

'wait for response or timeout
lTimeout = Microsoft.VisualBasic.Timer + 5

Do
Application.DoEvents()

Loop Until AxMSComm1.InBufferCount >= 8 Or Microsoft.VisualBasic.Timer > lTimeout
'
'read in response
sInput = AxMSComm1.Input
receivetext.Text = sInput

End Sub
'another attempt at reading counts when com event
'
' Private Sub AxMSComm1_OnComm()
' Dim sInput As String
' commevent 2 = Received RThreshold number of characters. This event is generated continuously
' until you use the Input property to remove the data from the receive buffer.
' If AxMSComm1.CommEvent() = 2 And AxMSComm1.InBufferCount > 0 Then
' sInput = AxMSComm1.Input
' ' receivetext.Text = sInput
' End If
'' End Sub

# coad said on September 1, 2005 10:23 PM:

How do you program the Basic Stamp to output a string that you sent from your PC?

Anyone can help?

Thanks!!!

# coad said on September 5, 2005 10:59 PM:

I am using VS.Net 2003, Actually i ve to do hardware interface in which i need to recieve data and plot it as graph and save it in database. Can anyone help me out...
Thanks

# coad said on September 8, 2005 3:55 PM:

Hi All,

I have the following problem:

After sending a Write command to a device, directly followed by a Read command it seems that the data on the device is not yet available.

It seems that the write/read part is too fast for the device to 'generate' the data.

The baudrate is 9600 and cannot be higher. Also i would not like to add a pause.

Does anyone have a solution here ?

Thanx,

Jan

# coad said on September 11, 2005 3:21 PM:

We call it boba tea in Los Angeles. Some of my favorite places are Boba Paradise (Torrance) or Tapioca Express (Irvine). Thanks for the information. Now I know where to send my mom in CS.

# coad said on September 14, 2005 12:59 AM:

What about the Timer in windows forms, for data arriving at any time and various durations?
does firing an event during reading current event would cause problems?

thanks for your efforts

thanks,

elwolv

# coad said on September 15, 2005 8:02 AM:

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP]

That key is for Windows 9x/ME. I use XP and that key doesn't exist for me.

# coad said on September 23, 2005 5:09 AM:

Bad file error... (404)... where should I download it? HYH
Ueslei

# TrackBack said on September 25, 2005 1:55 AM:

# coad said on September 26, 2005 6:26 AM:

Hi All,

Noha - a great article!

For some reason I'm not reaching the 'port_DataReceived' function. Any ideas why?
I'm running the 'SerialPortTerminal' application on my computer with the 'Portmon' application monitoring all data at the serial port so nothing is physically connected to the COM. May this be the reason?

Thanks for your help.


Elad

# TrackBack said on September 27, 2005 8:03 AM:

# coad said on October 12, 2005 3:27 AM:

Hi there,

Your article is awesome and the information is so great and very useful.

However, I have a problem when I tried to write a software to communicate to bluetooth ports(COM4 and COM7) in PDA. The .NET 2.0 does not provide a platform for mobile device.

Suggestions please.

Thanks a lot,
Ikkyusan ;)

# coad said on October 17, 2005 8:53 PM:

Ikkyusan:
The .NET Compact Framework does not have built in support for serial communications. There are many third-party controls available. Try a Google search like:
http://www.google.com/search?hl=en&q=serial+com+compact+framework

# coad said on October 18, 2005 6:57 AM:

Where is my Beta

# coad said on October 28, 2005 3:07 PM:

This is an awesome and extremely useful article! My one suggestion is that you add some minor clarifications on the DtrEnable property. I'm connecting to an Ultra 5 Sun box and was having a lot of troubles with my commands just getting echoed back to me. Setting the DtrEnable = true solved that problem. My understanding is that it tells the serial port that you're talking from one data transmitter to another data transmitter.

# coad said on November 10, 2005 11:15 AM:

He blogs again!!!

# coad said on November 12, 2005 10:21 AM:

Im trying to contact my sony wavehawk scanner with.
port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.Encoding = System.Text.Encoding.Default;
port.NewLine = "\r";
port.ReceivedBytesThreshold = 1;

port.DtrEnable = true;


It reacts, but I dont get the "ok." that I'm expecting... Any ideas?

I use Serial monitor so that I see what goes in and out.

//J

# coad said on November 13, 2005 8:29 PM:

I am try to get exactly Method that line the Hexa Method using for sending data throught RS232, that I want is the function fo sendding binary. How can I slove this problem, thank for helping!

# TrackBack said on November 19, 2005 4:53 PM:

# coad said on November 25, 2005 2:14 PM:

Jimmy:
Don't forget to attach a delegate to the DataReceived event, open the port (.Open), and send data (.Write). Beyond that, it may be something specific to your scanner device.

# coad said on November 28, 2005 10:42 AM:

The .NET 2.0 class library does not seem to support devices powered by the serial port.

I have a couple different magstripe readers here at work which will work correctly after making a connection with HyperTerminal or opening the port in a similar .NET 1.1 library, but the device will not function after SerialPort.Open() on .NET 2.0, whether I write a driver program from scratch or try something like Noah's Serial Terminal. No exception is thrown and SerialPort.PortOpen return True so I know at least, the class library thinks it is funnctional. The light on the device, however, is off, so I know it's not getting power.

Does anyone have a serial port powered device working?

# coad said on November 28, 2005 11:19 AM:

Great tutorial. I really want to read data from the com port using managed c++ rather than C#. Can't find a sample anywhere, Heeellllp!!!

# coad said on December 8, 2005 7:15 AM:

I am trying to open a connection to COM3 on my machine. I have a USB device attached to the computer and its drivers emulate a serial port on COM3.

SerialPort.GetPortNames() returns "COM1" and "COM3" and if i connect to the port using TeraTerm its fully functional and i can see the data.

When i invoke open on the port after having set the port name to "COM3" i get an argument exception that the name doesn't start with COM or that there is no such port. The name DOES start with COM and as i said, GetPortNames() includes COM3.

Anyone experienced this? Solutions?

I am using VS 2005 Final on Win XP SP2.

/// Isak

# Marcus said on December 11, 2005 5:11 PM:

Top Stuff, I thought there may be a way to hack it... 10 is just tooo low...

# TJ said on December 13, 2005 5:10 PM:

Does anyone know how to send a special character over the serial connection? Specifically I'm trying to send a ctrl+c.

Thanks!

# TJ said on December 23, 2005 11:09 AM:

How would I send a ctrl+c (break) via serial?

Thanks!

# syncter said on December 29, 2005 5:05 AM:


Thanks for useful code snippet.

If I would like to use a different DefaultIcon other than current defaulted in the application, let's say in a resource assembly file (myResource.dll contains multiple icon files), how can I identify the resource ID it should point to?


rkey.CreateSubKey("DefaultIcon").SetValue("mypath/myResource.dll" + ",?");

Thanks.


# Noah Coad's Code said on January 4, 2006 7:21 PM:


Well in the switch from .Text (and msmvps.com) to Community Server (and blogs.msdn.com), there was...

# Daniel said on January 5, 2006 6:43 PM:

Ive written a Serial Port monitoring app that reads data from the COM port real time and displays it to a Rich Text Box (along with any special characters such as Carridge Returns, Line Feeds etc). This program works perfectly on Windows XP however when I transfer it to my Server running Windows Server 2003 Standard Edition, it doesnt work. I have installed the NET.Framework 2 on the Server.

Further troubleshooting I redesigned the program to write a line of text to a text file when the method is called for Data waiting at the Serial Port Buffer. That line of code is :-

port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

So it appears to me that the method is never being called. The text file also logs when the Serial port is opened and close and when any exceptions are thrown.

I know the device attached to the serial port is working as I fire up a 3rd Party Serial Port Monitor &/or Hyperterminal and I see the data continuously coming through.

Can anyone offer any assistance with this problem?

Thanks,
Daniel.

# Kintesh Patel said on January 13, 2006 4:30 PM:

Those who are using Serial to USB convertor, Please check article "USB-to-RS232 Hurdle Race" published in elektor electronics Sept. 2005.

It describe behind the scene effect and it's reason.

# Noah Coad's Code said on January 14, 2006 6:15 AM:


Well in the switch from .Text (and msmvps.com) to Community Server (and blogs.msdn.com), there was...

# Noah Coad's Code said on January 14, 2006 6:40 AM:


Well in the switch from .Text (and msmvps.com) to Community Server (and blogs.msdn.com), there was...

# Noah Coad's Code said on January 14, 2006 6:40 AM:


Well in the switch from .Text (and msmvps.com) to Community Server (and blogs.msdn.com), there was...

# Noah Coad's Code said on January 14, 2006 6:41 AM:


Well in the switch from .Text (and msmvps.com) to Community Server (and blogs.msdn.com), there was...

# Noah Coad's Code said on January 14, 2006 7:41 AM:

Here's a quick little bit of fun. I was just going through my Netflix rental log, and through ye-old...

# Noah Coad's Code said on January 14, 2006 7:42 AM:

Here's a quick little bit of fun. I was just going through my Netflix rental log, and through ye-old...

# Noah Coad's Code said on January 14, 2006 7:45 AM:

Well in the switch from .Text (and msmvps.com) to Community Server (and blogs.msdn.com), there was a...

# Ashley said on January 17, 2006 6:16 AM:

Hi guys,

Many terminal programs that are available (Hyperterminal being one of them) do not implement handshaking correctly.

A normal 232 connection will most likely require DTR enabled as well as RTS as well.

For you apps try setting your serialport with

port.Handshake = System.IO.Ports.Handshake.RequestToSend;

This is what most terminal programs call hardware flow control. It will enable RTS/CTS flow control which most devices rely on for transmission timing.

You may have played with the handshaking in HyperTerminal but if you use a 232 hardware analyser you will notice that it does not change any lines on your port. Changing these setting with a .net v2 app certainly will

Setting DTR to enabled and handshaking to hardware should power the pin that manufacturers use for power robbing as well.

Hope that made sense and is of some use

Ashley



# Gan esh said on January 18, 2006 3:41 AM:

Hi, I am using Visual Studio .NET 2005 which has serial port class built with it.
I am developing a Web Application in which i require to do serial communication. and i just wanted to know how exactly to include the SerialDataReceivedEventHandler Event in my web application, please help me out.

Thanks in advance
gan esh

# Limber said on January 18, 2006 10:59 AM:

Are you aware of that this method locks the GUI, if you have one, while fetching remote data?

# Mark said on January 26, 2006 3:12 AM:

Err, where's it gone? The link leads nowhere. Well, okay it does lead to a 404...

# Mark said on February 1, 2006 2:31 AM:

Thanks for the article Noah! I've run the sample as it is and have been unable to get a response from the Wavecom GSM Modem that I am trying to talk to - the port_DataReceived() event is never fired.

This is driving me nuts! Any ideas? I'm running this on a Windows 2003 Server using VC# Express 2005.

Regards,
Mark.

# Tim Nguyen said on February 3, 2006 7:46 PM:

If you are having trouble with this, remember to send a "\r\n" command. It works perfectly if you do this.

# LarsPetter said on February 4, 2006 11:21 AM:

I have connected my PC to a BS2 sitting on a Board of Education(using an USB to Serial adapter). When i write something to the BS2, it gets there, but it also ends up in the input buffer. Why does this happen, and how can i prevent it from happening?

# Glenn said on February 13, 2006 5:18 PM:

Using your code:
-----------------------------------------------
private List<byte> PortBuffer = new List<byte>();

private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port = (SerialPort)sender;

byte[] data = new byte[port.BytesToRead];

port.Read(data, 0, data.Length);

PortBuffer.AddRange(data);

ProcessIncomingData(PortBuffer);
}

private void ProcessIncomingData(List<byte> PortBuffer)
{
// Search through the bytes to find the data you want
// then remove the data from the list. It is good to
// clean up unused bytes (usually everything before
// what you're looking for)
}
-------------------------------------------------
I need to find a two byte sequence (E0 80) in the data. I can find one byte or the other with something like this:
----------------------------------------------
int found = PortBuffer.FindIndex(delegate(byte i)
{return i==0xE0;}
);

Console.WriteLine(found);
----------------------------------------------
But how can I find the index of a exact sequence? Thanks.

# Mark Holt said on February 14, 2006 11:36 AM:

The SerialPort Terminal worked fine for me...that is if I was communicating with another SerialPort Terminal app.
When I tried to communicate with HyperTerminal I had to change the handshaking.

After:
comport.PortName = cmbPortName.Text;

Add:
comport.Handshake = Handshake.RequestToSend;

Or:
comport.Handshake = Handshake.RequestToSendXOnXOff;

I used SysInternals' Portmon to compare how HyperTerminal connects to the COM port vs. the .Net 2.0 SerialPort class and noticed quite a few differences that I cannot control via the SerialPort class such as:

IOCTL_SERIAL_SET_HANDFLOW has a different XonLimit and XoffLimit (1024 instead of 80 and 1024 instead of 200, respectively)

IOCTL_SERIAL_SET_TIMEOUTS has a different RI, RM, RC and WC (-1 instead of 10, -1 instead of 0, -2 instead of 0 and 0 instead of 5000, respectively)

IOCTL_SERIAL_SET_WAIT_MASK checks for RLSD and ERR (like HyperT) but also checks for RXCHAR, RXFLAG, CTS, DSR, BRK, and RING.

IOCTL_SERIAL_SET_QUEUE_SIZE has an InSize of 4096 (instead of 8192) and OutSize of 2048 (instead of 8192).

# Asi said on March 6, 2006 6:49 PM:

I'll have to check out both those places! Thanks for the info, I'll be heading there soon, and I really Love boba tea. I usually go to Fusion Bubble Tea (Vancouver, Wa) and so far I love it! Their boba are perfect too, sweet and chewy.

# Leslie Viljoen said on March 16, 2006 8:54 AM:

You probably have something else using that com port and it's locked. Make sure your terminal program is closed.

# MaheshKumar.R said on March 30, 2006 8:51 AM:

Nice collection. Thanks a lot.

Mahesh

# Vincent Collin said on March 30, 2006 2:35 PM:

Thanks alot Noah,

Great tutorial, was very very useful in my project.

Framework 2.0 is pretty useful when you need to use those good old serial port.

# Carlos said on April 11, 2006 12:33 PM:

Hi, I am trying to read the data on COM7 (USB) on my machine.
When add the event handler to the progam i get an JIT debugging error: Class not registered.

Anyone expirienced this?

I'm using Visual C# Express ed. on Win XP SP2

# tooBusy4MyOwnGood said on April 27, 2006 11:59 PM:

How does 4NT compare with BASH? I have been using CYGWIN for years, and often find myself using the BASH shell for complicated projects (and since I put the ../cygwin/bin in my PATH I can call the GNU utilities from either BASH or CMD). Since I have the basic GNU utils installed, this is a pretty strong colleciton to agument hte 50 or so built-in BASH commands. Plus, it is hard to compare power BASH scripts (augmented with Perl as needed) to anything else I have seen for Win32.

# rachel said on May 11, 2006 1:15 AM:

port = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
port.Open();


USB Cable Off - > CPU 100%

Help me

# Telecharger Messenger said on May 21, 2006 1:20 PM:

http://blog.iquebec.com/telechargement

# EP said on May 29, 2006 10:50 AM:

what is the source codes for RS232 connection in framework 1.0 ? please help me!!!!!

# Srikanta said on June 9, 2006 6:56 AM:

Thanks for this article.i am new to .net development.i am fresher in development.
i want to learn more deep in serial programming.
i have connected to com1.
i am able to check whether bonus card is present or not,but i want to raed data from card from a particular byte to n byte.
so which method i have to use and how to use.plz reply me with syntax and code

# hassan said on June 19, 2006 10:35 AM:

thinks for these information ,i want do this ,but in Visual Studio2003 . I mean open Port COM3  and  have a communication with a modem and call from My Pocket PC

# hitesh said on June 20, 2006 1:24 AM:

hello,i want to require vb.net code for reading stream of data asynchronously  from serial port using multithreading as a background thread,so that is required,if more than one RFID tag read by serial port at a time.so how i can store all the tag read by serial port.

# Ahmet Vehbi said on June 26, 2006 3:23 AM:

Dear All ;
Would you please send me the tha samples data's to compile in my own pc.
Because i couldn't achive to make the form in the appropriate shape,size or position.
Thanks to whom it may concern..

# Palani said on June 27, 2006 2:04 AM:

Hai,
thanx for the nice list of resources.

I would also some more on usb and serial stuff.

Thanx
Palani

# Punx said on June 29, 2006 1:35 PM:

Why does my timer dont start when I use timer1.Enable=true inside the DataReceived event handler?

# TheRunningBoard said on June 29, 2006 8:14 PM:

Great work!

# coad said on July 1, 2006 4:13 PM:

If you'd like to find the place for yourself, here are some links.  Late fall to early summer is the best time.

Trailhead Location is Latitude 48:04.07 N by Longitude 121:30.83 W

Google Map to Trail Head
http://maps.google.com/maps?f=q&hl=en&q=48.0678333333,+-121.5138333333+(Big+Four+Ice+Caves+Trail+Head)&ie=UTF8&om=1

Other Links to the Ice Caves
http://www.google.com/search?hl=en&lr=&q=Big+Four+Ice+Caves%2C+washington&btnG=Search
http://www.localhikes.com/Hikes/BigFourIceCaves_7602.asp
http://www.fs.fed.us/r6/mbs/recreation/activities/trails/drd/drd_0723.htm
http://glaciercaves.com/html/bigfou_1.HTM
http://www.wta.org/~wta/cgi-bin/wtaweb.pl?3+tg+fetch+english+1004

# Zak said on July 3, 2006 6:07 AM:

hi
I'm using Visual Studio.net 2003
I have installed the .NET 2.0 (not the beta version)
and I cant find the name space
System.IO.Ports
any idea why
please help me

# Noah Coad's Code said on July 3, 2006 10:14 PM:

My wife, Dawn Melody Coad,&amp;nbsp;and I have been married for just over a year now!&amp;nbsp; Wow, what a year!&amp;nbsp;...

# Noah Coad's Code said on July 3, 2006 10:14 PM:

My wife, Dawn Melody Coad,&amp;nbsp;and I have been married for just over a year now!&amp;nbsp; Wow, what a year!&amp;nbsp;...

# Noah Coad's Code said on July 3, 2006 10:14 PM:

My wife, Dawn Melody Coad,&amp;nbsp;and I have been married for just over a year now!&amp;nbsp; Wow, what a year!&amp;nbsp;...

# Noah Coad's Code said on July 3, 2006 10:14 PM:

My wife, Dawn Melody Coad,&amp;nbsp;and I have been married for just over a year now!&amp;nbsp; Wow, what a year!&amp;nbsp;...

# Noah Coad's Code said on July 3, 2006 10:14 PM:

My wife, Dawn Melody Coad,&amp;nbsp;and I have been married for just over a year now!&amp;nbsp; Wow, what a year!&amp;nbsp;...

# Noah Coad's Code said on July 6, 2006 8:20 PM:

I&amp;rsquo;ve been searching for a way to nicely display code on my blog for a long time!!&amp;nbsp; These old...

# Noah Coad's Code said on July 6, 2006 8:20 PM:

I&amp;rsquo;ve been searching for a way to nicely display code on my blog for a long time!!&amp;nbsp; These old...

# coad said on July 7, 2006 7:40 PM:

Zak:

Visual Studio 2003 is only for writing code against the .NET 1.1 framework.  Even if you have .NET 2.0 installed, you won't see it in VS 2003.  You need VS 2005.  You can write the code with a plain text editor and compile it through the .NET 2.0 command line compiler.

# David Briggs said on July 9, 2006 8:41 PM:

I am doing some serial communication to a divice using .NET 2.0.  The device has a set of simple commands, each command and responce is a fix size. Each command will generate a responce and a new command can not be sent until the responce from the previous command has been recived.  I have set the DataReceived event handler to a method that will read the responce data. That part works OK.  There is a flag in the event handler that I set when I read the response. I poll for that flag to see when I can sent the next command. My question is is there any way I can know when it is OK to send the next command without polling? The DataReceived event is raised on a secondary thread. If there was some way to get the thread Id of the event handler I could do a thread Join to tell when the data reading is done.

# De IT y cosas peores » Java vs .NET: Puerto Serie (Parte II) said on July 10, 2006 2:14 PM:

PingBack from http://cesarolea.com/index.php/archives/157

# valker’s blog » Blog Archive » ?????????? CMD.EXE said on July 11, 2006 5:14 AM:

PingBack from http://valker.wordpress.com/2006/07/11/cmd_exe_tricks/

# Noah Coad's Code said on July 14, 2006 2:32 PM:

Here are two project templates that I created and use on an almost daily basis that I packaged up to...

# Quick Code + Console App Custom Project Templates for C# in VS05 » Wagalulu - Microsoft » » Quick Code + Console App Custom Project Templates for C# in VS05 said on July 14, 2006 3:04 PM:

PingBack from http://microsoft.wagalulu.com/2006/07/14/quick-code-console-app-custom-project-templates-for-c-in-vs05/

# shinoy said on July 20, 2006 11:49 PM:

it is good. But if some one could explain about if someone need to get data from an epbx, wat method can be used.

# silibug said on July 23, 2006 1:43 AM:

Hi... nice article :)

btw..

How can  we  communicate with our serials port on LAN environment.?.
any idea how to convert rs232 output for tcp/ip input?

PC <-> LAN/switch <-> Microcontroller <-> Rs232 <-> devices

thanks:)

# Noah Coad [MS] said on July 24, 2006 11:33 AM:

silibug,
There are devices that let you control RS232 ports remotely over an ethernet network.  For example, the $99 LS100 by Aaxeon at http://www.aaxeon.com/products/Productdetail.aspx?cate=2&modelno=LS100    A Google search on "ethernet rs232" (without quotes) shows some more such devices.  

# SR said on July 27, 2006 12:48 AM:

Thanks for creating this, it has helped me greatly.  This is my first day using visual C# express and tutorials like this are making progress possible.  Hopefully I can contribute in the future.

One note:  In order to build, I had to comment the line //File.WriteAll(TempFile, html); out as I got an error "'System.IO.File' does not contain a definition for 'WriteAll'.  Not sure if I am an isolated case, but it doesn't seem to affect the program.

# Allan said on August 9, 2006 8:53 AM:

I'm sending commands ATs for modem port, and the modem do not receive the commands. I use (SerialPort Terminal) .... HELP me


thanks

# Noah Coad [MS] said on August 10, 2006 12:22 PM:

Allan,
There isn't enough info in your comment to figure out what's going on.  Try [ENTER] [ENTER] [ENTER] ATE1 [ENTER]      The first set of [ENTER] commands is for the modem to detect the baud rate.  ATE1 turns on echoing back commands so you can see if the modem is responding.  Good luck.

# Noah Coad [MS] said on August 10, 2006 12:22 PM:

SR,
Thanks for the pointer! :)

# Julio Silva said on August 10, 2006 3:15 PM:

Hello,

I'm a begginer, and I'm tring to do a simple terminal (receive only) for my
pocket pc, built in C#, with CF.Net 2.0.

I have 2 bottons, one for serialport.open, other serialport.close.
And works fine, since it's for a GPS connection, and I see it
connecting/disconnecting.

I have a label, that if I do a label1.text=serialport.readexisting(); it
displays all.
but if I do it in serialport.datareceived event, it get's an runtime
error...
If I do anything like label1.text=serialport.readchar(); it get's the same
error.
What I'm doing wrong?
I only have some programming experience in Delphi and C++...

Thanks for your help,

jS

# Noah Coad [MS] said on August 10, 2006 7:24 PM:

jS,
I've answered your question in the (new) FAQ section:
http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#FAQ

# Julio Silva said on August 11, 2006 6:41 AM:

Sorry I missed it.
The problem it's now solved, thanks.

BTW there is an link error in SerialPort Terminal, the filename has a space, SerialPort Terminal.zip, and the link doesnt, so it say's it's not found...

Thanks again for the help,

jS

# James Vaughan said on August 14, 2006 11:21 AM:

XslCompiledTransform is the new class to do this with.  It should be really easy to convert between the two.

# coad said on August 14, 2006 5:39 PM:

Julio,
I agree the file name is confusing with the space (and has been for a long time).  I've removed the space from all the links in the post and the filename.

# Seng said on August 16, 2006 8:46 PM:

Hi All

I try to use this example to send a ATDT6129 command to dial an extension number. I got an error message from my Modem. If I try to use Microsoft Hyper termanal it works. Any ideas?

Thanks

# Sheng Zhou said on August 16, 2006 9:33 PM:

Hi Coad

This example is very good, but atd or atdt command doesn't work. I have try other commands such as 'at', 'ati4' etc. they works. I don't know how to send a atd or atdt command to my modem. At moment, when I send atd or atdt command to my modem it got 'error' message back. Any ideas?

Thanks

# NAFF said on August 17, 2006 9:08 AM:

I am looking to setup serialport in VC++.NET V2.  Do you have an example. All I wnt is to be able to read data from a microcontroller. I an new to VC++ and cant understand the c# example.

many thanks

# Bill - WV7G said on August 18, 2006 2:06 PM:

I've been searching for the simplest way of coding the deligate to send received text to a textbox.  I should have known it would be a fellow HAM who had the answer!
Great stuff and very well done!

# Todor’s Weblog » Serial Communication said on August 22, 2006 2:53 PM:

PingBack from http://todor.be/blog/?p=45

# prem said on August 23, 2006 12:23 AM:

hi,
iam using visual studio3.0 and framework version is 1.1
Now ia want to access the serial prot using c#.

in this version SerialPort namespace can't use

how can i use API to access the serial port in C#(version1.1)
or
any method top access the SerialPort namespace in this version

plz help me
i want this very urgent
plz send
my email.id is
gpremkamal@yahoo.co.in

# coad said on August 29, 2006 5:44 PM:

Hey prem, I just wrote an answer to your question in the FAQ portion of this post as question #3. See: http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#FAQ

# Tsahi said on September 3, 2006 3:20 PM:

hi, regarding .net 2.0 being free, well, the sdk is free, but who wants to code in notepad? you will have to pay for visual studio 2005 lot's of dollars, and my understanding is that the "express" editions are only free until november 2006. but there's a free open souce alternative called SharpDevelop, at http://www.icsharpcode.net/OpenSource/SD/Default.aspx . i tried their version 1.1 a while back and it was not bad, except for a few bugs. i hope their version 2.0 (for .net 2.0) is better, but i didn't try.

# rajnish said on September 4, 2006 10:44 PM:

Dear Coad, I am an MCA student and need your help in , in Bi Directional interfacing an instrument, wherein I have to send some Delimited String to the instrument with certain commands Like ACK NAK STX etc. and Take the Data Instrument sends, So far I have been able to receive the data from the instrument, but while sending the data I don't get any reply, and nothing reaches to the instrument, where as the cable I have made is correct, and I know there is something wrong with the code it self please help me I am posting the details below please guide me how I can send the string to the Instrument i am using c# 2005 Please guide me Thanking you in anticipation Rajnish

# SilentDawn said on September 5, 2006 7:10 AM:

.net 2.0串口通信新控件--(serialPort)

# Gaurav said on September 11, 2006 6:18 AM:

Hello Sir, The code you have provided is very appreciable to me coz almost all my problems have been solved. But only one problem is there i m explaining you: I m using a RichTextBox to display all the data that is in Buffer, But while displaying that data that is coming to textbox is some symbols not the actual text data. Like as if we use HYPERTERMINAL a windows program where it will display all the calls,duration,Number etc. I want to display the same data in RichTextBox. Only the textual data. Plz Help????? Urgent??????????

# Noah Coad [MS] said on September 11, 2006 12:32 PM:

rajnish,
I just wrote an answer to your question in the FAQ portion of this post as question #4.
See: http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#FAQ

# Pockey said on September 13, 2006 8:56 PM:

Hi, thanks for your article!

I have a problem.  In your demo program, after I click the "Close Port" when there are still data sending from the Serial Port, the application will die. And I have to use "Ctrl + Shift + Delete" to end it. Any method to solve this? With "comport.close()" and data still in process, where all the data will be sent to?

# coad said on September 22, 2006 12:23 AM:

Pockey,

In a case like this, you can do something like when the user clicks "close", in the form's closing event handler, make a loop that check's the comport's sending buffer, when it is 0, then allow the close to contine.  I'd also set the cursor to a wait hourglass and add a timeout (in case it takes too long).

# Huy Tran said on October 4, 2006 12:03 AM:

hi Coad,

I am using serialport in framework 2.0 to make a connection to another port.I have some problem, some attribute in serialport are not has like AxInterop.MSCommLib.dll's attribute, such as : in AxInterop.MSCommLib.dll, there are have EOF enable, Sthreshold, Inputlen, InputMode. But in serialport, there is no these attributes.

One more question : Is serialport just suppose for Smart device (POCKET PC, WINDOWN CE)?

I am writing a app to connect another machine to send/receive data.

Please give me some advice!!

Thanx for reading.

# Fredrik said on October 12, 2006 8:00 AM:

FINALLY! I've been looking for this kind of solution for 8 hours.

I am so happy right now.

Super great tutorial or what I sould call it.

Thank you!

# Jon said on October 16, 2006 9:08 AM:

Coad, thanks for the excellet article.

I have tried to implement it in C++.NET 2 and below is some of the code in question which I am having problems with, when I run this it gives me exception which says BUFFER CAN NOT BE NULL.

Any help would be greatly appreciated. I am working on a PIC MCU, I will make my work public on your blog once it works hopefully.

void SendRs232Data()

{

 // Instantiate the communications port - this is done in //the form properties of serialPort control from the toolbox

 // Open the port for communications

 serialPort->Open();

 // Write a string

 serialPort->Write("Hello World");

 int offset = 1;//The offset in the buffer array to begin //writing.

 int count = 1; //The number of bytes to read.

 array<unsigned char>^ buffer ;//The buffer array to write //the input to.

serialPort->Read(buffer, offset, count);

 serialPort->Close();

}

# Noah Coad's Code said on October 16, 2006 4:53 PM:

When copy/pasting from MS Word, the HTML it generates is really messy and can't be used verbatim. This

# Mach said on October 17, 2006 2:23 AM:

hi,

I want to have  local resources (COM1, COM2) available to a terminal server.

I made my local serial port available in a session in Remote Desktop Connection window.

On terminal server I can see my serial port mapped to some TS033 and TS034 ports.

How can I open/use/connect these ports?

private SerialPort port = new SerialPort("TS033", 9600, Parity.None, 8, StopBits.One);  deasn't work.

On WinServer2003 it says:  The given port name does not start with COM/com or does not resolve to a valid serial port.

Thanks for any help.

# coad said on October 17, 2006 11:14 AM:

Jon,

You've defined the variable for the buffer, but you need to create an array as well.  In C#, it would look like this:

byte[] buffer = new byte[10];

# coad said on October 17, 2006 11:15 AM:

Mach,

Usually ports are mapped to COMx, sometimes as high as COM32.  Please see if you can map them to a COM number like this.

# coad said on October 17, 2006 11:17 AM:

Huy Tran,

The .NET 2.0 SerialPort class is not for devices, only full PCs.  There are 3rd party serial classes for mobile devices.  The .NET classes are wrappers around the Win32 APIs, so some of the members are renamed and they may not all be avalible.

# jon said on October 18, 2006 8:46 AM:

coed,

thanks for pointing me in the right direction. as you said buffer was not defined as an array correctly.

the program sort of works but does no print hello world, it prints the numbber 5, which is the byte size i am looking to print.  i expected hello to print. any ideas as to where i am going wrong?  many thanks.

void SendRs232Data()

{

 serialPort->Open();

  serialPort->Write("Hello World");

 int offset = 0;//The offset in the buffer array to begin writing.

 int count = 5; //The number of bytes to read.

  array<unsigned char>^ buffer = gcnew array<unsigned char> (10);//The buffer array to write the input to.

 serialPort->Read(buffer, offset, count);

lblSerial->Text= (serialPort->Read(buffer, offset, count)).ToString();

  serialPort->Close();

}

# Dejan said on October 20, 2006 6:44 AM:

My project requires external GPRS modem attached to serial port to send and receive SMS messages.

In addition to original Noah's code at the start of the blog, I've laso added and changed some things according to hints in the blog (thanx, guys); following i s a short summary of my add-ons to make the modem work:

1. Set modem handshake, like:

serialPort1.Handshake = Handshake.RequestToSend;

2. Prior to send first command, try to synchronize modem by sending "\r\n" after port.Open(), like:

serialPort1.Write("\r\n"); // sync purpose only

3. Always use "\r\n" at the end of the command, like:

serialPort1.Write("AT+CMGF=1\r\n");

(just in the case of sending SMS message itself, I use something like:

serialPort1.Write(textBox1.Text + "\u000D\u000A\u001A\n");

)

4. As described in FAQ (Q1), use Invoke and event delegation, like:

private void MyLog(string msg)

       {

           listBox1.Invoke(new EventHandler(delegate

           {

               listBox1.Items.Add(msg);

           }));

       }

private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)

       {

           // Read data

           string data = serialPort1.ReadExisting();

           // Display the text to the user in the terminal

           MyLog(data);

       }

And this is it. After a couple of hours of being frustrated because of simplicity of using SerialPort class in .NET 2.0, but no result, it finally works.  

# Yonas said on October 23, 2006 9:08 AM:

RE: Test,

you dont say what programe you are using, but if you are sending and receiving data from the same port for a test, i suggest you wire up a NULL MODEM cable with one end connected to your COM2 port and at the other end connect PIN2 and PIN 3 using a wire. This will send what ever is in the Tx line to Rx line and you should be able to send TEST and read TEST on you monitor. A quick test to verify your cable is wired right would be to use hyperterminal. I hope I understood what you are trying to do correctly.  

# Matthias said on October 31, 2006 3:59 AM:

I need to send/recieve data to/from a uC using rs485 as protocol. I use a transducer to get the PC's rs232 and the uC's rs485 connected and therefore I need to have the RTS signal set at the start of writing data and unset it after all bytes have been written.

Unforutnately the given Handshakes set the RTS line but don't unset them after write.

Manually setting and unsetting RTS causes the RTS to be unset before all data have been written (although while loop until writebuffer is empty)

P.S.:

I can get it working if I run the obsolete c++ program, that was used for the same purpose, and send a command to the uC once. After that the RTS handling with the c# prog works fine. But there has to be a way to get it working directly from c#.

Regards

Matthias

# pegah said on November 8, 2006 1:12 AM:

how can i access to pin ??? i want set CTS or ...???

# Vinay said on November 8, 2006 6:32 AM:

Hi...

Your demo project is very good.

In my application i want to read text recieived on PC comport upto a string and after that i've to transmit some data on my port. So can you tell me how i can do this.

(e.g. I want to set the date & for that i have to wait until i receive text "Set Date :". )

Thanks,

Vinay

# Jack said on November 21, 2006 2:07 PM:

ClosePort() is also sending a byte '00' to receiver, how avoid it? I can't set DiscardNull=true because I am using rs232 for binary data communication.

Thanks!

# Rick said on November 22, 2006 4:18 PM:

Where in Victoria is this place? could you give me an address?

# bidi said on November 27, 2006 11:04 AM:

i have a problem when i use GetPortName , i take port name for Com like this Com4, and i use the following code

--------------

foreach (string s in SerialPort.GetPortNames())

           {

               cmbCom.Items.Add(s);

           }

------------------------

the com4 is bluetooth . is  anyonethat have any ideea about this?

thks bidi

# zanis said on November 28, 2006 10:54 AM:

Hello,

I have a zebra printer connected to the com1 port, i use

the serial port class to send command to the printer but an exception is thrown on the Open method

"The given port name does not start with COM/com or does not resolve to a valid serial port"

Can someone help me please!!!

# Onur Gorgulu said on November 30, 2006 12:12 PM:

Hi friends;

In my program I am calculating a number in Int16 type between 0 and 255, and then I want to send this number to my microcontroller via serial port in 1 byte. for example 139 = 10001011. But the command comport.write(string  s) only accepts string format to send. if I convert byte = 139 to string type and then send, the ascii codes of 1 3 and 9 are going separetly. I want to send the byte as a whole- the Hex equivalent of 139 in one byte. How can I do that? please explain me with useful commands. I am very newbie in this subject but I have a little time to do this project. Please response ASAP. Thanks alot for your help.

Best Regards

Onur

# seval said on December 12, 2006 12:40 PM:

if DataReceived event dos not trigger

try

port.Handshake = System.IO.Ports.Handshake.RequestToSend;

it solved my problem

good luck

# trichloramine said on December 13, 2006 1:25 AM:

My bad. It works.

# zxf92183 said on December 13, 2006 1:41 AM:

hello,

I just use the  sample program from SerialPortTerminal to get data from a machine, it can received data at first time, but if the machine make a new test, and the program can't receive the data any more, after i restart the PC, the program can receive the data again. can someone help me.

thank you.

# Reddie said on December 13, 2006 5:12 PM:

I have the same problem as Matthias, some body already got a solution?

# Reddie said on December 15, 2006 4:19 AM:

@satya_chaitanya pleaze RTFM.

@Matthias on http://www.gotdotnet.com/ there is a serial port project which contains a sendI() function who direct sends a byte to the device. I've try'ed it and it works fine for our purpose.

# Sergey said on December 15, 2006 10:02 AM:

Need send to com1 command "{$04A$03$46}". If send this commant on Terminal - all work. If send command in c# - dont work. Please Help me !

# Reddie said on December 15, 2006 12:01 PM:

@Sergey: something like

byte[] b = {0x4a, 0x03, 0x46};

Serialport.Write(b,0,b.Length);

Is there a possibility to reach the Serialport handle???

# zxf92183 said on December 18, 2006 11:28 PM:

hello,

I just use the  sample program from SerialPortTerminal to get data from a machine, it can received data at first time, but if the machine make a new test, and the program can't receive the data any more, after i restart the PC, the program can receive the data again. can someone help me.

thank you.

# Sergey said on December 19, 2006 1:37 AM:

May be motheboard or servise havs the "Time out" for you port or connect.

# Mark said on December 23, 2006 3:03 AM:

Thank you!! After trying to make sense of MSDN tutorials, I landed here, and let me tell you this is much better. But the SerialCom FAQ.zip can't be accesses... Can you help? Or for the others that were able to access it before, please send it to ltl_piggies@yahoo.com. Thanks much!

# Noah Coad's Code said on December 28, 2006 4:37 PM:

All of us geeks know ways to tweak our PC in various ways, but there are just so many entry points that

# Noah Coad's Code said on December 29, 2006 12:42 PM:

Here's a quick little bit of fun. I was just going through my Netflix rental log, and through ye-old

# Noah Coad's Code said on December 29, 2006 1:12 PM:

These are my top 10 favorite tools. Seams having a top 10 list is popular these days, so here are mine.

# Mr. Spock said on January 2, 2007 11:52 PM:

Mr. Steve Balmer is... highly illogical..

Has there been an escape from the mental ward?

# tesha said on January 5, 2007 12:24 AM:

when i do "port.Open()", it says

UnauthorizedAccessException was unhandled.

Access to the port "COM1" is denied.

Make sure you have sufficient privileges to access this resource

# Muhammad Sajid said on January 10, 2007 10:55 AM:

Hi

Your Project is Excellent in every aspect

I want to use some part of ur code in my industrial project i request for a permission please !!!!!!!!!!!!!

# Ravichandran said on January 11, 2007 9:37 AM:

hi everyone,

i don't  know how to connect usb port in c# 2003,

i can't able to use 2005 because my projects are already developed in 1.1 ,any can help me

thanks

# helpstudent said on January 17, 2007 8:29 AM:

does anyone know how to set StopBits to None ????

I always get a runtime error!

thanks in advance

# coad said on January 19, 2007 11:32 AM:

Ravichandran, This isn't about USB, it's about SerialPort.  You can get a USB to Serial adapter:

http://www.google.com/search?hl=en&q=USB+Serial+Adapter

If you have to use .NET 1.1, you can use info from my old post:

http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320

# coad said on January 19, 2007 11:34 AM:

Muhammad Sajid,

Sure!  Feel free to use any code you find on my blog for any project.  This goes for any and everyone here.

# coad said on January 19, 2007 12:31 PM:

Muhammad Sajid, Ravichandran, tesha, Mark, and others,

I've updated the FAQ section of the post to answer many of your questions, as well as added more support options.  Hope it helps!

FAQ Section: http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#faq  

# Noah Coad said on January 20, 2007 8:50 PM:

Onur Gorgulu,

Try: com.Write(new byte[] { (byte)(new Random().Next(0, 255)) }, 0, 1);

# Traverer said on January 23, 2007 8:52 AM:

Thanks for such resourceful material on c# serial tutorial!

I am just a beginner to c# and serial port programming, after download the SerialPortTerminal.zip and try with TC35i terminal, I discover the reason that causing "my modem not responce to my at command".

It seem to me that the comport.Write method does not send the "\r\n" I type in txtSendData textbox. Thus i add the "\r\n" string to the SendData() function as shown below and it works !!

==================================

  private void SendData()

   {

     if (CurrentDataMode == DataMode.Text)

     {

       // Send the user's text straight out the port

         comport.Write(txtSendData.Text + "\r\n");   // <-- add "\r\n" here

       // Show in the terminal window the user's text

       Log(LogMsgType.Outgoing, txtSendData.Text + "\r\n");   // <-- add "\r\n" here

     }

=====================================

Hope this could help those newbie like me to have a good starting experience in dealling the C# SerialPort and GSM terminal.....

# sth_Weird said on January 25, 2007 4:15 AM:

hello,

thanx for this article, it helps a lot and is much better than anything else I found on the net!

I have a question...

I have two  classes "MyMainClass" (let's call it A to make it shorter...) and "MySerialConnectionClass" (A). A instanciates B and calls function SendToSerial. SendToSerial opens the connection and I add the event. then I send data to the device, and after some time the device is supposed to answer. the problem is that SendToSerial does not wait for this answer. How does the code have to look to make the function wait for the answer? I already tried a while-loop in the function which will only exit if a variable is true, and the variable is set to true by the data-receive event, but it didn't help, if I do that the programm stays in this loop forever. I also tried Application.DoEvents() inside the loop but it doesn't work. Any ideas?

# Noah Coad said on January 27, 2007 11:17 AM:

Traverer,

Thanks for posting this back!  This is a question a lot of people have asked and it's good to see an answer posted.

# Noah Coad said on January 27, 2007 11:20 AM:

sth_Weird,

What you need to do is attach to the SerialPort class' DataRecieved event that will call your code whenever there's incoming data.  See the 2nd block of code on this post, that what it does.  You can create the SerialPort class in your MySerialConnectionClass and put the DataRecieved event code there too.

# Phil said on February 3, 2007 1:21 PM:

Hello,

    I am new to C# and this article has been very informative and helpful in the startup of my serial port coding. I was wondering if anyone knew how to parse the data coming from the serial port. I want to enter the data into 3 textboxs. I've been looking up information on how to do this, but haven't found much. A sample code to startoff would be very helpful. Thanks for your time.

# Jim Mason said on February 9, 2007 6:14 AM:

Thanks to your article titled "Serial Com Simply in C#", I was finally able to communicate with a serial device that I struggled with for quite some time.  I was trying to use old C++ dlls that even though they worked in C++ .NET, they would not work in C#.  Your article saved me!

I learned alot about serial communications in the process too.  I will definitely be studying the info posted on this web site.

Thanks Again.

Best Regards,

Jim

# coad said on February 12, 2007 11:02 PM:

Phil,

There is a sample application that does something simular to this linked to above in the post.

# Georges said on February 13, 2007 2:58 AM:

Hi, i'm trying connecting to aCisco Catalyst 3560, when I use the port.Open(); after setting all the properties, the port.CDHolding is False, so i cannot transmit data to the Serial Port If someone have the same problem.

# balaji said on February 13, 2007 6:04 AM:

sir

ur article is awesome

im incorporating the same concept in my proj

without using interfaces i should get the data from the port connected and

convert it to the form compatible to the cimplicity

software

plz give the suggestion to do that

revert imediately

# balaji said on February 13, 2007 6:06 AM:

my id is balaji_sairam@rediffmail.com

# silibug said on February 13, 2007 9:29 PM:

hi...

your project seems interesting..

can u give us a link of ur schematic design..etcs..

so.. we can build/learn almost like u did...

thanks.. :)

# balaji said on February 14, 2007 7:48 AM:

hi

ill give that tommoro

# Tim said on February 14, 2007 10:29 AM:

When I try to make the example project I get an error. In the file about.cs the System.IO.File.WriteAll method is referenced, but this is not a valid method. The valid ones are listed here:

http://msdn2.microsoft.com/en-us/library/system.io.file_methods.aspx

I'm using C# Express, .Net v2. Anyone else have this problem? I fixed it by changing the call to File.WriteAllText

My previous post on this disappeared......

# altan said on February 14, 2007 4:52 PM:

hi guys

currently i m trying to program PP- 6750 Access Controller

but i only have a vb6.0 source code not the instruction set. the problem is i m writing code in c#. when i investigated the vb6 source code , it seems that it  s too complex and too long approximately 35000 lines! do you think that i can do it in a short way by using c#?

my mail: altantoksoz@myne.com

thanks

# balaji said on February 14, 2007 10:22 PM:

hi folks iam in halfway to finish my project. as i use 1.1 i wrote code on my own i can read the data from the port but unable to write that into a file in csv format. here i can create the file but iam unable to write the data received into the file;

# Gemballa said on February 17, 2007 5:05 AM:

Hi,

I currently programming an atmega168 which is connected to my computer. The communication between the 2 devices works but c# doesnt always take the correct things. For instance if i send with my atmel 123,456,789 (100ms between each number) then my c# application sometimes gets 123,45,78

He just looses some numbers. Is 100ms to fast for a serial port? So that the buffer is full and he cant get any data ? While if i listen to my serial port with hyperterminal i receive all my data correct.

Something weird.

Thanks for helping.

# Karabulut said on February 20, 2007 4:12 AM:

Hi Dear Noah,
Thank you very much Noah! It was a very nice and helpful tutorial for me. I have jumped to C# in Visual Studio 2005 nowadays. But I have a problem with showing the incoming data on my textBox. It works with MessageBox, but not with my textBox. It gives error with my textBox. It gives yellow line and says something like, How to make Cross-Thread Call.... Could you help me?

# Santos said on February 20, 2007 8:44 PM:

Hi I just wanna know if the DataReceived event of SerialPort in C# .Net 2.0 also works in USB to USB?if yes how could I make it work thanks

# Noah Coad's Code : Post 100 - Blog Stats and Post Highlights said on February 21, 2007 11:56 AM:

PingBack from http://blogs.msdn.com/noahc/archive/2007/02/21/post-100-blog-stats-and-post-highlights.aspx

# Noah Coad's Code said on February 21, 2007 1:32 PM:

I was digging around recently and came across an interesting fact... My blog gets more views per month

# Noah Coad's Code said on February 21, 2007 1:34 PM:

I was digging around recently and came across an interesting fact... My blog gets more views per month

# coad said on February 21, 2007 1:43 PM:

Limber,

Yes, it is a syncronous operation.  For my applications (in this case a command line app) I want it to be syncronous.  If it's in a GUI app, it'll delay responsiveness. It is easy to turn it into an asyncronous procedure by using the BackgroundWorker Control, an asyncronous delegate, or the Begin/End async methods of the key calls.

# coad said on February 21, 2007 6:00 PM:

Santos,

See question #6 in the FAQ:

http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#faq

# coad said on February 21, 2007 6:09 PM:

Karabulut,

See question #1 in the FAQ:

http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#faq

# coad said on February 21, 2007 6:11 PM:

Tim,

Perhaps it is deprecated method?  The project still compiles so it shouldn't be too bad.

# coad said on February 21, 2007 6:13 PM:

silibug,

If you buy a Parallax BASIC Stamp starter kit, it comes with schematics and parts to get you started.  http://basicstamp.com

# coad said on February 21, 2007 6:14 PM:

Gemballa,

Keep in mind that data comes in to the serial port's buffer whenever it is avalible and not in nice easy to use packets.  It can be a challange to parse the data correctly to where it appears you have it all.

# Jan Axelson said on February 22, 2007 10:44 AM:

For anyone who would like a look at another .NET SerialPort example, my COM Port Terminal application is available here:

http://www.lvr.com/serport.htm

It includes exception handling, detecting newly attached ports, support for user-selected handshaking/flow control, and more. There are C# and Visual Basic versions.

# karabulut said on February 23, 2007 3:47 AM:

Thanks Noah!

It works now well. This was what I want.

# Noah Coad's Code said on February 23, 2007 12:28 PM:

I was digging around recently and came across an interesting fact... My blog gets more views per month

# balaji said on February 26, 2007 12:35 AM:

hi noah

          i had cached the incoming data from the rs232 port

       into the csv file format.

      now i need to convert this into a cimplicity file format.

      i have explored cimplicity in many ways.

      but cant convert to the cimplicity compatible format.

     Is there any provision for it noah.

     i need to convert the csv file raw data(#12$0$0$0) and so on.

    plz give any suggestion so that i could finish as soon as possible.

   revert immediately anyone

# raghu said on February 28, 2007 9:25 AM:

i am doing a project on railway signalling in vb.net.

my requirement is i have to control or adjust the form designed in my computer from another computer connected through a serial port cable.

to be in detail i have designed a track circuit with some picture boxes and buttons.so i need to change the color of the picture boxes and buttons through xl sheet in another computer by changing the status from 1 to 0 and viceversa.

first i tested for the communication between two systems by writing a chatting application which is working fine but i am not getting the idea to do the main task

please help me out in this

# balaji said on February 28, 2007 10:47 PM:

hi raghu

ur project seems interesting

could u send me the project details and

codes so that i can help you

# raghu said on March 1, 2007 12:51 AM:

hi balaji thanks for offering  me help.

i dont know whether i can send u the whole details but i will try to send to send atleast the main code.

first of all i just want a confirmation whether is it possible to change the status of a programm in one computer with xl sheet or some sought of table in another computer through serial port.

as i said in my previous post, communication between the two systems is possible.in that we can only send and receive text strings.

# Chris said on March 5, 2007 7:00 AM:

Your posts were very helpful.

"Access to the port COM4"  was being denied and I have absolute and total authority over this computer! Simply switching to a different USB, which also changed the name to COM6 worked for me!

# Miguel said on March 5, 2007 12:21 PM:

Hi, i´m from Argentina. This page was very usefull for me to make my modem make a call. Now i want to know how to know when the other side pick up the phone and answer the call i make or when is busy??

this is my simplified code to make a call:

               SerialPort myport = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

               myport.NewLine = "\n";

               myport.DiscardNull = false;

               myport.Handshake = Handshake.XOnXOff;                

               myport.Open();

               myport.Write("atdt xxxx\r"); //xxx phone number

...

 ...

Now, how can i know if is busy o someone answer my call?

Thanks for your support, all of you!!!

# Luke said on March 13, 2007 4:16 PM:

Hello,

Is it possible to develop a code that enables the COM port to send and receive data at the same time (bi-directional communication)? and if the answer is yes, how is it possible to develop such a code?

many thanks.

# coad said on March 14, 2007 12:01 PM:

Miguel,

Does the modem give a signal/command back if it detects a busy signal?  Can you look for this response from the modem?

# coad said on March 14, 2007 12:08 PM:

Luke,

You can think of the send and receive as two completely separate operations.  So you can definitely do "bi-directional" communications, just send data whenever you need to and receive data whenever it comes in.  Whether your device support bi-directional communications is another story entirely and up to the device.

# Luke said on March 14, 2007 2:28 PM:

Well i have created two infrared devices that can send and receive data (using infrared LED to transmitt and Photo detector to receive the data on each device) each device i connected to computer using RS232 in order to do a bi-directional communication between the two computers using the infrared devices that i created. I used hyperterminal to test the devices and they are working except that the letters being received have different symbols than the key pressed! what i am trying to acheive is to use c# in order to send a "hello" word for example from one computer to the other and to make the second computer send an acknowledgement back saying "the word have been received" as an example. So how can i acheive that? is it actually possible?

# ahmed gad said on March 15, 2007 9:47 AM:

hi all

i need one to help me about the interfacing the at89c52 to the pc . i finished the connection of MAX232 AND AT89C52 BUT THE PROBLEM IS HOW TO INRTERFAC PC TO IT.i think that i must have vesual basic software in my pc  i thik that,

but i dont have it.

please help me

thanks all

# zafar said on March 16, 2007 9:07 AM:

hi.

its nice to see such competent people on net.

but i am still not satisfied bcz my requirements are still not fulfilled.bcz i wants to have input from my 8051 uc  and process that data in c++ programme.for example if i press a button on keypad of uc then pc should show a message well come if i press any other button it sholud say good bye

.or ican do numeriacel calcualtion.so kindly guide me.my email is

soheel_657@yahoo.coml

# Saeed said on March 17, 2007 1:38 AM:

Hi Miguel and All:

First of all thanks for such a nice article. Secondly i want to dial my ISP to connect to internet using Modem on Serial Port...

Miguel i think u have worked on this.. can u give me some more help

Waiting ,

n thanks once more..

SAEED

# oliver456 said on March 19, 2007 6:57 AM:

hi all

 very nice article!

 I have a problem , a serialPort is in use by an another application , I want to  monitor its data ,how can I do that

thanks

# Miguel said on March 19, 2007 7:50 AM:

Saeed, i´ve been in vacations. First i have to check something that coad askme about my problem. In your question, i don´t understand very well what you want to do, but the code i write up in the post works very fine to dial any number you want. I´m using VS2005 with Serv Pack and a internal modem on my notebook. I recommend you to use the static method: string[] myPorts = SerialPort.GetPortNames(); so you can see what aviable ports your pc have. Then you can use my code post up here to make your modem dial a phone number. I think that if you want to handle the internet connection you will have to use the

void myport_DataReceived(object sender, SerialDataReceivedEventArgs e) method to handle what you want. The code up load by Coad is very help full. Just remember to make phone call via the modem you have to use AT commands and have all your connection cables set well (i mean the line cables with the modem). my mail is: miguelb_fiuba2@hotmail.com bye and thank every one for all the post.

# ghalip said on March 21, 2007 5:48 AM:

now i face to the problem that ..

when i change the baund rate from 38400 to 9600 and begin initialize the port (serial port sp1;)it dosn't work?

why?

# Noah Coad's Code said on March 25, 2007 11:20 PM:

HTML Applications (HTAs) are DHTML pages that have full local privileges. They've been around for a long

# mark said on March 28, 2007 10:40 AM:

the device manager on my laptop doesn't show any serial ports, but getportnames() returns "com3". what does that mean?

# JohnH said on March 29, 2007 8:11 AM:

mark, com3 could just be the port used by an internal modem. You can check your modem properties to be sure.

# JohnH said on March 29, 2007 8:21 AM:

Has anyone managed to get the SerialPort class to work using redirected com ports on a Remote Desktop Connection?

I'm running the SerialPortTerminal example app on the server (using RDC to connect to the server) and trying to send/receive data through the client PC's com port.

Sending data to the client port seems to work okay but no data is received. I know MSComm (VB6) had problems with Remote Desktop but I was hoping that framework 2.0 serial driver would do the job.

# Good said on March 30, 2007 6:19 AM:

Hi Noah, first of all thanks for this tutorial, it's very useful for me, a newbie of C#.NET.

I've encountered some problems with serial port communications between PC and a reader, hopefully can get some help from you.

I just wrote a simple program to send a byte array from PC to reader and the reader will send back another byte array to the PC. here is the code:

private void button1_Click(object sender, EventArgs e)

       {

           open_serialPort1();

           byte[] data = new byte[7];

           serialPort1.Write(addCheckSum(resetReader), 0, 4);

           serialPort1.Read(data, 0, data.Length);

           close_serialPort1();

           string str = BitConverter.ToString(data);

           richTextBox1.Text = str;

       }

When I first time press the button1, the reader can receive the byte array correctly from the PC and the PC also can receive the data which is sent back by the reader, everything is correct.

But when i press again the button1, only the reader can receive the data from PC, but PC cannot receive any data from reader, the richTextBox1 showing 7 bytes of 00.

Can you pls help me to figure out the problem, is there anything wrong with my program?

# william chang said on March 30, 2007 11:31 PM:

Dear Noah:

          It is william from A&M, long time no see, how are you??? you wedding photo is beautiful! Congratulations! my email is pillow_chang@yahoo.com, please let's keep in contact!

# ... said on March 31, 2007 2:02 AM:

Du musst ein Fachmann sein - wirklich guter Aufstellungsort, den du hast!

# jithen said on April 13, 2007 8:54 AM:

Hi im trying to get my c#.net app to work the problem is that when using

SerialDataReceivedEventArgs it echos all bytes/strings that is sent to the

port. If I send the AT command it always echos the AT and OK I just want it

to echo the OK.

# SWAPNIL M GHOLAP said on April 15, 2007 8:35 AM:

RESPECTED SIR ,

    I AM STUDENT OF THIRD YEAR,STUDYING IN INSTRUMENTATION AND CONTROL ENG.

SIR,I AM DOING PROJECT, IN WHICH I WANT TO READ THE SIGNAL FROM COM PORT1 THROUGH RS232 PARALLEL(DB25)AND THEN WITH RESPECT TO TIME,I WANT TO DISPLAY GRAPH ON VISUAL BASIC 6.0 SOFTWARE.

    I WANT CODE IN VB,WHICH WILL DISPLAY THE GRAPH WHEN THE INPUT WILL CHANGE,GRAPH ALSO CHANGE FROM RS232(DB25). I HOPE U WILL DEFINEATELY SOLVE MY PROBLEM.I AM WAITING

FOR UR RESPONSE TILL WEDNESDAY.

# wiwi develop said on April 16, 2007 7:10 PM:

i need some help i have a bluetooth printer and send the string to the port COM9 example puerto.WriteLine("something");

but a need send to the printer code for barcodes is send it by hexadecimal code o how?

# Ngoc Lan said on April 19, 2007 1:53 AM:

Pls help me!

I am learning programing for Serial Port in C# and I have encountered  a problem. I don't understand why SerialPort.Write method don't act. I used that method , but I didn't receive data from the port.

Pls show the reason!

# David Howell said on April 29, 2007 2:41 PM:

Thanks for the useful post on serialport. I am making a program for reading numbers and a newline trigger from serial connected balances.

Just a note on your SerialPortTerminal program. There seems to be no System.IO.File.Writeall method anymore, and I think .WriteAllText is what you need there.

I get the part about setting a buffer and reading it and writing it, but how do I write it to any active field on screen? I don't want to write to file or console, but rather to an information management system that can take key entries. Somewhat like a keyboard wedge.

# kranthi said on April 30, 2007 5:42 AM:

am kranthi

am working a project in small company

am fresher so please give me code about my problem.

what am saying my sir one modem(that is one type of modem) connected to com1 port(serial port) in my pc.

am using .net 1.1 with c#.net , so i will created one form.

am used one text box and one button in that form ,

we will type some message in that textbox and click button.

how will send that messge to one any mobile number through comport settings(serial port).

please give me that code.please u can solve my problem.

# girija said on May 2, 2007 2:10 AM:

how will know the receiver is availabel or not?

we sended the data to receiver but that is availlabel or not how will know.that is not availabel how much time will wait and how will display receiver not found.

# girijapakala said on May 2, 2007 2:13 AM:

we send the data to reciver but that is not found how much time wait and how will display receiver not found message

please tell that anwser

# Carmelo said on May 3, 2007 4:09 AM:

Thank you very much for the code...if I could ever return the favour feel free.  Recieving serial was not as straightforward as sending.

But using invoke and the way you've demonstrated has really really help...cant thank you enough.

# Dean said on May 4, 2007 9:03 AM:

I used this code as a starting point for interacting with an old barcode scanner that connected via RS232.  Only real thing to add to what can be found here is that I needed to set RtsEnable to TRUE in order to receive data, otherwise the scanner just hung.

Oh, and if anyone's looking for info on a Handheld Products (formerly Welch Allyn) 3400 scanner, don't believe the defaults given in the user guide - it's 9600 baud, 8 data, 2 stop and no parity!  ;-)

# Yasser said on May 7, 2007 11:15 PM:

Hi, Folks,

Can anyone help me with next probem

I have notebook with 1 Com (rs232) port.

On this laptop also have modem and infrared device.

I d'like to create from modem or infrared another COM rs232 port, So bi visible under pure dos withouth any drivers.

Some of programs under dosr does not working when using PCMCIA - rs232 ot USB - rs232 adapters.

Best regards

Yasser

# Syntax76 said on May 8, 2007 6:30 AM:

Thanks for the great site. Intresting thing was i was looking for a tutorial for SerialPort, since my try went somehow wrong (i thought).

Im experimenting with serial communication between BASIC Stamp (BS2 for now) and PC; i already found the SerialPort class in .NET and was really glad for that. Unfortunatly the DataReceived event handler  isn't willing to work, neither at my code nor at yours (SerialPortTerminal) ; when using e.g.  PuTTY it displays my data sent.

I tried both in PBASIC: SEROUT and DEBUG

SEROUT 16, $4054, ["100 GET", 13]

as well as

DEBUG "100 GET", 13

(of course both are equal, but you never know...)

that sending both ways works is, as written, visible in PuTTY

in all 3 testing apps (my, yours and PuTTY) the serial settings were the same (9600 baud, 8 bit, 1 stopbit, no parity, no flow control)

and the .NET apps don't even jump into the event-handler (it never stops at the breakpoint inside).

Maybe you have a hint for me?

Best regards

Syntax76

# Syntax76 said on May 8, 2007 6:35 AM:

oh yes, to mention:

i use Win XP x64 may be this is the reason? But in the docs for this class is explicitly written, that it works under XP x64...

# Clement said on May 9, 2007 4:55 PM:

I get an "Access to the port 'COM1' is denied" when I run the GUI version of my C# program, but when I run the console equivalent, I don't get the error and everything works perfectly.

I did the testing with the console and put the cs file in the other project, renaming the namespace of course. Why is that? I don't have a similiar problems with the other COM ports, but I need to use COM1 since the others are taken.

# Noah Coad's Code said on May 9, 2007 8:23 PM:

Download ShellExec ( source code ) Here's a really simple but surprisingly useful little tool. It performs

# Ryan Dutton said on May 10, 2007 10:09 AM:

I had the "UnauthorizedAccessException" error.  It turned out that running the application from a mapped network drive was the problem.  If you have this issue, ensure its running from your C: drive and see what happens.

# Clement said on May 15, 2007 3:08 PM:

I do run it from the C drive. I think there is a problem with using the serial port in other forms other than the main form. If I put the code in the main form, it works fine.

Whatever works. LOL.

# Surya said on May 16, 2007 8:18 AM:

Hi,

I am sending data in bytes over serial port using .net 2.0.

problem is I am not getting the response from the device.

# behkian said on May 20, 2007 4:50 AM:

Hi I have writen apog by using MSCOMM.ocx in vc++.net(windows application form) but I can not get numbers more than 127

if u can help me about this my prog must get this valuse and put them in thier text boxex and thier showers and I 'm getting data from 3 ports at one time .

if i can't use mscomm in vc++.net please guide me to use serial port component

thanks a lot

# *** said on May 23, 2007 12:23 AM:

This is Bullshit.

# Michae said on May 24, 2007 7:17 AM:

Hello their developers..  can you help me with my problem... i'm using a foot pedal device and i want to read the data it sends, so i use the serial port in VS2005 but i dont know what code for it to recieve the data from the foot pedal??... can anyone help me.. pls

# Surender Rawat said on May 25, 2007 2:02 AM:

Hello all developers

i have to develop an application in dot net which communicate with a infrared sensor which count the number of people passing away from. there is need of serial communication.

Dot net know how to start of it.

How to detectet by the application whether device is connected or net, how to receive and sent data.

# Joesy said on June 1, 2007 5:36 AM:

Hey,

I found your article which is an execellent one. I implemented okie but I got problem with receiving reply message:

In order to receive reply, I changed a little bit in your send button event:

port.RtsEnable = true;

SendData();

port.RtsEnable = false;

But with the same command send, I received diffrent reply messages:

<<< Sent: 02 30 D0 31 30 30 31 30 30 30 52 03

>>> Received: 60 83 06 AF 4C 36 56 76 0C 00

<<< Sent: 02 30 D0 31 30 30 31 30 30 30 52 03

>>> Received: 60 E8 15 32 33 35 17 00 00

Could you please help me? I uploaded my code here: download.yousendit.com/BEF9777251C1D8EF

This is very urgent project of mine, Can you please spend some time to help me? Could I have your email, I will contact you?

Thank you very much,

Joesy

# Jun said on June 3, 2007 1:45 AM:

I need to to simultaneously open and use 8 Comport!

Hello there,

Im communicating with 8 serial devices (Atmel 89S52 microcontroller) using usb2RS232 adapter connected in usb hub. Enumerated port are Com1 to Com8.

In order to send and receive data, i have to open and close each comport and sequently move to next comport.

I can exchanged data to and from serial devices however most of the time it throw an exception  " access denied to Comx". And eventualy my application would hang up.

I figure its hard to close and dispose serial port resources in moving from i.e. Com3 to another Com4.

Even I give enough time to Close the comport using timer.

I would like to Open and Use 8 Comport (Com1 to Com8) simultaneously.

I would deeply appreciate any hints, clue, HELP from anyone!

Jun

# Joesy said on June 4, 2007 8:38 AM:

I got a probem when event fires: DataReceived:

Frame: The hardware detected a framing error.

Can you help me to explain about this error: When, how and where this error ocurrs?

Thanks,

Joesy

# JD said on June 5, 2007 3:35 PM:

Hi,

I'm working a project using audio data gathered with a mic, using C# and DirectSound, that I'm trying to send to a device via serial, however because I'm so new to this, I cant get the audio to stream.  I can send files already recorded, but the goal is a "live" transmission of sorts.

Can anyone possibly help me?  

I'm new to C# (like 5 or 6 days new...), so code with an explanation would be a great big help!  Thanks!

JD

# Rashmi said on June 6, 2007 7:04 AM:

Finally you helped me out

# tfgdfg said on June 6, 2007 8:04 AM:

heyyyyyyyyyy

# Broionni said on June 6, 2007 8:04 AM:

your gheyy

# Phillipe said on June 7, 2007 3:37 AM:

Hey Everybody! i think this is a little more complicated but maybe someone could help me, am working on a PIC - 18F258, i am sending data between the PIC and the program that Noah created, but every time my PIC send data it only appear 3F for every hex that my pic send, the weird thing is when i test the pic with terminal v1.09 because it works perfect, every hex that my pic send appear on terminal but can't do this with the program in c#, could someone give me some help? plz........... my e-mai is pcasorla124@gmail.com

# Abebe said on June 8, 2007 2:48 PM:

Currently I am doing my final year project  and I came across Serial C# interfacing . I want to generate 40khz,50% duty ctcle square wave. Can any one help me PLZ?

# kiwi said on June 10, 2007 10:20 PM:

hi guys.. i need to read tags using rfid reader. the reader is connected to the computer using serial port. can anyone advise me the codes for receving the tags data?

thanks

# kiwi said on June 10, 2007 10:25 PM:

hi guys.. i need to read tags using rfid reader. the reader is connected to the computer using serial port. can anyone advise me the codes for receving the tags data? i'm using microsoft visual studio 2005.

thanks. your help is appreciated.

# andrew said on June 13, 2007 5:53 AM:

hi just wondered if you had ever tried coding to something like this

www.mp3car.com/.../102176-need-advice-obd-c-net-app.html

it connecting to a cars computer

andrew

# dan said on June 14, 2007 9:48 AM:

upon receiving properly formatted data according to a given protocol, i need to send back an ACK message within 2ms. is there any way this is possible using the SerialPort class? or is this only possible with drivers? i would really like to keep my implementation as simple and high-level as possible. i really don't want to have to write a driver to do this.

any suggestions?

# vishnu said on June 19, 2007 12:38 AM:

Hi Noah,

Great article..... it help me lots of think........

keep it up......

Cheers........!

# Chris said on June 20, 2007 9:39 AM:

Thanks for sharing your great info - I have a VS2005 .Net2.0 app which is reading a Truck Scale.  It works great with 1 huge exception - the datareceived event is not firing soon enough.  I am running a port monitor along with my application and realize my application lags about 20 lines (roughly 12 characters each line) behind the actual data being read in the port.  Is there a way to speed the datareceived event to trigger faster?  Each line being received from the scale ends with a CRLF.  Thanks for your help!!!

# Miguel said on July 4, 2007 4:56 AM:

Thanks a lot for this article.

# kumaran said on July 5, 2007 4:35 AM:

Can anyonr guide me on writing barcode scanner(PT2000 TopGun) program. Just to download data from it

# Miha said on July 6, 2007 8:44 AM:

Hello, I am new to Serial Port Programming. Liked your article. I have bought two usb to com adapters and gender changer (is this the same stuff as null modem adapter?). I setup everything, and I now have COM3 and COM4 ports (USB2COM adapters). If i programaticaly send writeline on com3 port the light on the port blinks. My question is how to loopback these two connections, so I can test software with it.... I think the problem is, that  do not have null modem adapter. Please if anyone has any ideas and comments please, let me know. Thanks!

# hussein said on July 6, 2007 10:21 AM:

Thanks for the great sample. I have one issue, I used the code provided to lsiten to a port that has a card reader attached to it, I am receiving the data in the receive event but it gets split, so i receive part of the message and then receive the rest. Your assistance is much appreciated.

# Miha said on July 6, 2007 11:02 AM:

OK, I have resolved my issue. I've created Loopback adapter and connected it to USB2COM cable and stuff now works!!!

Here is how to connect pins to create loopback adapter.

www.passmark.com/.../loopback.htm

#   Несколько советов по работе с командной строкой Windows by Lifehacker said on July 8, 2007 11:16 PM:

Pingback from  &nbsp; Несколько советов по работе с командной строкой Windows&nbsp;by&nbsp;Lifehacker

# logki said on July 9, 2007 1:29 PM:

Hi I am trying to write to a serial port  using a protocol which looks like this

<address> <length> <commd> < data ><checksum>

and heres is how i am writing it

public void SendDatathruPort(int addr, int length, int comd, int checksum)

       {

           byte[] data7 = new byte[17];

           //byte[] data1 = datainuput();

int totalsum = data7[0] + data7[1] + data7[2] + data7[3] + data7[4] + data7[5] + data7Devil + data7[7] + data7Music + data7Music + data7[9] + data7[10] + data7[11] + data7[12] + data7[13] + data7[14] + data7[15];

           checksum = (totalsum) & (0xFF);

           data7[0] = (byte)addr;

           data7[1] = (byte)length;

           data7[2] = (byte)comd;

           data7[3] = Convert.ToByte("1");

           data7[4] = Convert.ToByte(txBxP1.Text);

           data7[5] = Convert.ToByte(txBxP2.Text);

           data7Devil = Convert.ToByte(txBxP3.Text);

           data7[7] = Convert.ToByte(txBxP4.Text);

           data7Music = Convert.ToByte(txBxP5.Text);

           data7[9] = Convert.ToByte(txBxP6.Text);

           data7[10] = Convert.ToByte(txBxP7.Text);

           data7[11] = Convert.ToByte(txBxP8.Text);

           data7[12] = Convert.ToByte(txBxP9.Text);

           data7[13] = Convert.ToByte(txBxP10.Text);

           data7[14] = Convert.ToByte(txBxP11.Text);

           data7[15] = Convert.ToByte(txBxP12.Text);

           data7[16] = (byte)checksum;

           comport.Write(data7, 0, data7.Length);  

       }

and this is how i call it

private void setvalue_Click(object sender, EventArgs e)

       {

           // Send the user's text straight out the port

           //comport.Write(txtSendData.Text)

           //SendData();

           SendDatathruPort(0x7B, 14,0x0A,0);

       }

# logki said on July 9, 2007 1:30 PM:

When I set the values it doesnt seem to be seeting the values on the controller ,... any help is appreciated

# ahmad said on July 10, 2007 2:04 AM:

hi;

Is there any way for me to use my .net 2 .exe aplication in other PCs (or platforms) which has not .net frame work?

regards

# Geoff said on July 12, 2007 7:28 AM:

Hi Noah and all

This is a very useful page and has helped me greatly.

As a matter of interest has anyone had issues with

SerialErrorReceivedEventHandler on a windows XP pro

SP2 laptop using USB serial converters?.

My code displays framing and parity errors ,but will not

generate any events using USB on XP.

A PCMCIA serial card port on the same laptop works fine.

The same code also works well on Win 2k pro using either PCI or USB ports.

Best Regards

Geoff

# Jan said on July 18, 2007 3:53 AM:

At a glance, the example at msdn2.microsoft.com/.../t8t5yhhk.aspx seems to provide the similar functionality

# Rafael said on July 19, 2007 5:41 PM:

I' am trying to control a power suply using RS-232 interface

But the power suply has a frame of 26 bytes

I am newbie and I just now hot to send strings through serial port, not how to sent bytes,

Please help me

rac28_03@hotmail.com

# Georgi said on July 20, 2007 1:51 PM:

Hi,

I need to read binary data from comp port on C#, do I can use

byte[] signal;

signal = new byte[5000];

port.Read(signal, 0, 500);

And how to be able to read binary frames?

# Georgi said on July 20, 2007 1:51 PM:

very interesting article

gwtt@abv.bg

# Chris said on July 22, 2007 3:34 PM:

Hey Guys,

I can get a list of com ports in use to print out to the command window but i would like more information than just "com1, com2" i would like to see for example  "com1 Max Stream UVG, com2 4G cruiser mini" get my drift?

Any one have an idea how to do that?

Thanks!!!

# Jones said on July 26, 2007 5:20 AM:

Hey nice site!

Am currently doing a project with CS and USB to UART controller (Virtual COM port), my aim at the moment is to be able to write a string of data from one from COM1 port to COM3, then get a reply back acknowledging reciept.

what have done so far is use some "if and else if" statment in my OUTPUT  box (textbox)  so that if the input we require is inside the textbox, we get a reply in the other COM port saying recieved.

This works fine, BUT AFTER RECIEVEING THE 1ST TEXT, I CAN'T READ NEW TEXT INPUT, BECAUSE MY READ COMMAND READS ALL THE TEXT IN THE OUTPUT TEXTBOX, I HAVE TRIED READLINE, IT DOESNT WORK NEITHER.

Can someone advise on what method i can call to read new string from my output textbox rather that reading everything, and also how can i go to a new line automatically inside a text box. (this doesnt work \r\n)

if (this.txtData.Text == "Hello")

           {

               serialPort1.WriteLine("recieved\r\n");

                           }

           else if (this.txtData.Text == "Hiya")

           {                

               serialPort1.WriteLine("hey");

           }

so what am saying is that "Hello" goes into the output text box and "Recieved" is printed out, but when "Hiya" goes into the same output box, the readExisting() or readLine() method reads everything inside the text box and doesnt print/writes out "Hey"

Please help if you can!

Regards

Jones

# mina said on July 31, 2007 2:16 AM:

hi.what i can connect 2 pc whit port usb whit c#?

# mina said on July 31, 2007 3:15 AM:

hi

what i can connect 2 pc whit port usb?

i need code c#!

please help me!!

# junied said on August 1, 2007 2:18 PM:

Excellent artical

i was searching for serial communication example using .net2005 v2

but this was the best

# Adrian said on August 2, 2007 7:29 AM:

Nice article.

May you help me with a question?

Can i set DTR value? I need this signal to reset a PIC mcu.

# Martin Lee said on August 10, 2007 9:10 PM:

Become a more intelligent investor. Learn the value investing strategies of Warren Buffett as well as that of his mentor, Benjamin Graham.

# YZ said on August 16, 2007 5:06 PM:

I  can get SerialDataReceivedEventHandler to work if I send a command to a serial device in a timer or click botton event. However, if I use a while-loop to continue send comands with a Thread.Sleep(1000) in between, the receive event does not even fire once. Why cannot I use while-loop in this case?

I would greatly appeciate your help.

# krishna said on August 18, 2007 1:09 AM:

i want connect foot padel through comm port.

if pin change then how to call pin change event ?

# krishna said on August 20, 2007 7:34 AM:

if i change comm port pin then auto working as foot padel for use in wav file.

how to work

send me

krishna551@gmail.com

# hassan said on August 24, 2007 2:53 PM:

hi i want make a dailing with modem with c# code but i dont what work i must to do please help me thanks

# Steve M said on August 27, 2007 5:54 AM:

That's really  a smart and quick sloution for video conferencing, without much efforts and time.

www.sony-conferencing.com

# vissu said on August 28, 2007 12:04 AM:

HI i am also trying the same thing with vs.net 2005.

what i am looking for?

I am having a weighting scale which will give lt/wt/depth/hgt etc.

I am a system with .net 2005

using RS 232 cable i am trying to get those data from scale to my application.

for that using serialport class i am configuring the com and then i am taking the data from scale.

Problem facing:

step1: In my .net windows applcation i click an Activate button.In this i had written a code

a.send a request to scale

b.sclae will send an acknowledgement as * to my application.

c.then user will keep an weight in scale and click print button in device.

d. In my application i kept a message button which user can peform above step.

e. then i am getting the bytes of data to my application and am storing thta information into my database.

Now problem is

In 2nd time if user has kept another weight in scale and user click a print button then its not getting that data. Even i kept a while(True) loop.

How can i achieve this in my application.

is there any way to achieve that 2nd, 3rd ... data from scale with out restarting comport repeatedly.

if u had give code it will be very helpful to me.

# sam said on September 6, 2007 10:35 AM:

Hi, I am using VS 2005 and have a Thermal Printer connected to COM1.  I am trying to sniff text being send to the printer but every time I try to open COM1 it will give me the following exception:

{"The given port name does not start with COM/com or does not resolve to a valid serial port.\r\nParameter name: portName"}

My printer is plugged in and turned on, the driver is installed... I'm not sure how to get rid of the exception.  

Thanks for anyone's help in advance!

# sundar said on September 8, 2007 9:53 AM:

Hi,

How to send and receive data from com1(port)?

any dll files add   to the port  access?

can you replay clearly?

Many thanks s s s s s  s s s s sssssssssssssssss

# jenny said on September 9, 2007 9:03 PM:

Hi, I would like to ask the same question as Haluk.

I am running the serialport transmitting program very fine in computer which using english language for non-unicode, and also standard and format, but when I change them to Chinese PRC, I got problem to send unicode 192.

I am using VB .net,

Dim buff() As Byte

       Dim i As Integer

       If SerialPort1.IsOpen Then

           ReDim buff(2)

           buff(0) = 192

           buff(1) = 80

           buff(2) = 192    

           SerialPort1.Write(buff, i, 3)

       End If

when I tried to capture with hyperterminal, i will get 192 192 80. Why this happend, and how to solve?

I really hope you can help me.. Thanks

# Bijay said on September 10, 2007 11:22 AM:

Works like a  charm . Thanks

# ali said on September 11, 2007 3:03 AM:

hi

I write a Pocket PC program with c# and use it's serial port to communicate with my device. I have a problem with serial port. I defined a "static" class for serial port

communication. I have several form and used serial

class in most of them. When I run program, for firs time

I can connect via serial port. after first communication

I never can send or transmit data with serial port.

I checked serial port to be open. It open but do not response.

# rajini said on September 17, 2007 4:42 AM:

hey all,

i need to receive a file from pos terminal to system in vb.net any body can help me........

# rajesh patel said on September 19, 2007 2:09 AM:

Hi

 i need add swipecard device into my project (asp.net c#) so which step i follow for this task pls help

# Ajay Khatri said on September 19, 2007 11:59 PM:

very nice ...............!!!!!

# David Amyotte said on October 1, 2007 10:53 AM:

Hello,

I have a question about programming in C# and .net 2.0 with serial ports..

I'm writing an application to read data from a micro controller. I know the data array the controller spits back is 24 bytes.

I used the bytethreshold property and set it to 24. What the program does it sends a hex 93 command and its spits back data. Problem is when I started using the bytethreshold property and if I hit the send command for  a second time the data in the array comes back isnt in the order it should be.

The reason why i used the bytethreshold property is to prevent the datarecieved event from firing until I have all the data in the buffer then I can store the data in my byte buffer.

What is the issue? Should I be clearing my buffer after each send command?

# Darshan said on October 4, 2007 1:29 PM:

Hey I was just wondering if there was away around opening COM ports (more than one app).  Thanks

# cute-solutions said on October 9, 2007 6:58 AM:

very nice tutorial!!

# Rodrigo Silva said on October 9, 2007 11:48 AM:

Dear,    

the application usually works, when I open first in the hyperterminal and closed.    

Else makes this procedure the application doesn't work.    

Did anybody already go by this problem?    

I am using C #. Net 2.0    

Thanks

# Stefan Matokic said on October 12, 2007 4:51 AM:

hello,

i've got a problem with comports, too. i need a way to close a opened comport in c# after the device on it already were turned of. it's not enough for me just to catch the exceptions, for regulare it would be myPort.Close(); but if the device is missed at the comport you'll recive a unauthorizedaccess exception.

someone an idea?

i would be very happy about some ideas --> stefan(at)matokic.de

thanks...

# krishna said on October 12, 2007 5:07 AM:

i have connect comm port and also call pinchange event but does not able to connect DataReceiveEvent.

so pls help code how to connect .

krishna551@gmail.com

thanks

# german said on October 12, 2007 1:20 PM:

hi i'm working  with serialport1 and i send to an aplication in C#  10 bytes and the aplicacion receive just 8 byte always, my buffer rx is of 20 bytes, what is wrong

this is reception

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

       {

          int total = serialPort1.BytesToRead;// here always read 8 just bytes and bufer_rx is a20 bytes

           serialPort1.Read(bufer_rx, 0, total);

# NloGoloMRaR // Yuhn said on October 13, 2007 3:22 AM:

Hi German ... Check this out

Just put in a Thread.Sleep(250); in the start of the method, then it haves time to read all the incomming date in the buffer before empty it.

private void port_DataReceived(Object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

       {

           Thread.Sleep(250);

           int total = sp.BytesToRead  

           buffer_rx = new char[total];

           sp.Read(buffer_rx, 0, total);

           for (int i = 0; i < buffer_rx.Length; i++)

           {

               sB.Append(buffer_rxIdea.ToString());

           }

           MessageBox.Show(sB.ToString());

           sB.Remove(0, sB.Length); //sB is a StringBuilder

       }

# Martin Lee said on October 15, 2007 9:44 PM:

Learn Strategies and Tips for Making Money Online Using Affiliate Marketing.

# paper said on October 18, 2007 11:44 PM:

hi,

I need help in a serialport communication program. i will have 2 form. form1 and form2, form1 will allow user to select their comport, baudrate,parity etc in a combobox. when i click ok, a connection should be establish in order for me to run form2. i have no idea how i shd write it, therefore i need some help here.

# Randy Douglas said on October 19, 2007 12:29 AM:

Ashley nailed the problem for me here: "Setting DTR to enabled and handshaking to hardware should power the pin that manufacturers use for power robbing as well. "

I added "comport.DtrEnable = true;" and that solved my DataReceived problem where it would output the result after passing an AT command to my ISU to send SMS messages.

Thanks Ash ;-)

# Moki said on October 19, 2007 9:10 AM:

The code snippet is very handy. Thanks for posting!

# german said on October 19, 2007 1:50 PM:

hi Yuhn

thank you, it's working fine

# german said on October 19, 2007 1:52 PM:

hi Yuhn, thank you it's working fine

# K Naib said on October 26, 2007 3:43 PM:

Information, history, buying advice and industry news on various famous watch brands including Accurist, Rotary, Citizen, Tissot, Sekonda, Police, Guess and more.

# mohsen said on October 29, 2007 3:22 PM:

hi

i want to make mens that cheng USB to com

please send for me shematic and file hex about it.

thank

# Meme Team · S2MIDI: Open Source Serial to MIDI Converter for Windows said on November 7, 2007 2:43 PM:

Pingback from  Meme Team  &middot;  S2MIDI: Open Source Serial to MIDI Converter for Windows

# Kai said on November 15, 2007 10:51 PM:

Hi mister, i doing my final year project which will link up to a solar panel to accuqire the voltage reading , it will go through the analog to digital conversion , so the signal( voltage reading becomes digital) , it will then send to a wireless transmitter , and send to the receiver which will then be interface to the computer thru rs232 to usb converter to comp.

currently i using C# , do u have any sample program to plot graph of the voltage reading against time ?, and since the voltage reading from solar panel varies, do i need a timer or so ? thanks alot for your kind attention , i using visual studio 2005

# kai said on November 15, 2007 10:53 PM:

my email is rawdy_502@hotmail.com if u need to send me any sample data thanks alot...

# Sri said on November 16, 2007 5:30 AM:

Hi,

       I Have to Pass ctrl + D thru my Serial Port Connection Can any body say how is it possible, bit urgent pls

# Vibhor Goswami said on November 18, 2007 11:56 PM:

Hi!

I'm using C# to create an interface between my card reader and my PC. I usually got Access denied but when i booted the system without my device connected to it, the error didn't appear when i run the program. Is there any way to prevent windows from accessing the 'COM1'? i also require some help to further communicate with my card reader as my establishment with the reader is done using methods from its dll but the reader doesn't respod. Pls guide me in some direction on how to proceed further? Any help is appreciated.

# Thai Do said on November 19, 2007 2:47 PM:

Hello Noah,

Is it possible to access a remote com port using c#, a com port that is on another computer?

# seph said on November 22, 2007 2:49 PM:

msdn says:

PinChanged, DataReceived, and ErrorReceived events may be called out of order, and there may be a slight delay between when the underlying stream reports the error and when the event handler is executed. Only one event handler can execute at a time.

quote

Only one event handler can execute at a time...

does this mean that if a 1st serialport event is executing and have not  yet returned while a second event fires.. the second event is lost to oblivion...

I've setup a microcontroller to send 2 parity errors but only one error receive event fires..

also is the pinchange event can only fire in the breakstate i.e. when the port is not sending and receiving..

# Jason Green said on November 27, 2007 1:15 AM:

If you become a subscriber to Site Salary you will also be presented with exclusive tips and advice on monetizing your website.

# Anil said on November 28, 2007 11:25 PM:

I want to send Ctrl+A on serial port....How can I send the Ctrl+A... Please help me... Its very urgent.

Anil

# bahar said on December 3, 2007 2:06 AM:

Hi

  I want to use Image scanner in my project with c#.net.

so how can I send and recieve data to/from image scanner with c#.net

thanks

# amy said on December 4, 2007 2:14 AM:

OH COOL! :) thanks! :) steve

# Jonathan Vanpeteghem said on December 4, 2007 5:19 AM:

Great tool! I used it to communicate with the pic 16f877 and it worked perfectly on the first time. I will add some exception handling, for when the pic does not reply to the pc ;-)

Thanks!

# Manoj said on December 11, 2007 10:17 AM:

Hi I am using this

string st = serialPort1.ReadExisting();

int j =recievedB.ToString().Length();

I am using .NET 2.0 serialPort() class and ReadExisting method. I am interested in getting value not length. How do I do that. Thanks in advance.

# Taiyeb ali said on December 12, 2007 2:42 AM:

Sir, i am desinging fapplication in asp.net in which i wnat to use a port to send sms by that port to attach mobile with that port

please help i am not getting port response

# prem said on December 16, 2007 11:55 PM:

Hi

iam working on one application, using my app i should read data from device using com, i know how to read data from port.

my question is how to identify/ scan the port(com1 or com2,,etc)? is any specfic way is there.

plz help me on this.

Thanks

# tester said on December 17, 2007 4:33 AM:

hi, i'll test this applikation, will send you my solutions

# vijay said on December 19, 2007 6:11 AM:

the value of ctrl+A can be sent as (char)1,ctrl+b as (char)2 ..............ctrl+z value as (char)26

# harpal said on December 21, 2007 4:44 AM:

hi coad,

            i am trying to fire an at command on a device using your serial port tools but device si not reponds to these commands...........

# shraddha said on December 24, 2007 11:48 PM:

hey i want to connect foot pedal for player with the use of Asp.Net 2005 with C#.... online...

Can you guide me How it will bw possible?

# Yos said on January 3, 2008 11:21 AM:

Hi

I have 3 serial devices. Should I use 3 hreads to handle each incoming com port? is there any way to handle this issue with one thread/function, how?

Thank You

# senthil said on January 4, 2008 7:38 AM:

Hi,

when i send AT command to my modem it is not responding. In hyperterminal AT commands work fine, i was able to send SMS using it. When i use AT command in C# 2.0  there is no reponse from the modem. Modem is in the server, i have created the application in my server and running it from my local machine. Please help

# monica said on January 8, 2008 9:34 PM:

hi, I am using visual C# 2008 express edition and the code i found in this page does not compile, and it does not seem to be able to be converted either.

# 4DOS said on January 8, 2008 10:44 PM:

I started using 4DOS(for Win 3.x, 95 & 98) 10 years ago. Then 4NT.  Still use it at work/home everyday.  Simply the best.

# fall bridal shower favors said on January 8, 2008 11:07 PM:

The incredible thing about the world wide web is the fact that one can access it from everywhere.

# IoNiX said on January 9, 2008 5:53 PM:

hi.. i want to learn a lot of stuff as much as i can about c# serial port.. my email is

humberto_hr@hotmail.com

if sum1 know a lot of c# and serial port.. it would be nice if u add me.. to help pls.. ty

# Gunnar Peipman's ASP.NET blog said on June 12, 2009 6:36 PM:

SharePoint Uploading Files to SharePoint Server 2007 from ASP.NET Web Applications by Using the HTTP

# Amit said on June 16, 2009 7:02 AM:

hi, I am using visual C# 2008 express edition and I want to close the Serial Port forcefully while it is receiving the data from the instrument. Can It be Possible to close the port while it is receiving the data? If Yes, How?

Please help me out

Amit

# amit said on June 16, 2009 7:04 AM:

hi, I am using visual C# 2008 express edition and want to Close the port while it is receiving the data. Is it Possible? If Yes, How?

Please Let me Know.

# Rakesh said on June 24, 2009 3:46 PM:

Hi, im working on a project, programming with C#.  Ive got to reset my module by sending a low state level through the TX. Actually when my module receives a low state for a certain time e.g 3sec. It resets itself.  

My question is that is it possible to send a "0" through SPP with C# or C++ and will the module decode it as a zero and reset it or will it just light up my TX lamp? please help me, i'm new to programming and first time i'm doing application programming.

Thank you.

# kasun said on June 25, 2009 6:04 AM:

In early my baud rate was 9600 & its successfully capture data which coming through comport. But in another machine baud rate was 4800 & now its not going to capture data. But in Hyper Terminal its going to capture data. Why........ ?

email to - kasunrox@yahoo.com

# improve credit said on October 15, 2009 3:22 AM:

This conversation is titilating! I\'ll have to come back here often!