Posts: 3
Joined: Tue Nov 03, 2009 4:43 pm
Location: USA

BlueTools - Optimization

Wed Jan 27, 2010 3:47 pm

I need help optimizing my BlueTools TX/RX methods in my application. First off the application does not use BlueTools asynchronously. I have TX/RX methods that call the Bluetools RemoteService.Stream.Write and RemoteService.Stream.Read methods as shown below.
NOTE: mBlueToolsRemoteService is of type Franson.BlueTools.RemoteService
lBytesRead = mBluetoothRemoteService.Stream.Read(lByteBuffer, 0, lBytesToRead)
mBlueToolsRemoteService.Stream.Write(lByteArray, 0, lByteArray.Length)

I’m using an oscilloscope to monitor the IO stream on our device, and the pulses fluxuate drastically. When monitoring our PC verstios, the pulses are almost a constatn 25ms between TX/RX. With my BlutTools mobile application, I’ve yet to get a TX/RX pulse less than 100ms and as I mentioned it fluxates anywhere from 100ms to 200ms. My application knows when data should be in the BlueTools.Stream as it only calls this method after TX. Basically, after calling TX, I loop until I’ve RX the entire message and verified its check sum. I suppected that I was polling, so I added a 1ms sleep after each call to the Stream.Read. System.Theading.Thead.Sleep(1). However, as everyone knows this 1ms is device dependant and based on the hardware platform. I suspect this is why I’m seeing a fluxuation between TX/RX. The 1ms sleep does improved TX/RX speed, but not the fluxation, and I’m still no where close to my 25ms TX/RX target.
You mentioned in this thread (When is it necessary to use Stream.Flush()?) that the first step in optimization is to use a System.IO.BufferedStream, and asked the thread owner to post a new thread on this topic. I couldn’t find this new tread so I thought I would start one if nothing else to get the link to an existing post regarding BlutTools IO optimization.
With that said I would suspect you may be suggesting creating a System.IO.BufferedStream and setting it equal to RemoteService.Stream and use the buffered stream for TX/RX.

mBufferredStream of type System.IO.BufferedStream
mBufferredStream = mBlueToolsRemoteService.Stream

TX/RX the replace calls to RemoteService.Stream.Read and RemoteService.Stream.Write with mBufferredStream.

Am I on the right track or does anyone else have any suggestion or a better solution.



Return to “BlueTools”