0

i want to detect/Configure serial port (COM Port) on which my device is connected automatically. Is it possible to do so in c#?

Swarup
  • 95
  • 1
  • 3
  • 15
  • You have to detect **COM** number – ASalameh Jul 20 '14 at 12:16
  • thanks, yes but how do i do it programmatic automated ? I need to set Com port number, Boud rate n all things that I wanna detect programatically automated – Swarup Jul 20 '14 at 12:18
  • [Maybe this help](http://stackoverflow.com/questions/3293889/how-to-auto-detect-arduino-com-port) – ASalameh Jul 20 '14 at 12:20
  • Nothing is "automatic" when you use serial ports. Dating from the stone-age of computing, they are not plug & play devices. You have to know the port number and the port settings, like baudrate, up front and they must exactly match the device settings. You typically need to provide the user with a configuration UI or file so they can match your program to the device. – Hans Passant Jul 20 '14 at 12:32
  • Will the device respond automatically when connected? – dbasnett Jul 20 '14 at 14:18
  • @dbasnett my device will sends ack ready signal as it gets connected and config with CPU. but my problem is unless I config my device by setting Port number,baud rate, etc it doesn't happens. i want to write program for config my device automatically when i plugged into CPU. – Swarup Jul 20 '14 at 16:26
  • Using the port names returned from IO.Ports.SerialPort.GetPortNames try to connect to each of them in turn. The device that returns 'ack ready' is the device you want. – dbasnett Jul 20 '14 at 17:49
  • It gets even less "automatic" when you have two such devices. – Tom Blodget Jul 20 '14 at 19:50

1 Answers1

2

What exactly you like to do? Did you look at Properties and Methods in System.IO.Ports class?

Following MSDN article may help.

http://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.110).aspx

Haja Maideen
  • 450
  • 2
  • 4
  • I am going to read data from serial port given by my electronic device which i am going to connect. But i need to configure each time manually within my program. I got all config details from system.IO.Ports but i am not getting automate config... – Swarup Jul 20 '14 at 12:24
  • You must convert your app as multi threaded and a function which runs in background thread, and poll all the com ports in the system and try to open and handshake each. What ever port open successfully with out timeout, and able to handshake with you, it is the port you are interested and device connected to it. Then you can raise an event, from this background function which is nothing but the autodetect. – Haja Maideen Jul 20 '14 at 12:43