本文整理匯總了Java中com.bitalino.comm.BITalinoDevice類的典型用法代碼示例。如果您正苦於以下問題:Java BITalinoDevice類的具體用法?Java BITalinoDevice怎麽用?Java BITalinoDevice使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BITalinoDevice類屬於com.bitalino.comm包,在下文中一共展示了BITalinoDevice類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doInBackground
import com.bitalino.comm.BITalinoDevice; //導入依賴的package包/類
@Override
protected Void doInBackground(Void... paramses) {
try {
// Let's get the remote Bluetooth device
final String remoteDevice = macAddress;
final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
dev = btAdapter.getRemoteDevice(remoteDevice);
/*
* Establish Bluetooth connection
*
* Because discovery is a heavyweight procedure for the Bluetooth adapter,
* this method should always be called before attempting to connect to a
* remote device with connect(). Discovery is not managed by the Activity,
* but is run as a system service, so an application should always call
* cancel discovery even if it did not directly request a discovery, just to
* be sure. If Bluetooth state is not STATE_ON, this API will return false.
*
* see
* http://developer.android.com/reference/android/bluetooth/BluetoothAdapter
* .html#cancelDiscovery()
*/
Log.d(TAG, "Stopping Bluetooth discovery.");
btAdapter.cancelDiscovery();
sock = dev.createRfcommSocketToServiceRecord(MY_UUID);
sock.connect();
BITalinoDevice bitalino = new BITalinoDevice(1000, new int[]{0, 1, 2, 3, 4, 5});
Log.i(TAG, "Connecting to BITalino [" + remoteDevice + "]..");
bitalino.open(sock.getInputStream(), sock.getOutputStream());
Log.i(TAG, "Connected.");
// get BITalino version
Log.i(TAG, "Version: " + bitalino.version());
// start acquisition on predefined analog channels
bitalino.start();
// read n samples
final int numberOfSamplesToRead = 1000;
Log.i(TAG, "Reading " + numberOfSamplesToRead + " samples..");
while (!isCancelled()) {
BITalinoFrame[] frames = bitalino.read(numberOfSamplesToRead);
publishProgress(frames);
}
} catch (Exception e) {
Log.e(TAG, "There was an error.", e);
}
return null;
}