.NET Components for Mobility

Simple Bluetooth Transfer - Widcomm issues

Last post 02-23-2010 3:21 AM by lamle. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 02-05-2010 2:50 PM

    • rorik
    • Top 500 Contributor
    • Joined on 02-05-2010
    • Toronto, Ontario, Canada
    • Posts 4

    Simple Bluetooth Transfer - Widcomm issues

    Hello,

    I'm new to using Bluetooth, so am not sure if I'm missing something. 

    I'm trying to write a few functions that will transfer arbitrary information from one device to another.  I'm not sure of the best way to do this, so was originally looking at making a modification to a "Bluetooth Chat" sample.

    I'm running Windows 7, programming in MS Dev. Studio 2008.  Therefore, my desktop bluetooth stack is a Microsoft stack.  The device I need to transfer information to and from is an HTC Touch Pro 2 (which, from my understanding, has a Widcomm stack). I'm using the Microsoft CF and Windows Mobile 6 Professional to program for the HTC.

    I believe I've followed all of the instructions to get the Widcomm stack to run (copied the native DLL to the execution folder, etc.), however, I am still having issues.  I modified the BluetoothChat sample program by removing the listener and translating it to C#.  My goal was to get the program running on the HTC.  I successfully get a list of devices I can connect to, however, when I go to send a message, I get an error on the client.Connect() function stating "IOException was unhandled - IOError on socket".  I pulled the lines of code apart to ensure that this was the command that was having the issue:

     BluetoothClient client = null;
     BluetoothAddress adr = null;
     BluetoothEndPoint endpt = null;

    ...

     adr = ((BluetoothDeviceInfo)cboDevices.SelectedItem).DeviceAddress;
     endpt = new BluetoothEndPoint(adr, ServiceName);

     client = new BluetoothClient();
     client.Connect(endpt);

     

    After a bit, I gave up on this attempt and tried to run the DeviceListener code.  For this, I'm getting an error on the device "Assertion Failed: Unexpected exception creating factory 'InTheHand.Net.Bluetooth.Widcomm.WidcommBluetoothFactory, ex:System.MissingMethodException: Can't find PInvoke DLL '32feetWidcomm' at InTheHand.Net.Bluetooth.Widcomm.WidcommBtIf.Create() ... The source code shows an issue for the line:

    InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio.Mode = InTheHand.Net.Bluetooth.RadioMode.Discoverable.

    Now, reading through the forums, it sounds like this is expected as it's the Widcomm stack.

    So, is there another way I should be approaching my problem?  Again, my hope is to simply pass a string that I can parse out on one side or the other, so that the devices can communicate.  i.e. (a string formatted "Show:HelloWorld+Length:10+Unit:sec").

    Thanks.

    Filed under: , , ,
  • 02-06-2010 5:15 AM In reply to

    Re: Simple Bluetooth Transfer - Widcomm issues

    What library version are you using 2.4 or 2.5?  If 2.4, try 2.5 it might give a more precise error message.  Also try the config file enableing setting "reportAllErrors", see the Widcomm doc in the release for a template config file.

    So just to check you're using the native DLL from "Assemblies\CE2\WM5\"

    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.
  • 02-08-2010 11:48 AM In reply to

    • rorik
    • Top 500 Contributor
    • Joined on 02-05-2010
    • Toronto, Ontario, Canada
    • Posts 4

    Re: Simple Bluetooth Transfer - Widcomm issues

    Hi Alan,

    Thanks for the reply!  

    Yes, I'm using the DLLs from the "Assemblies\CE2\WM5\" folder.  To ensure the version I'm using, I re-downloaded version 2.5 and re-copied the files over ("32feetWidcomm.dll" & "InTheHand.Net.Personal.dll").  To ensure I have the files in the correct location, I've put both of the files in the debug folder, as well as the project folder (which is where I added the reference from).

    For the config file, I created the file and put it in the debug folder as well as the project folder (as I wasn't sure which location it was supposed to go).  

    The error I get is the same with or without the config file, and I don't see any log files (unless I'm looking in the wrong location).

    In examining the error, I drilled down on the error box details a bit more, and do have futher details regarding the error.  The details state the following:

    System.IO.IOException - "IOError on socket"

    InnerException ";SetSecurityLevel"

    StackTrace "   at InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommInterface.SetSecurityLevelClient(BTM_SEC securityLevel)
       at InTheHand.Net.Bluetooth.Widcomm.WidcommRfcommStream.BeginConnect(BluetoothEndPoint bep, String pin, AsyncCallback asyncCallback, Object state)
       at InTheHand.Net.Bluetooth.Widcomm.WidcommBluetoothClient.Connect_FillInPortCallback(IAsyncResult ar)
       at InTheHand.Net.AsyncResultNoResult.SetAsCompleted(Exception exception, Boolean completedSynchronously)
       at InTheHand.Net.AsyncResult`1.SetAsCompleted(BluetoothEndPoint result, Boolean completedSynchronously)
       at InTheHand.Net.Bluetooth.Widcomm.WidcommBluetoothClient.FillInPort_ServiceDiscoveryCallback(IAsyncResult ar)
       at InTheHand.Net.AsyncResultNoResult.SetAsCompleted(Exception exception, Boolean completedSynchronously)
       at InTheHand.Net.AsyncResult`1.SetAsCompleted(ISdpDiscoveryRecordsBuffer result, Boolean completedSynchronously)
       at InTheHand.Net.Bluetooth.Widcomm.WidcommBtInterface.HandleDiscoveryComplete()
       at InTheHand.Net.Bluetooth.Widcomm.WidcommBtIf.HandleDiscoveryComplete()"

     

    Thanks for your help!

  • 02-10-2010 5:57 AM In reply to

    Re: Simple Bluetooth Transfer - Widcomm issues

    I'll test that case when I next get a moment.  The Widcomm docs don't have any discussion of what threading it safe to use, so maybe we need to not start the connect from the discovery thread...

    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.
  • 02-13-2010 5:11 AM In reply to

    Re: Simple Bluetooth Transfer - Widcomm issues

    I've made a change so that the DiscoverDevices callback is raised on a thread-pool thread.  So now if there's any problem with reentrancy with Widcomm we avoid them.  That kinda looks like that was the problem here.  Hopefully this solves it for you.

    You can download the sources from codeplex and compile the new library for yourself.  (You just need the WM library, so ignore everything but the InTheHand.Net.Personal.CF2 project in the root.  It will compile as Debug no problem, so you can use that.  (To compile as Release, comment out the AssemblyKeyXxxx lines in Properties/AssemblyInfo.cs).  It'd be good to get confirmation that it is fixed. :-) )

    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.
  • 02-14-2010 11:52 AM In reply to

    • rorik
    • Top 500 Contributor
    • Joined on 02-05-2010
    • Toronto, Ontario, Canada
    • Posts 4

    Re: Simple Bluetooth Transfer - Widcomm issues

    Great!

    I won't get a chance to try this until tomorrow (Monday), but I'll let you know how it goes.

    Thanks.

  • 02-19-2010 3:39 PM In reply to

    • rorik
    • Top 500 Contributor
    • Joined on 02-05-2010
    • Toronto, Ontario, Canada
    • Posts 4

    Re: Simple Bluetooth Transfer - Widcomm issues

    Ok, I've managed to get the two devices talking, but I'm not sure which thing I did fixed it...I'll try to outline the major actions I did in case that helps anyone else.


    My setup:
      PC - Microsoft Stack
      Touch Pro 2 - Widcomm stack

    So, I think the important/major changes I made are as follows:

    1) I compiled the new .dll and put it in the correct directory, and re-added it to the project

    2) I played around with the "SetPin" - this caused some headaches!  I've ended up with:
      a) using an access key between the computer and device (when pairing)
      b) I use SetPin() from the device to the computer (talking to the Microsoft Stack)
      c) I don't use SetPin() from the computer (talking to the Widcomm Stack - I think this is expected as I believe I saw that the SetPin() function isn't yet supported for the Widcomm - is that correct?)
      d) Rebooted my computer (multiple times)

    3) I deleted the Touch Pro 2 device from the device manager on the PC, and re-added/connected it; set the access key (PIN) value, etc.

    I am now able to send messages from one device to another, however, it seems that I need to send the first message from the Touch Pro 2 to the computer, after which they can talk back and forth.  If I try to send the first message from the computer, I get an error stating that the device "actively refused" the request, at which point neither will talk to the other.

    Thanks Alan, for your help with this.

  • 02-22-2010 4:35 PM In reply to

    • lamle
    • Not Ranked
    • Joined on 01-30-2010
    • Posts 2

    Re: Simple Bluetooth Transfer - Widcomm issues

     HI,

    Can you post the source code here for reference pls.

    I am trying to send files between pc with MS stack and pc with Widcom stack using C#.

    When I add 32feetWidcomm.dll to project reference it cries that file cannot be added. Do you have sample code for communication between different stacks ? 

    Filed under:
  • 02-22-2010 7:03 PM In reply to

    Re: Simple Bluetooth Transfer - Widcomm issues

    Don't add the 32feetWidcomm.dll as a reference (its a native DLL not a .NET assembly).  Just copy it to the same folder as your application at run-time.  For the user-guide:

    To enable the Widcomm support, in brief the 32feetWidcomm.dll native DLL need to be present at runtime in the same folder as the main library assembly (InTheHand.Net.Personal.dll) and the application itself.  As a native DLL it cannot be referenced at compile-time like a normal managed .NET assembly

     See what heppens then... :-)

    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.
  • 02-23-2010 3:21 AM In reply to

    • lamle
    • Not Ranked
    • Joined on 01-30-2010
    • Posts 2

    Re: Simple Bluetooth Transfer - Widcomm issues

     Thank you for your reply.

     I will try to run those example to check if it works and will inform you soon.

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