.NET Components for Mobility

using SetServiceState

Last post 07-31-2009 6:07 AM by rafalc. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 06-29-2009 3:16 AM

    using SetServiceState

     hello,

    I am using SetServiceStat to connect my BT device to the computer. It seems to work very nicely on the first time but how do i connect my device again to same comport after for example i restart the BT device or take the dongle out. Thanks for the help!

    My platform desktop windows XP SP3

    here is my code for the connection

    BluetoothClient test = new BluetoothClient();                                               
    devices = test.DiscoverDevices();
                    while(connections != 4)
                    {
                        foreach( BluetoothDeviceInfo device in devices)
                        {    
                        
                        
                         
                            if(!device.Authenticated)
                                {
                                if(!InTheHand.Net.Bluetooth.BluetoothSecurity.PairRequest( b.DeviceAddress,"6115"))
                                    {
                                    
                                    return;
                                    }
                
                                }

                             device.SetServiceState( BluetoothService.SerialPort, true ); //this connects the device but when connection is lost it doesnt do it again

                         }

     

     

     

  • 06-29-2009 9:01 AM In reply to

    Re: using SetServiceState

    Isn't the COM port there after you reboot?  I thought it should be.  That API does the same as checking the relevant checkbox on the Services tab of the Bluetooth Device control panel.

    Do you need to use a COM port anyway.  I like BluetoothClient a lot better, see the "Bluetooth Serial Ports" in the user guide. :-)

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 07-01-2009 2:00 AM In reply to

    Re: using SetServiceState

     yeah my bad the comports stay here after reboot..  and rest of my application is using these comports so i kind of need them.. my aplication is working now by the way.. only problem is that i have to use comport names as names of my signals..

    could you help me with this.. 

    So i would like to find the name of the device that is connected to certain comport, or name of the certain comport that handles certain device.. is this possible with this library..

     

  • 07-05-2009 2:46 PM In reply to

    Re: using SetServiceState

    We don't have anything that does that.  I'd try looking in the Registry for the port definition, hopefully the device information is available there.
    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 07-15-2009 11:09 AM In reply to

    Re: using SetServiceState

    I have similar problem.

    We're developing GPS application (on windows mobile 5/6 platform) for automotive/drivers. ATM we're switching from using GPS Intermediate Driver API (GPSOpenDevice(), GPSGetPosition() etc) to parsing NMEA directly from COM port - no matter if it's virtual COM port from GPS ID, hardware bluetooth port or builtin GPS 'hardware'  COM port.

    Users of this application have the configuration options, where they choose which GPS receiver they want to use: device builtin, bluetooth GPS, or advanced configuration where they configure all stuff like GPS ID program COM port, hardware COM port, baud rate etc manually. 

    For bluetooth GPS, we're using 32feet library to show them bluetooth devices already configured/paired on their device, as well as bluetooth devices in range. If user chooses a device which is not paired yet, we're first pairing it using BluetoothSecurity.PairRequest then enabling serial port using SetServiceState. After that GPS Intermediate Driver is configured to use serial port just configured as hardware port and signaled to reload it's configuration. The code looks like this (removed not relevant parts)

     

    BluetoothDeviceInfo[ devices = bc.DiscoverDevices(255, true, true, true);
    BluetoothDeviceInfo bdi = ... // user selects one of discovered devices
    if (bdi.Authenticated == false)
    {
    bool ret = BluetoothSecurity.PairRequest(bdi.DeviceAddress, PinValue);
    if (ret == false)
    // handle error - couldn't connect to selected device

    bdi.SetServiceState(BluetoothService.SerialPort, true, true);

    // this function reads port name from HKLM\Software\Microsoft\Bluetooth\Serial\Ports\<device address>\Port
    SelectedPort = GPSConfig.GetBluetoothPortName(bdi.DeviceAddress);
    }

    The problem we're having is with PairRequest/SetServiceState. On the first sight it works fine - the configuration is set up in the registry (HKLM\Software\Microsoft\Bluetooth) exactly like bluetooth configurator from windows mobile does it. The only exception is, that it doesn't work until the device is rebooted. 

    I read the 32feet source code to see how SetServiceState and PairRequest work and it seems that those functions do not notify bluetooth(?) driver that the configuration changed. There must be some way to do this. Devices configured with control panel bluetooth configurator do not require reboot to work.

    Is there some way to fix this issue? Maybe setting those devices directly to the registry is not the best idea. Maybe provisioning would work better?

    Btw. I know BluetoothClient works nice when communicating to the bluetooth GPS receiver, but I can't use it because the rest of our GPS related code is expecting virtual or hardware COM port from which it can read.

    I can provide some more details if needed.

     

    Best regards

    Grzegorz Aksamit

    Grzegorz Aksamit
    http://blog.aksam.it
  • 07-15-2009 8:19 PM In reply to

    Re: using SetServiceState

    Ok, I already almost solved it myself.

    I'm not using SetServiceState() anymore. I wrote my code that writes the necessary settings to the registry and (this was the missing part I guess) calls RegisterDevice() from Windows Mobile API.

    I'll post some code after I test this solution and clean the code.

    Grzegorz Aksamit
    http://blog.aksam.it
  • 07-16-2009 10:43 AM In reply to

    Re: using SetServiceState

    Good stuff!  Its a often asked for feature to not need that reboot.
    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 07-30-2009 9:20 AM In reply to

    • rafalc
    • Top 500 Contributor
    • Joined on 07-30-2009
    • Posts 5

    Re: using SetServiceState

    Grzegorz,

    I'm having the same issue. 

    I would be very interested to see your code responsible for writting appropriate registry settings and then using native RegisterDevice function. I'm partiucullary interested how you set up the PORTEMUPortParams structure which is being passed as a parameter. Do you have a c# wrapper for this function only and do all the rest in c# or you implemented pure c++ routine handling all and then wrapped to c#?

    Looking forward to hearing from you.

    Regards,
    Rafal

  • 07-30-2009 12:36 PM In reply to

    Re: using SetServiceState

    hey,

    I wrote some quick blog post about that: here's the link

    Regards

     -- edit: blog moved somewhere else, domains changed, etc - link updated

    Grzegorz Aksamit
    http://blog.aksam.it
  • 07-30-2009 1:30 PM In reply to

    • rafalc
    • Top 500 Contributor
    • Joined on 07-30-2009
    • Posts 5

    Re: using SetServiceState

    Thanks for the blog post. This looks what I need however I cannot see the code you posted.
    Get blank pages when clicking on one of the links bellow your article ;(

     R.

  • 07-30-2009 2:27 PM In reply to

    Re: using SetServiceState

     try again, I've reposted them to pastebin

    Grzegorz Aksamit
    http://blog.aksam.it
  • 07-31-2009 6:07 AM In reply to

    • rafalc
    • Top 500 Contributor
    • Joined on 07-30-2009
    • Posts 5

    Re: using SetServiceState

    Grzegrz,

    Thanks a lot for your EXCELLENT post!!

    Bardzo bardzo wielkie dzieki!!

    Pozdrawiam,

    Rafal

Page 1 of 1 (12 items)
Copyright © 2001-2010 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.