CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

how work serial port in c# topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2009, 03:13 AM
Junior Member
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
morteza bazrafshan is on a distinguished road
| More
how work serial port in c#

hi
i start work with c# three week ago
i'm an electronic engineer and i want send some data from micro to pc
i want work with c# for data monitoring
how can we work with serial port in c#?
thank you
Reply With Quote
  #2  
Old 04-26-2009, 08:53 PM
Junior Member
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
DotNetNewb is on a distinguished road
| More
Re: how work serial port in c#

I've written a few apps using the System.IO.Ports.SerialPort library.

It's pretty straight forward.

Simply create an instance of System.IO.Ports.SerialPort,


example from MSDN:

// Create a new SerialPort object with default settings.
System.IO.Ports.SerialPort _serialPort = new SerialPort();

// Allow the user to set the appropriate properties.
_serialPort.PortName = SetPortName(_serialPort.PortName);
_serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate);
_serialPort.Parity = SetPortParity(_serialPort.Parity);
_serialPort.DataBits = SetPortDataBits(_serialPort.DataBits);
_serialPort.StopBits = SetPortStopBits(_serialPort.StopBits);
_serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);

// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;

_serialPort.Open();


when you want to write something to the port

_serialPort.Write(.....);

there's a few different ways to write, you can write a string, or a byte array.

when your done with the port,

_serialPort.Close();
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
HideCaret() Windows API function doesn't work properly cygnusX C# Programming 1 05-30-2008 02:58 PM
C#/C++/TGE(A) programmers for indie gamedev, remote work, royalty pay BirdDog Looking to hire 8 05-08-2008 04:08 AM
transmit and recieve data from serial port using c sakshamgupta C Programming 1 05-29-2007 06:42 AM
c code for transmitting and recieving data from serial port sakshamgupta C Programming 0 05-29-2007 05:15 AM
pda communication with serial port sleepyzzz C Programming 0 03-24-2007 12:29 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:28 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board