开发者

Problem with C# and 32feet.NET Bluetooth Library

I just started bluetooth programming. I need to come up with an desktop application in C# that receives images from a J2ME application.

Before beginning...I just tried some code snippets from 32feet user guide...the guide is in VB.NET.

The VB.NET works fine...but my C# is not working correctly.

Here is the VB.NET snippet

Public Shared Sub find()
    Dim btClient As New InTheHand.Net.Sockets.BluetoothClient
    Dim bdi As BluetoothDeviceInfo() = btClient.DiscoverDevices()
    Dim device As BluetoothDeviceInfo = bdi(0)
    Dim addr As BluetoothAddress = device.DeviceAddress
开发者_C百科    Dim name As String = device.DeviceName
    Console.WriteLine(name)
End Sub

And here is the C# conversion

public static void Main()
    {
        BluetoothClient cli = new BluetoothClient();
        BluetoothDeviceInfo[] peers = cli.DiscoverDevices();
        BluetoothDeviceInfo device = peers[0];
        String name = device.DeviceName;
        Console.WriteLine(name);
        Console.Read();
    }

The C# gives me an ArrayIndexoutofBOund exception...meaning that no devices are discovered.

Any suggestions?? Thank you for help.


My guess is that the two programs are somehow using different versions of the library. And the C# compiler is using an older version of the library and copying in to the output folder. Check what versions the library assembly is in the same folder as each .exe.

Likely also that Widcomm or BlueSoleil is being used on your machine rather that the Microsoft Bluetooth stack. If its Widcomm make sure the 32feetWidcomm.dll file is there too.


Your C# code looks fine to me.

Are you sure that there are bluetooth device(s) attached to your PC when you ran the C# code? I realise that may sound a simplistic response, but it could be that, when you ran the C# code, there was a problem with the bluetooth connection or device?

Other then that, if the C# code is calling the exact same code that VB.NET version is calling, I honestly can't see why there should be a difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜