none
Visual Basic + Bluetooth (bluegiga WT12 module)

    Question

  • Hello, im trying to configure bluetooth device with visual basic, i added my bluetooth device(wich is "bluegiga WT12") to my laptop and it was registed on COM7.

    In visual basic i created serial port object for COM7 named "bt", and i just want to test community sending a simple char:

    bt.open()

    bt.Write(1)

    But when i try to send, it asks for pairing code, i checked on datasheet of my module and they say it is "1234", but when i put 1234 i get error.

     

    Any1 got experience with this that can help me? Do you know if is needed any .dll for bluetooth virtual serial port?

     

    Thanks for all help,

    Apok

    Monday, January 10, 2011 10:09 PM

Answers

  • Let's start by getting some details clear.   I am assuming that your laptop already supports BlueTooth - either BT support is built in or you have added it  (eg, a BT controller in a USB port).   This device appears in Widows device manager (eg, Generic BlueToothAdapter, MS Bluetooth Enumerator), and you can open the BT device manager and check the settings.   You could not have got as far as you did if all this wasn't in place.

    Now you want the PC to connect to a BT device (excuse the pedantry, but this is not "added bluetooth device to my laptop" - it is "connected to a remote BT device").   I presume from your description that the device type is standard serial port (not a HID, not a Radio, not a mass storage device etc), so that when the BT connection manager finds the device within range, it determines the device type correctly (it should display some identification for this device) and installs a serial port for you.  It is coming up as port 7.   This indicates that your configuration of the device profile as SPP is correct (the BT connection manager software in the PC determines that the profile is SPP, so it installs a generic BT serial port for you).

    You should be able to see COM7 in Windows device manager and the description should be something like "Standard BlueTooth Serial Port".

    If the port is installed and accessible then the remote device detection and pairing has worked correctly. I would have thought that the option to enter the pairing code, using the code recommended by the manufacturer, would be the best option, but if the remote device connection procedure completes properly then pairing is working OK.

    At this point, errors can occur in the serial comms link.   For instance, the baud rates might not match (you haven't indicated how object bt has been configured) or there may be a required handshake setting, or the comms link might just hang.   But if you are still getting a pairing error at this point then that indicates that the connection to the remote BT device is not correctly installed.  That is, it's not a VB problem, but a problem to do with the BT device itself, and particularly with its identification and configuration.

    You could try accessing the device through COM7 using some other softare (such as HyperTERM) and confirm that the error is not in the serial comms link but is in the identification/pairing.   If that's the case, your best bet is to go back to the manufacturer's support, or their forums, and see if someone can take you through device configuration and connection step by step.

    Essentially, when it's working properly, your VB application does not know or care about how the serial link is implemented - cable or bluetooth is irrelevant.   If that's not happening (ie, you get BT errors, not serial port errors, when you try to open the port) then the connection to the remote device has not been completed properly, even though the comms port is installed and everything looks OK. 

      

    Wednesday, January 12, 2011 3:30 AM
  • Let's start by getting some details clear.   I am assuming that your laptop already supports BlueTooth - either BT support is built in or you have added it  (eg, a BT controller in a USB port).   This device appears in Widows device manager (eg, Generic BlueToothAdapter, MS Bluetooth Enumerator), and you can open the BT device manager and check the settings.   You could not have got as far as you did if all this wasn't in place.

    Now you want the PC to connect to a BT device (excuse the pedantry, but this is not "added bluetooth device to my laptop" - it is "connected to a remote BT device").   I presume from your description that the device type is standard serial port (not a HID, not a Radio, not a mass storage device etc), so that when the BT connection manager finds the device within range, it determines the device type correctly (it should display some identification for this device) and installs a serial port for you.  It is coming up as port 7.   This indicates that your configuration of the device profile as SPP is correct (the BT connection manager software in the PC determines that the profile is SPP, so it installs a generic BT serial port for you).

    You should be able to see COM7 in Windows device manager and the description should be something like "Standard BlueTooth Serial Port".

    If the port is installed and accessible then the remote device detection and pairing has worked correctly. I would have thought that the option to enter the pairing code, using the code recommended by the manufacturer, would be the best option, but if the remote device connection procedure completes properly then pairing is working OK.

    At this point, errors can occur in the serial comms link.   For instance, the baud rates might not match (you haven't indicated how object bt has been configured) or there may be a required handshake setting, or the comms link might just hang.   But if you are still getting a pairing error at this point then that indicates that the connection to the remote BT device is not correctly installed.  That is, it's not a VB problem, but a problem to do with the BT device itself, and particularly with its identification and configuration.

    You could try accessing the device through COM7 using some other softare (such as HyperTERM) and confirm that the error is not in the serial comms link but is in the identification/pairing.   If that's the case, your best bet is to go back to the manufacturer's support, or their forums, and see if someone can take you through device configuration and connection step by step.

    Essentially, when it's working properly, your VB application does not know or care about how the serial link is implemented - cable or bluetooth is irrelevant.   If that's not happening (ie, you get BT errors, not serial port errors, when you try to open the port) then the connection to the remote device has not been completed properly, even though the comms port is installed and everything looks OK. 

      

     

    Hi Acamar,

     

    Thanks for your analysis, I agree with your opinion.

     

    I dont know if bluetooth+Visual Basic works like this, but i cannot find examples on internet, and by what i heard this should work.

    Hi Apokalyptor,

     

    Welcome to the MSDN forums!

     

    Here are some tutorials:

     

    Bluetooth Simulation in C# with Serial Ports

    http://www.codeproject.com/KB/windows/bth_serial_port.aspx

    Communicating with LEGO NXT via Bluetooth in C#
    http://www.codeproject.com/KB/cs/nxtBluetooth.aspx

    Bluetooth Connection in Windows Mobile 5.0 using InThehand - C#

    http://www.codeproject.com/KB/windows/Bluetooth_connection_C_.aspx

    Bluetooth SDK adds support for C#, VB.NET

    http://www.windowsfordevices.com/c/a/News/Bluetooth-SDK-adds-support-for-C-VBNET/

    It's likely to get better responses at this appropriate forum:
    .NET Framework Networking and Communication

     

    You can convert C# code to VB code using below tool:

    http://www.carlosag.net/Tools/CodeTranslator/

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

     

    Best Regards,


    Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 18, 2011 6:02 AM
    Moderator

All replies

  • What is the error you get when you enter the pairing code "1234"?     Have you searched the www using the error message text?

    If the serial port for the device has been installed properly and if the device is connected (that's what the pairing code will do) then there is no need for additional DLLs to establish basic serial communication.  But a vendor's DLL may be required to manage the device, or implement a particular data transfer propocol that the device requires.

    Monday, January 10, 2011 11:26 PM
  • The Bluetooth COM port is a service, not a device. You probably do not want to use the COM port just yet because you have not paired to any Bluetooth devices and you cannot use that COM port for that in any event. In Vista, you can connect to Bluetooth devices using Control Panel. In XP, Bluetooth is an add-in and you usually must use either generic device calls, or a specific API provided by the Bluetooth radio manufacturer. (BlueSoleil, for example.)

    So, use control panel to pair to your device...otherwise, you will have to use interop with setupapi.dll and also hid.dll

    Tuesday, January 11, 2011 12:16 AM
  • Hello acamar,

     

    There is no needed vendor DLL to manage the device.

     

    The error is on the following link:

    http://img526.imageshack.us/img526/2159/errorkm.jpg

     

    It happens when vb executes bt.open() line. It asks for pairing code, i write 1234 and i get the error.

    Btw when i added this device to my laptop i added the option "no pairing code is needed for connection" i cannot figure out why this is happening.

     

    Hey jinzai,

    I added device with control panel, and it created COM7, i need to send data VB-> Device, and Device-> VB, and i heard that i can do it using bluetooth as a virtual serial port on VB. (Device will be connected to a microcontroller).

    I will have to use dll's that you mentioned??

     

    Thanks,

    Apok

    Tuesday, January 11, 2011 12:20 AM
  • Btw when i added this device to my laptop i added the option "no pairing code is needed for connection" i cannot figure out why this is happening.

    That is probably the error.   Remove the BT device (from the BT device manager).  Reboot.  Add it. Select to enter a pairing code.  Enter 1234.  Try again.

    Typical behaviour is for the device to show as unconnected uintil you open the serial port, then, if pairing is properly established, opening the port cretes the connection (and it should show as connected on the device icon within your BT manager).   But lots of BT devices are not 'typical'. 

    Tuesday, January 11, 2011 1:00 AM
  • No, just get it installed correctly once....Acamar is right, I think. (I see you are using Vista....that helps.)

    Tuesday, January 11, 2011 1:10 AM
  • Hello guys, acamar i though that too, but it wont work, when i add device to my laptop i got 3 options, they are in the following link:

    http://img689.imageshack.us/img689/9900/62034947.jpg

     

    If i choose option "Create a pairing code for me" or "Enter the device's pairing code" i get the same error, it's why i choosed the last option, because is the only option that works.

     

    I will explain all i did, maybe it can helps.

    I got bluetooth device wich is "blue giga wt12 module" connected to a microcontroller, like in this link: http://i263.photobucket.com/albums/ii123/surf_hbc/mbed_bt_final.jpg

     

    My micrcontroller got a code, wich does when i send via bluetooth char "1", a LED will turn on.

     

    Frist i added bluetooth device to my laptop, it was only sucessfully using last option "Pait without using a code".

    After device installation, i went to his properties to check what COM was attributed, it was COM7, as you can see in this link:

    http://img199.imageshack.us/img199/9905/45483182.jpg

     

    After all this i maked Visual Basic app, a simple form with a single button. And i created a serial port object named "bt" for COM7.

    And code is only this:

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            bt.Write(1)

        End Sub

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            bt.Open()

        End Sub

     

     

    to check if LED turn's on clicking on button, just to know if communication is working to make the real project.

     

    The problem is on bt.open(), i get the error in frist topic.

     

     

    I dont know if bluetooth+Visual Basic works like this, but i cannot find examples on internet, and by what i heard this should work.

     

    Thanks for all help,

    Apok

     

     

    Tuesday, January 11, 2011 12:52 PM
  • Let's start by getting some details clear.   I am assuming that your laptop already supports BlueTooth - either BT support is built in or you have added it  (eg, a BT controller in a USB port).   This device appears in Widows device manager (eg, Generic BlueToothAdapter, MS Bluetooth Enumerator), and you can open the BT device manager and check the settings.   You could not have got as far as you did if all this wasn't in place.

    Now you want the PC to connect to a BT device (excuse the pedantry, but this is not "added bluetooth device to my laptop" - it is "connected to a remote BT device").   I presume from your description that the device type is standard serial port (not a HID, not a Radio, not a mass storage device etc), so that when the BT connection manager finds the device within range, it determines the device type correctly (it should display some identification for this device) and installs a serial port for you.  It is coming up as port 7.   This indicates that your configuration of the device profile as SPP is correct (the BT connection manager software in the PC determines that the profile is SPP, so it installs a generic BT serial port for you).

    You should be able to see COM7 in Windows device manager and the description should be something like "Standard BlueTooth Serial Port".

    If the port is installed and accessible then the remote device detection and pairing has worked correctly. I would have thought that the option to enter the pairing code, using the code recommended by the manufacturer, would be the best option, but if the remote device connection procedure completes properly then pairing is working OK.

    At this point, errors can occur in the serial comms link.   For instance, the baud rates might not match (you haven't indicated how object bt has been configured) or there may be a required handshake setting, or the comms link might just hang.   But if you are still getting a pairing error at this point then that indicates that the connection to the remote BT device is not correctly installed.  That is, it's not a VB problem, but a problem to do with the BT device itself, and particularly with its identification and configuration.

    You could try accessing the device through COM7 using some other softare (such as HyperTERM) and confirm that the error is not in the serial comms link but is in the identification/pairing.   If that's the case, your best bet is to go back to the manufacturer's support, or their forums, and see if someone can take you through device configuration and connection step by step.

    Essentially, when it's working properly, your VB application does not know or care about how the serial link is implemented - cable or bluetooth is irrelevant.   If that's not happening (ie, you get BT errors, not serial port errors, when you try to open the port) then the connection to the remote device has not been completed properly, even though the comms port is installed and everything looks OK. 

      

    Wednesday, January 12, 2011 3:30 AM
  • Let's start by getting some details clear.   I am assuming that your laptop already supports BlueTooth - either BT support is built in or you have added it  (eg, a BT controller in a USB port).   This device appears in Widows device manager (eg, Generic BlueToothAdapter, MS Bluetooth Enumerator), and you can open the BT device manager and check the settings.   You could not have got as far as you did if all this wasn't in place.

    Now you want the PC to connect to a BT device (excuse the pedantry, but this is not "added bluetooth device to my laptop" - it is "connected to a remote BT device").   I presume from your description that the device type is standard serial port (not a HID, not a Radio, not a mass storage device etc), so that when the BT connection manager finds the device within range, it determines the device type correctly (it should display some identification for this device) and installs a serial port for you.  It is coming up as port 7.   This indicates that your configuration of the device profile as SPP is correct (the BT connection manager software in the PC determines that the profile is SPP, so it installs a generic BT serial port for you).

    You should be able to see COM7 in Windows device manager and the description should be something like "Standard BlueTooth Serial Port".

    If the port is installed and accessible then the remote device detection and pairing has worked correctly. I would have thought that the option to enter the pairing code, using the code recommended by the manufacturer, would be the best option, but if the remote device connection procedure completes properly then pairing is working OK.

    At this point, errors can occur in the serial comms link.   For instance, the baud rates might not match (you haven't indicated how object bt has been configured) or there may be a required handshake setting, or the comms link might just hang.   But if you are still getting a pairing error at this point then that indicates that the connection to the remote BT device is not correctly installed.  That is, it's not a VB problem, but a problem to do with the BT device itself, and particularly with its identification and configuration.

    You could try accessing the device through COM7 using some other softare (such as HyperTERM) and confirm that the error is not in the serial comms link but is in the identification/pairing.   If that's the case, your best bet is to go back to the manufacturer's support, or their forums, and see if someone can take you through device configuration and connection step by step.

    Essentially, when it's working properly, your VB application does not know or care about how the serial link is implemented - cable or bluetooth is irrelevant.   If that's not happening (ie, you get BT errors, not serial port errors, when you try to open the port) then the connection to the remote device has not been completed properly, even though the comms port is installed and everything looks OK. 

      

     

    Hi Acamar,

     

    Thanks for your analysis, I agree with your opinion.

     

    I dont know if bluetooth+Visual Basic works like this, but i cannot find examples on internet, and by what i heard this should work.

    Hi Apokalyptor,

     

    Welcome to the MSDN forums!

     

    Here are some tutorials:

     

    Bluetooth Simulation in C# with Serial Ports

    http://www.codeproject.com/KB/windows/bth_serial_port.aspx

    Communicating with LEGO NXT via Bluetooth in C#
    http://www.codeproject.com/KB/cs/nxtBluetooth.aspx

    Bluetooth Connection in Windows Mobile 5.0 using InThehand - C#

    http://www.codeproject.com/KB/windows/Bluetooth_connection_C_.aspx

    Bluetooth SDK adds support for C#, VB.NET

    http://www.windowsfordevices.com/c/a/News/Bluetooth-SDK-adds-support-for-C-VBNET/

    It's likely to get better responses at this appropriate forum:
    .NET Framework Networking and Communication

     

    You can convert C# code to VB code using below tool:

    http://www.carlosag.net/Tools/CodeTranslator/

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

     

    Best Regards,


    Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 18, 2011 6:02 AM
    Moderator
  • Are you using a WT12 evaluation board? Do you see the password "1234" when you type "SET" on the computer attached to the eval board?
    Thursday, June 02, 2011 8:58 PM