Connect Serial Port

 

  1. //Add the NameSpace fo serialPort  
  2.   
  3. using System.Io.ports;  
  4.   
  5. Write the below code in a Button Click :-  
  6.   
  7. ---------------------------------------  
  8.   
  9. SerilaPort sp=new SerialPort();  
  10.   
  11. sp.PortName="COM1";  
  12.   
  13. sp.BaudRate=9600  
  14.   
  15. sp.DataBits=8;  
  16.   
  17. sp.Open();  
  18.   
  19. textWieght.Text=sp.ReadLine().ToString();  
  20.   
  21. sp.Close();