I am creating an Android application which connects my device to an embedded chip via Bluetooth. I am modeling my design after a program which already exists on the Palm Pilot( written in C ). I am using the Bluetooth Chat example to get my code running, and have gotten stuck. I am pretty new to the whole coding world still, and am confusing myself slightly.
I want to convert the following code from C to Java....
SrmReceive(portId,&c,1,(t*5L*Sec)/1000L,&err)
The only real problem I'm having here, is the third parameter. The 1
represents the number of bytes to receive
, as stated in the palm docs, and is of type UInt32
.
The code from the Bluetooth Chat example has the following function for reading in data...
public void run() {
Log.i( TAG, "BEGIN mConnectedThread" );
buffer = new byte[1024];
int bytes;
// Keep listening to the InputStream while connected
while( true ) {
try {
// Read from the InputStream
bytes = mmInStream.read( buffer );
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage( BtHelperHandler.MessageType.READ, bytes, buffer).sendToTarget();
} catch ( IOException e ) {
Log.e( TAG, "disconnected", e );
sendErrorMessage( 1 );
break;
}
}
}
I want to change the run()
method to have a parameter for the certain number of bytes to read. I am slightly confused as to what to do. I was thinking...
public void run( int size ) {
buffer = new byte[size];
...
}
But that doesn't seem right to me, I feel like I'm mixing up my definition of byte. May sound stupid but I'm not confident with this information enough yet. It is confusing to me to convert a UInt32
to java, since java does not have an equivalent type. If anyone knows please let me know.