Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I am pretty new to serial port communication Please help me out how to set port mode through c sharp.

Thanks and regards
Pavan Kumar
Posted
Updated 2-Jan-12 20:12pm
v2

 
Share this answer
 
v2
Comments
Un_NaMeD 3-Jan-12 2:45am    
That's a nice link to follow. My 5!
Kim Togo 3-Jan-12 2:58am    
Thanks!
Sergey Alexandrovich Kryukov 3-Jan-12 3:02am    
Should help, a 5.
Happy New Year!
--SA
Kim Togo 3-Jan-12 3:03am    
Thanks SA. And Happy New Year!
That's pretty simple in .Net. You need to add these library:

using System.IO.Ports;


To open/close a port:

serialport.Open();
serialport.Close();


but you need to be carefull not the open an open one. You need to check if it's open or not with:

serialport.IsOpen();


Then you can use SerialPort class and make necassery adjustments like Port name, baudrate, parity, handshake...

SQL
seriPort.PortName = ....;
serialPort.BaudRate = ...;
serialPort.Parity = Parity.None;
serialPort.Handshake = Handshake.RequestToSend;



Also, you can get all the serialPort(including virtual ones) names using this little code:

serialport.GetPortNames();


Have Fun :)
 
Share this answer
 
v2
Comments
Kim Togo 3-Jan-12 2:59am    
My 5 for all the good advice :-)
Un_NaMeD 3-Jan-12 3:09am    
Thank you, Kim :)
Sergey Alexandrovich Kryukov 3-Jan-12 3:03am    
Agree, a 5. I would also add: good to run it all in a separate thread(s).
Happy New Year!
--SA
Un_NaMeD 3-Jan-12 3:10am    
Thank you, too SA..
Happy new year...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900