Reputation: 9857
So I have a connection to an arduino using a Bluetooth card. Right now I have the com hard coded into the C# and the arduino doesn't set or choose a COM. My question is, assume I distributed this product. How do I know that my arduino will always connect to that COM? Is there a way to scan all COMs for a specific item then use that as a connection param? Here is some sample code of what I am doing to give you an idea.
SerialPort BlueToothConnection = new SerialPort();
BlueToothConnection.BaudRate = (9600);
BlueToothConnection.PortName = "COM3";
BlueToothConnection.Open();
This code is currently working but as you can see COM3 is hard coded... No good for distribution
Also this is the basic example given when you Google C# and Bluetooth connections so no help there.
Upvotes: 0
Views: 351
Reputation: 11176
Possible options are:
SerialPort.GetPortNames()
) and attempt to communicate to your deviceYou cannot guarantee that your device will be connected to that COM port because that depends on OS specific setting (is there COM3 at all?) and user specific settings (user may choose on of several COM ports)
Upvotes: 1