bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

DevFound.Name Unicode Problem

Wed Mar 12, 2008 7:01 pm

Hi,

In a VB.NET demo, I have a listview that I use to maintain a list of all the bluetooth devices that I detect using Bluetools. I use this code:

lvi = .lstviewDevices.Items.Add(DevFound.Name)

to add every device I detect to the list. The problem occurs when I detect a phone that has a unicode name (arabic or hebrew). The name of the device is added as empty squares inside the listview.

I tried to add unicode names to the listview and it worked correctly, so I think that the DevFound.Name that is being received is incorrect.

I checked a name with four arabic letters (that should be represented by 8 bytes as unicode). I received a device name with 8 characters string, but the string seems to be incorrect. Can you please tell me how to fix this problem?

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: DevFound.Name Unicode Problem

Wed Mar 12, 2008 9:33 pm

Try some Unicode encoding function that is available in .NET. Maybe that can convert it to the correct codepage.

Regards,
Jonas

bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

RE: DevFound.Name Unicode Problem

Wed Mar 12, 2008 11:32 pm

Hi Jonas,

It has been a busy day for both of us, hasn't it?

I tried that already, but the weird thing is that the bytes I receive from the name string are all the same value except for the last one.

Is there any chance to take a look at this part of the code and just let me know what is the function that you're using to convert the device name from unicode (4 letters) into 8 characters. I think this function fails for some reason and returns 8 characters that are actually unfilled (uninitialized).

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: DevFound.Name Unicode Problem

Thu Mar 13, 2008 9:42 am

Apparently the Widcomm stack returns the name of detected bluetooth devices as ASCII and not Unicode.

There is no solution for this in the short run.

Regards,
Jonas

bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

RE: DevFound.Name Unicode Problem

Thu Mar 13, 2008 1:56 pm

Jonas,

I've modified the FindAndConnect Demo like this:

=======================================
' NOTE! Use Network.DiscoverDevicesAsync() for event driven lookup (async)
devices = nwork.DiscoverDevices()

Dim inx As Integer
For inx = 0 To devices.Length - 1
mybytes(0) = Asc(devices(inx).Name.Chars(0))
mybytes(1) = Asc(devices(inx).Name.Chars(1))
mybytes(2) = Asc(devices(inx).Name.Chars(2))
mybytes(3) = Asc(devices(inx).Name.Chars(3))
mybytes(4) = Asc(devices(inx).Name.Chars(4))
mybytes(5) = Asc(devices(inx).Name.Chars(5))
mybytes(6) = Asc(devices(inx).Name.Chars(6))
mybytes(7) = Asc(devices(inx).Name.Chars(7))

listDevices.Items.Add("test")
Next
========================================

And as you have mentioned above, I was expecting the bytes to be of different values that need to be converted somehow to unicode.

The problem is that this array has all the elements set to (63 ASCII, &H3F HEX). This shows that the name returned is incorrect because all the bytes have the same value. I would expect the even-indexed bytes to have the same value (they're the most significant bytes in the unicode values), but the odd bytes should definitely have different values.

I'm just hoping that you can take a look at the code and see how you handle the returned name from the Widcomm Stack until you set it as the device name. I’m sure there’s a conversion process here that is working correctly.

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: DevFound.Name Unicode Problem

Thu Mar 13, 2008 2:20 pm

The bytes are returned exactly like they are given by the Widcomm stack, but since the Widcomm stack for XP is returning only ASCII, maybe it simply can't read the name properly?

Regards,
Jonas

bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

RE: DevFound.Name Unicode Problem

Fri Mar 14, 2008 10:53 am

Jonas,

I'm not sure if this is correct.

I've just tried the WidComm software that came with my laptop (HP Pavilion) and in "My Bluetooth Places" I tried to do "Search for devices in range". My mobile is detected and the software returned the correct arabic name. So, I'm sure there's something wrong, what do you think?

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: DevFound.Name Unicode Problem

Fri Mar 14, 2008 11:17 am

It's not certain that the software that is made by Widcomm is built entirely from their SDK though. They probably have a lot of other tricks up their sleeve than they offer to the rest of the world.

In any case, BlueTools returns the result from the stack byte by byte.

Regards,
Jonas

bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

RE: DevFound.Name Unicode Problem

Sat Mar 15, 2008 12:53 am

Jonas,

Thank you for your answer, I understand that the Widcomm stack is sending the name of the device as multi-byte, not as unicode, but I can't understand why the bytes are of the same value. That's what I'm trying to find out.

Could you please be so kind and try to go through a short debug just to see why this is happening? I just need to know why the name is sent as multi-bytes with the same value for all the bytes.

If you want me to help you with this, maybe because you can't set your mobile name to unicode, you can send me a debug version of your dll, or maybe a dll that dumbs the name to the hard drive and I will send you the result.

thanks in advance.

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: DevFound.Name Unicode Problem

Sat Mar 15, 2008 1:17 am

I'll contact you off forum for this.

Regards,
Jonas

bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

RE: DevFound.Name Unicode Problem

Sat Mar 15, 2008 1:23 am

great! I will be waiting. thank you.

bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

RE: DevFound.Name Unicode Problem

Sun Mar 16, 2008 11:05 am

Hi Jonas,

Can we talk on the yahoo messenger? if yes, please use my email address to contact me. I'm online now.

bj_private
Posts: 35
Joined: Thu Sep 20, 2007 6:02 pm

RE: DevFound.Name Unicode Problem

Sun Mar 16, 2008 3:37 pm

Hi Jonas,

Can you send me a dll that will dumb a file to the hard drive with the device name (as binary) that's returned from the widcomm stack ? If yes, I can run that dll here and check the result out.

simonc
Posts: 2
Joined: Mon Oct 20, 2008 3:27 pm

RE: DevFound.Name Unicode Problem

Mon Oct 20, 2008 3:33 pm

Did you find a solution to this? I'm am experiencing the exact same problem using your software and the Widcomm stack... Arabic named devices are being returned as strings that are twice the length of their Arabic names (persumably some unicode transcoding problem) with all characters set to 63 / 0x3F / '?'.

The arabic named devices appear correctly when viewed using the Microsoft 'view devices in range' so long as Windows regional settings has been changed to use Arabic to display settings for non-unicode applications.

Clearly the device name can be returned in Arabic format... but how?

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: DevFound.Name Unicode Problem

Mon Oct 20, 2008 3:48 pm

RemoteDevice.UseUnicode is a new property.
Set it to True and BlueTools will attempt to convert the name to unicode (if possible)

Regards,
Jonas

Return to “BlueTools”