athma
Posts: 5
Joined: Tue Nov 25, 2008 6:46 pm

sending data to PC

Tue Nov 25, 2008 7:57 pm

Hi,

In a nutshell, following is my requirement:

1. I want to send some data to my PC from my Windows Mobile device. Since the amount of data is not gonna be huge I thought I could do it over Bluetooth. In the PC I use PortKey (http://www.barcodehq.com/portkey.html) to listen into the serial port. I will have another application in PC which will interface with PortKey and takes whatever the data I send from my WM device

2. In WM device I would develop an application in .Net CF (this should be written in .Net CF because apart from sending data I will be using some Webservice stuff in this app so using Webservice in a C++ or MFC based app is quite painful)

3. In the PC I (mostly) would use PortKey, unless I have another easy solution to extract data that I send from my Windows Mobile device.

I've downloaded 'Franson Bluetools'. I see some samples under 'dotNetCF200' folder. I want to know given this requirement which sample is close enough and I can use to get on with the solution.

Thanks.
Athma.

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

RE: sending data to PC

Wed Nov 26, 2008 1:14 am

Depends on if your pocket device will be the client or the server.
FindAndConnect is a client sample and SimpleService is a server sample.

Regards,
Jonas

athma
Posts: 5
Joined: Tue Nov 25, 2008 6:46 pm

RE: sending data to PC

Sun Nov 30, 2008 9:09 pm

May be I didn't put my question right. Actually as I've explained I need to send some bytes from WM device to my desktop PC. Actually in my previous post I have said some stuff about using PortKey but if that is not required to get the byte across I don't use it.

Once again my requirement is to send some bytes from Windows Mobile device and receive it in the PC. Please suggest me how I can do this.

Thanks.
Athma.

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

RE: sending data to PC

Sun Nov 30, 2008 9:10 pm

Look at the FindAndConnect sample.
When it opens a Stream you can write data to that Stream to send them to the remove device.

Regards,
Jonas

athma
Posts: 5
Joined: Tue Nov 25, 2008 6:46 pm

RE: sending data to PC

Sun Nov 30, 2008 9:31 pm

Hi Jonas, Thanks very much for your unbelievably fast response. I really appreciate that.

Excuse me... though I have good programing experience, I don't have any knowledge in the Networking, BT, ... areas. I'm an application programmer.

So I take your suggestion to use 'FindAndConnect' sample application is on the WM device side. Correct me if I'm wrong.

In the FindAndConnect sample, When I click on the 'Discover' button, I see my PC in the 'Network' list. When I select it and I see

COM7
Voic gateway
File Transfer Service
Object Push Service
Imaging

in the Device list. When I select 'COM7' from the list, I was asked for pwd in both PC and WM device. Once I enter that then I see the status change from 'Stream not open' to 'Receiving data'.

Now where should I write data and how would I send it to PC? (Sorry if this question sounds stupid. But I tried my level best to figure this myself but the more I think the more I get confused)

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

RE: sending data to PC

Sun Nov 30, 2008 10:06 pm

Receiving data means that the FindAndConnect sample is reading from the Stream.
The sample in itself doesn't have any place where you can write data, you have to add this yourself.
But the same Stream that you are now reading data from:

Code: Select all

currentStream = currentService.Stream;
you can now use to write data just like you would any other .NET Stream.

Regards,
Jonas

athma
Posts: 5
Joined: Tue Nov 25, 2008 6:46 pm

RE: sending data to PC

Mon Dec 01, 2008 12:19 am

ThankQ Jonas.

In the constructor I do the following to set the byte data in 'm_buffer'

m_buffer = new byte[25]; // Buffer to read data into
string strBuffer = "Hi Athma";
for (int count = 0; count < strBuffer.Length; count++)
m_buffer[count] = (byte)strBuffer[count];

Like I mentioned in my earlier post from the 'Device' list I select 'COM7' (here I don't understand why it is COM7 why not COM1-4)

In the 'serviceList_SelectedIndexChanged' event handler, under the 'try' block I did this...

currentService.Stream.Write(m_buffer, 0, m_buffer.Length);
closeConnection.Enabled = true;
serviceList.Enabled = false;
lStatus.Text = "Writinging data...";

I don't get any exception or anything. So I assume my data is being written correct on the selected device port. Could you please tell me a simple way to find whether the data I sent from my WM device really reaching the other end?

I know I'm pushing this to you beyond belief. But all I need is to prove that I can send data from WM device to PC using franson bluetools once this is done then, I will probably hand over my finding to my boss then he will find proper resource and get on with this project.

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

RE: sending data to PC

Mon Dec 01, 2008 12:39 am

It's COM7 because that's what the remote device is saying the name is. (COM7 is usually the one specified for bluetooth if I recall correctly)

You can only "really" know if the data reached the other end if you actually read it out of the Stream on the other side. You need to use some software to read the data off COM7 (perhaps that PortKey that you talked about earlier)

Regards,
Jonas

athma
Posts: 5
Joined: Tue Nov 25, 2008 6:46 pm

RE: sending data to PC

Mon Dec 01, 2008 7:15 pm

Hi Jonas, Now I have an MFC application which can read from the port COM7 and display whatever it is available in that port. But, from my Windows Mobile device FindAndConnect application over BlueTooth when I write in the COM7 though I set to write the complete string it writes only one byte at a time.

This is what I do:
In the constructor I do the following to set the byte data in 'm_buffer'

m_buffer = new byte[25]; // Buffer to read data into
string strBuffer = "Hi Athma";
for (int count = 0; count < strBuffer.Length; count++)
m_buffer[count] = (byte)strBuffer[count];

I 'Discover' and from the 'Network' list I select my PC and from the 'Device' list I select 'COM7'.

I've modified the 'FindAndConnect' application and added a button 'Write'. In the click event handler of that button I do the following:

if (currentService != null)
{
if (currentStream != null)
{
currentStream.Close();
currentStream = null;
}
currentService = null;
}

// Attempt to connect to the service
//

// Get service object from list box
currentService = (RemoteService)serviceList.SelectedItem;

try
{
currentService.Stream.Write(m_buffer, 0, m_buffer.Length);
closeConnection.Enabled = true;
serviceList.Enabled = false;
lStatus.Text = "Data written...";
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
currentService = null;
}

Once I hit the 'Write' button in my PC using the MFC application when I read available bytes in that port I get 'H'. Say in the F&C app I hit the 'Write' button couple times and read that on the other side I get 'Hi'. So to get the complete string on the other side I have to hit the 'Write' button 8 times.

Now, can you tell me what am I doing wrong? Why it is writing only one byte at a time?

I guess this is the last piece of the puzzle. Once this is addressed then I hope that I'll be all set.

Thanks.
Athma.

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

RE: sending data to PC

Mon Dec 01, 2008 11:15 pm

A transfer over bluetooth is not instantaneous, so depending on how your program is reading data off the Stream you cannot expect the entire buffer to be there as you write it.
On the other hand, if you hit Write 8 times you are sending the buffer 8 times and the data should certainly have reached the other end by that time.

So in short, you need to make sure that your server side application is reading until the Stream is empty (and until it has read as many bytes as you are sending).

Regards,
Jonas

Return to “BlueTools”