Author Topic: Problem with write  (Read 2449 times)

Offline mplopes

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Problem with write
« on: March 08, 2010, 08:18:49 PM »
Hi all.

I've the following code to write text to a bluetooth listener:

Code: [Select]
            wcl.wclClient client = new wcl.wclClient();
            client.Transport = wcl.wclClientTransport.ctBluetooth;
            client.BluetoothParams.Radio = GetSelectedRadio();
            client.BluetoothParams.Address = GetSelectedDevice().Address;
            client.BluetoothParams.Channel = Service.Channel;
            client.BluetoothParams.Service = new Guid("60047B27-C0C9-49d3-869C-B11A124DDB3B");
            client.BluetoothParams.Authentication = false;
            client.BluetoothParams.Encryption = false;

            client.Connect();
            string teste = "lopes";
            uint nr = (uint)teste.Length;
            wcl.wclErrors.wclShowError(client.Write(UTF8Encoding.UTF8.GetBytes(teste), nr));
            client.Dispose();

The problem is that in the listener, I've always no data available on the stream:

Code: [Select]
BluetoothClient bc = bl.AcceptBluetoothClient();
Stream s = bc.GetStream();

Can someone help me on this?

Thanks in advance.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Problem with write
« Reply #1 on: March 08, 2010, 08:41:54 PM »
Hi,

WCL Is asynchronouse library. You can not Write immediately after connect call. You have to wait when connection will be established (OnConnect event fires) and only then you can write something.

Also, what is Listener?

Offline mplopes

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Problem with write
« Reply #2 on: March 08, 2010, 10:05:08 PM »
Great! Thanks!

Haven't notice that. It's working properly now.

BluetoothListener is from the InTheHand framework which I'm using to create an application to the windows mobile.

Offline pshaw

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
Re: Problem with write
« Reply #3 on: May 24, 2010, 04:56:16 AM »
I have the same problem.  Do you have the sample code you used to wait for the OnConnect event to fire?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: Problem with write
« Reply #4 on: May 24, 2010, 05:15:46 AM »
Hi,

WCL includes samples shows how to use it. BluetoothClient demo should help you.

 

Sitemap 1 2 3 4 5 6 7 8 9