Más contenido relacionado Similar a 20140802 Bluetooth を使って Universall App で大連携 (20) Más de Takayoshi Tanaka (20) 20140802 Bluetooth を使って Universall App で大連携16. RFCOMM Scenario: Send File as a Client(XAML)
RFCOMM Scenario: Receive File as a Server(XAML)
GATT Scenario: Retrieve Bluetooth LE Data(XAML)
GATT Scenario: Control a Bluetooth LE Thermometer Device(XAML)
Bluetooth for Windows Phone 8
【連載】Bluetooth LE (1) Bluetooth Low Energy の基礎
Bluetooth SMART デバイス(LE GATT Profile)と連携するWindows
Store Appsの開発
23. //appxmanifet で指定したServiceUUIDを使う
rfcommProvider = await RfcommServiceProvider.CreateAsync(
RfcommServiceId.FromUuid(BluetoothServiceUuid));
//Socket作成して、Clientからの接続を待機
socketListener = new StreamSocketListener();
socketListener.ConnectionReceived += OnConnectionReceived;
await socketListener.BindServiceNameAsync(rfcommProvider.ServiceId.AsString(),
SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);
//SDPに設定する部分は略
//Advertising開始
rfcommProvider.StartAdvertising(socketListener);
25. writer = new DataWriter(socket.OutputStream);
//送信するバイトの長さ+byte配列を書きこみ
writer.WriteUInt32((uint)Command.CommandLength);
writer.WriteBytes(Command.CommandBytes);
await writer.StoreAsync();
26. Bluetooth SMART デバイス(LE GATT Profile)と連携する
Windows Store Appsの開発
https://github.com/tanaka-takayoshi/TISensor.Rx
27. //SensorごとのUUIDを指定して端末を検出する
var selector = GattDeviceService.GetDeviceSelectorFromUuid(
new Guid(sensorServiceUuid));
var devices = await DeviceInformation.FindAllAsync(selector);
var device = devices.First();
//ID指定でサービスを作成
deviceService = await GattDeviceService.FromIdAsync(deviceInfo.Id);
//センサーを有効化 (センサーによっては書きこむ値が違う)
var configCharacteristic = deviceService.GetCharacteristics(
new Guid(sensorConfigUuid)).First();
await configCharacteristic.WriteValueAsync(new byte[] {1}.AsBuffer());
30. dataCharacteristic = deviceService.GetCharacteristics(
new Guid(sensorDataUuid)).First();
await dataCharacteristic.
WriteClientCharacteristicConfigurationDescriptorAsync(
GattClientCharacteristicConfigurationDescriptorValue.Notify);
dataCharacteristic.ValueChanged += (sender, args) =>
{
ReadRawData(args);
};