.NET Components for Mobility

Widcomm crashes using the latest version inthehand.net.personal

Last post 06-23-2010 11:31 AM by Adel. 23 replies.
Page 1 of 2 (24 items) 1 2 Next >
Sort Posts: Previous Next
  • 02-28-2010 8:07 AM

    Widcomm crashes using the latest version inthehand.net.personal

    Hi,
    I compiled the latest source code 64209 (inthehand.net.personal) but when i try opening a second bluetooth connection on the windows mobile phone, i get the following error

    at InTheHand.Net.AsyncResultNoResult.EndInvoke()
    at InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommStream.EndConnect(IAsyncResult ar)
    at InTheHand.Net.Bluetooth.Widcomm.WidcommBluetoothClient.Connect_ConnCallback(IAsyncResult ar)
    at InTheHand.Net.AsyncResultNoResult.SetAsCompleted(Exception exception, AsyncResultCompletion completion)
    at InTheHand.Net.AsyncResultNoResult.SetAsCompleted(Exception exception, Boolean completedSynchronously)
    at InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommStream.HandleCONNECT_ERR(PORT_EV eventId)
    at InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommStream.HandlePortEvent(PORT_EV eventId, IRfcommPort port)
    at InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommPort.HandleEventReceived(UInt32 eventId)

    Any idea why that happens? Cant we have 2 or more simultaneous bluetooth connections with Widcom?
    cheers Peter
  • 02-28-2010 2:39 PM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    That's not a "crash"! :-)  It's just a error -- could not connect.

    It works for me.  Both to two services on one remote device, and to two remote devices.

    Bluetooth itself does not support two connections to one service on one device. :-(

    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.
  • 03-01-2010 12:59 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Hi,
    It seems i am not lucky with the latest version. Without changing my code i get now the following error when a device discovery has completed on widcom. I use the BeginDiscoverDevices technique. On private void HandleDiscoverComplete(IAsyncResult result) the application crashes with the following screen. See link. Never had these type of errors before.

    http://personalheartmonitor.com/download/error.png

    Any idea what is going on?
    Peter
  • 03-01-2010 1:34 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    I got a step further. My mistake was to use the Microsoft SerialPort service GUID for the widcom stack in this line of code

    btClient.Connect(new BluetoothEndPoint(btDeviceInfo.DeviceAddress, BluetoothService.SerialPort));

    I changed that to the following if i deal with a widcom stack

    btClient.Connect(new BluetoothEndPoint(btDeviceInfo.DeviceAddress, Guid.NewGuid()));

    But now i get the following error:
    "No connection could be made because the target machine actively refused it"

    With tis as additional info
    {"; PortLookup_Zero"}
  • 03-01-2010 4:28 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    I still cant figure it out how to get the GUID codes from the remote device. I do a devicediscovery and get an array of BluetoothDeviceInfo objects. I want to connect to one of these devices but i do not know which GUID to use. This only applies to widcom. I got it all working fine for Microsoft stack.
    I tried this
    ServiceRecord[ tmp = btDeviceInfo.GetServiceRecords(Constants.SERIALPORTSERVICE); where Constants.SERIALPORTSERVICE is a unique GUID. The method always returns no elements (length = 0)
  • 03-01-2010 5:01 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    I got it working again. I just use this to connect to a serial port
    btClient.Connect((new BluetoothEndPoint(btDeviceInfo.DeviceAddress, BluetoothService.SerialPort)));

    I am not creating a random Guid to connect to the serialport service but use the standard one:BluetoothService.SerialPort
    The weird thing is that i had this originally but then i was getting the errors mentioned before. .
  • 03-01-2010 6:29 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Almost there. I tested it on an HTC HD2 and it is okay. Testing it on an old model Asus P735 Widcom phone and i get now this error message:
    Assertion Failed
    Need to upgrade your 32feetWidcomm.dll
    at
    ......
    .....


    It seems that the latest inthehand compilation does not work with the 32widcomm.dll i am using. Maybe an idea to release all dlls with the source code.
    Any advice which 32feetWidcomm.dll to use?
  • 03-01-2010 12:27 PM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    So lots of things there. :-)

    Firstly. since r64192 calling Widcomm BtRadio.Mode will report that warning message unless a new version of the native DLL is included.  Aren't you using the new DLL on your new machine?

    64912    Enable the change to Widcomm radio get_Mode for when stack disabled (bug 26240) r64080.
    This needs a new version of the native DLL e.g. from http://32feet.codeplex.com/releases/view/40797 

     

    Secondly, have a read of the user guide.  It explains that both ends (client and server) need to use the same Service Class Id, its useless otherwise!  So for a custom application the developers create one unique Class Id at design time and both programs use it forever at run-time  See the examples in the user guide.

     

    Thirdly on reusing an existing Service Class Id.  If one runs two servers using the same Service Class Id, then there will be two SDP records identified by that UUID.  If the client connects by class id then it is completely random/arbitrary as to which server the client will choose to connect to.  In some cases it will be the first record and in others it will be the last record returned.  So you're lucky in your recent testing that the record your server added is being chosen.  You can't rely on that however.  In other cases the record added by the built-in virtual serial port server will be chosen.

    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.
  • 03-02-2010 12:25 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Hi, Ok i solved the issue with the Dlls. I read your documentation and also looked at your SDP browser app to see where i go off the track. I seem not to grasp it. I have sensors that will contact my mobile phone (widcomm). I have an bluetooth listener instantiated as follows:
    bluetoothListener = new BluetoothListener(Guid.NewGuid());


    So it is a unique GUID. Now you say that both ends need to use the same Service Class Id. So you mean they use the same Guid as created in BluetoothListener(Guid.NewGuid())?

    I can understand that but my problem is that my code never gets further than btClient = bluetoothListener.AcceptBluetoothClient();
    Here are some lines of code i wonder what i do wrong? For simplicity i dont create a separate thread to handle the incoming connection
    BluetoothListener bluetoothListener = new BluetoothListener(Guid.NewGuid());
    bluetoothListener.Start();
    BluetoothClient btClient = bluetoothListener.AcceptBluetoothClient();

    // I have a bluetooth snesor that tries to connect to my widcom phone but it is not picked up by the software MessageBox.Show("I NEVER GET HERE ");


    Can you please post the most simple bluetooth listener application that would work?
  • 03-02-2010 12:54 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Finally solved it! it had nothing to do with the software. When i manually pair the sensor with a HTC HD2 i use the default settings (Com2 port). I played with the Local COM Port and changed it to "BTC1:" for the widcom phone et voila it accepts the incoming connection and triggers the code. So the question is whether i can change the Local Com port programmaticaly?
  • 03-03-2010 12:25 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    The previous post was premature. I did NOT solve it. I thought i had it going but i was on a Microsoft phone. Basically i am still stuck on the widcom stack. I read all the documentation and i really would like to see an example for a WIDCOM stack where a bluetoothlisterner listens for serialport connections. I am dealing with sensors that contact the mobile phone and try to establish a connection. I have it all working for Microsoft stack phones but widcom never sees the incoming connection. I can see on an HTC HD2 phone that an incoming connection is set-up between the sensor and the phone but that trigger is never passed on to my software. I am 100% sure that it is a serial port connection. help would be appreciated. Thanks Peter
  • 03-03-2010 6:52 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Hi, I did some more testing and i tested it against the SdpBrowserCF2 that comes with the 2.5 release. I ran the SDPBrowser on a Microsoft phone and started listening for incoming connections. I have a sensor that will contact a phone it has been paired with. On a Microsoft phone the SDPBrowser detects the incoming request and says "connected" . I did the exact same thing on a HTC HD2 phone which has a widcomm stack. The widcomm phone DOES NOT see the incoming connection. So it seems to me that the bluetooth listener does not work for Widcom stacks. Does anyone have it working for a widcom phone? if so what are the exact lines of code to listen for incoming serial port connections. cheers Peter
  • 03-03-2010 3:10 PM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Are you writing software for the sensors, or are they third-party? 

    I will presume they are third-party, and they always only connect to SerialPort (SPP)?  If so that the built-in Widcomm service will get the connections and not your server.  It is listening on SPP, and you are listening on SPP.  That's not good!

    Two solutions:

    1. Just use the Widcomm virtual serial port and not BluetoothListener at all.

    2. Stop the Widcomm Serial Port service and use BluetoothListener.  Go to the Widcomm control panel, "Services" tab, select "Serial Port" and disable it.

    Widcomm Service configuration

     

    Whatever you do, just arrange for only ONE serial port server to be active ever.  Use SdpBrowser to check what SDP records exist.

    (There's a possibility that the sensor looks for a SDP recordby Service Name, does the documentation mention anything?)

    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.
  • 03-03-2010 7:55 PM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Hi
    Indeed that did the trick! Thanks for that! I disabled the serial port setting on the device. This works nice for older phones but for the HTC HD2 it seems you can just disable a particular service. Is there a way to programmatically disable a particular service? That would be ideal since i can still use the bluetoothlistener but by disableing the serial port service the application receives all the incoming data.
    Or would there be a piece of software that shares a widcomm incoming connection with multiple apps?
  • 03-04-2010 3:37 AM In reply to

    Re: Widcomm crashes using the latest version inthehand.net.personal

    Hi,

    Wow i got it finally solved for the widcomm stack and happy to share it with everyone. Maybe some of this can be included in the Widcomm documentation since, to be honest, it is not clear from the document that the bluetooth listener is quite a different beast when you deal with a WIDCOMM stack. The previous post with the image to disable the serial port service was the key to the whole problem. Of course as a developer you want to disable the serial port service programmatically and enable it when your application exists. Luckily you can do this by going into the registry. It took me a bit of testing to see which Key was the one that enables/disables the serial port service but i found it. So how does it all work if you want to listen to sensors (e.g. blood glucose monitors) that use the standard Serial Port service.

    You can use the BluetoothListener as normal (so the same code as for a Microsoft stack. So something like this:

    // Disable the Serial Port service on your phone

    DisableWidcommSPP();

      // Start a listener and wait for incoming serial port connection

    bluetoothListener = new BluetoothListener(BluetoothService.SerialPort);               

    bluetoothListener.ServiceName = “your particular name if you need to”;

    bluetoothListener.Start();

    // Start a new thread to deal with an incoming Bluetooth connection

    Thread t = new Thread(new ThreadStart(ListenLoop));

    t.Start();

     

    private void ListenLoop()

    {

    BluetoothClient btClient =null;

    while(listening)

    {

    try

          {

                // This call blocks till we get an incoming connection

                btClient= bluetoothListener.AcceptBluetoothClient();

     

                // Bond with the device? Very handy if you don’t wantthose annoying popups. Does not work always though!

    BluetoothSecurity.PairRequest(btClient.RemoteEndPoint.Address,“the pin for this device”);

     

    // Now do soemthing with theconnection etc

    btClient.GetStream());

          }

          catch (Exception ex)

          {

                string msg = ex.Message;

          }

    } // while

               

    // When to closethe connection?

    if (btClient!= null)

          btClient.Close();

    }

    // Somewhere in your application restore theserial port service.

    RestoreWidcommSPP(;

     

    NOW THIS IS IMPORTANT FOR WIDCOMM. You need to disable the serial port service on the phone so that theBLuetoothListener gets the incoming connection. You can programmaticallydisable the seruial port service by setting the “Auto” key to 0. So before youstart listening with BluetoothListener disable it. You want to enable it onceyou are done with the listener! Here is the code

      /// <summary>

            /// Disable the serial port service on the phone so long welisten for incoming connections

            /// </summary>

            public static voidDisableWidcommSPP()

            {

                RegistryKeyregistryKey = null;

                try

                {

                    registryKey = Registry.LocalMachine.CreateSubKey("Software\\WIDCOMM\\BTConfig\\Services\\0001\\");

                    objectvalue = registryKey.GetValue("Auto");

     

                    //remember the status of the SSPP service. We need to restore it later

                    Constants.WIDCOMMSPP= value;

     

                    //Deactivate the spp service

                    registryKey.SetValue("Auto", 0, RegistryValueKind.DWord);

                }

                catch(Exception ex)

                {

                    stringtmp = ex.Message;

                }

                finally

                {

                    if(registryKey != null)

                        registryKey.Close();

                }

            }

     

            /// <summary>

            /// Restore the Widcomm Serial Port service

            /// </summary>

            public static voidRestoreWidcommSPP()

            {

                RegistryKeyregistryKey = null;

                try

                {

                    registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\WIDCOMM\\BTConfig\\Services\\0001\\");

                 

                    //Restore the spp service

                    registryKey.SetValue("Auto", Constants.WIDCOMMSPP);

                }

                catch(Exception ex)

                {

                    stringtmp = ex.Message;

                }

                finally

                {

                    if(registryKey != null)

                        registryKey.Close();

                }

            }

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