Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Developer
Posts: 2
Registered: ‎11-30-2008
My Device: Not Specified

Writing floating point number to ascii file


I have an application that reads incoming data from the Bluetooth port. The data is coming at 50Hz, and it is close to 90 bytes per sample.  After reading the data, the program does some real time processing in order to verify the checksum, then converts some bytes into several floating numbers (>20) per sample and then writes all this data to an output ASCII file.   An ASCII file is used so that it can be opened by Excel for analysis.  The problem I am having is that after a couple of  minutes, it seems that the Blackberry is not ready to receive data on the Bluetooth port and the external device that was sending data gets a buffer overflow and stops.  If I remove the code that writes the floating point numbers to the file, the input stream continues without interruption.  I believe the issue is writing the floating point numbers to the file.

I am using the Blackberry 8800 and Blackberry JDE


The following is some sections of code:


public class DataThread extends Thread { //Constructor public DataThread(){


try { fconn2= (FileConnection)Connector.open("file:///SDCard/BlackBerry/dataFile.txt" ) ; if (!fconn2.exists()){ fconn2.create(); // create the file if it doesn't exist } output2 = fconn2.openOutputStream((long)999999999); osw2= new OutputStreamWriter(output2); } catch(IOException ioex) { //Catch and re-throw the exception. throw new RuntimeException(ioex.toString()); } }//end of constructor


public void run(){ ... Read incoming data with _port.read(_receiveBuffer) ...analyse every bytes read. //For every sample, converts some bytes into floating point number (around 20 per sample): ... FloatingNumber = Float.intBitsToFloat(iTemp); _stringBuffer.append(FloatingNumber); //Append to the string buffer _stringBuffer.append(";") ; try{ string_to_write_to_file =_stringBuffer.toString(); osw2.write(string_to_write_to_file,0,Output_Write_String.length()); _stringBuffer.delete(0,Output_Write_String.length()); } catch (IOException ioex) { throw new RuntimeException(ioex.toString()); } }//run } //Class


 A would like to know what is the most efficient and fast way to write a large amount of floating point numbers to an ASCII file?


BlackBerry Development Advisor
Posts: 15,882
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Writing floating point number to ascii file

You could hold the data you are reading in a buffer, allowing your read thread to just read in the data.  Then, spawn a second thread that removes entries from this buffer, performs your processing and writes out to a file.  This can allow you to read and write at the same time.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.