title: 32feet.net: How to connect to a specific COM port via BluetoothClient
body: <p>I am trying to build a windows application with C#/Visual Studio 2010 which would do the following functions (in sequence): For bluetooth operations, I am using 32feet.Net library functions.</p>
  
  <ol>
  <li><p>Find the bluetooth devices and list them in the list/combo box for the user to select. (I want to allow user to select multiple devices and hence NOT going for <code>SelectBluetoothDeviceDialog</code> class option.). I can get the list of devices via <code>BluetoothClient.DiscoverDevices()</code>, however, it is not an async operation. If possible, I would like to go for the async operation. I read about the <code>BluetoothComponent</code> class with events <code>DiscoverDevicesProgress</code> and <code>DiscoverDevicesComplete</code> and method <code>DiscoverDevicesAsync</code> but could not get it working. If possible, kindly share a sample code for this.</p></li>
  <li><p>User selects the devices from the list and clicks 'Pair' button. So far I can successfully pair the devices via <code>BluetoothSecurity.PairRequest</code>. No issues here.</p></li>
  <li><p>User now selects one/multiple device(s) from the 'paired' list and clicks 'connect'. Here I tried to connect to the device using <code>BeginConnect</code> (for async operation) and <code>Connected</code> methods of the <code>BluetoothClient</code> class but getting following exception.</p></li>
  </ol>
  
  <blockquote>
    <p>System.Net.Sockets.SocketsException: {"An invalid argument was
    supplied 000319002CC6:0000110100001000800000805f9b34fb"}.</p>
  </blockquote>
  
  <p>The number in the above exception is GUID number required for the <code>Connected</code> method which I passed using <code>BluetoothService.SerialPort</code>. This will fail as my device is expecting to be connected at COM7 port. I am not sure how can I connect/pair a device at the specific COM port? Is is even possible by 32feet.Net library functions? If so, kindly provide a code sample.</p>
  
  <p>References Note:I have already read and tried to implement the code explained in the article below on StackOverflow. However, due to my requirements (allowing user to pair and connect to multiple devices at COM ports) I am unable to run the same code. However, it did help understanding the concept.
  <a href="https://stackoverflow.com/questions/7773000/32feet-net-howto-discover-nearby-bluetooth-devices-async-in-c-sharp">32feet.net howto discover nearby bluetooth devices async in c#</a></p>
  
  <p>Request you to advise the best way to handle this situation. In case I should try using any other library/functions other than 32feet.Net , do let me know.</p>
  
  <p>My ultimate goal is to BOTH read and write data from and to the connected device(s). So, as of now, I am just trying to get connected on a specific COM port via bluetooth.</p>
  
  <p>Regards,
  Rumit</p>
  
  <p>===========================
  EDIT: updated information for answer 1:</p>
  
  <p>I have received a bluetooh device (a patch) which is supposed to be connected to TOSHIBA VIRTUAL BT COM port. I apologize if the TOSHIBA information was necessary to better answer the question. I am new to the communication with ports. So far I know that I need to use COM7. I have an application built in C++ which connects to the same patch on COM7 via bluetooh. However, I don't have the source code and I have been asked to implement the same utility in C#. From your reply, can I assume that the C++ application might be using Windows Sockets 2 by any chance? </p>
  
  <p>Also, I could see an option to specify a port (integer value) value in <code>BluetoothEndClient</code> but that also did not work. So, I assume that the port was not COM and was some other type of port.</p>
  
  <p>Regards,
  Rumit</p>