Created
April 23, 2018 09:34
-
-
Save peterfoot/ea07a026a6c9d978fd0f27c2431bc745 to your computer and use it in GitHub Desktop.
Sample Bluetooth printing from Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var devices = DeviceInformation.FindAll(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); | |
var deviceInfo = devices[0]; // this makes some assumptions about your paired devices so really the results should be enumerated and checked for the correct device | |
var device = BluetoothDevice.FromDeviceInformation(deviceInfo); | |
var serResults = device.GetRfcommServices(BluetoothCacheMode.Cached); | |
foreach(RfcommDeviceService serv in serResults.Services) | |
{ | |
if(serv.ServiceId == RfcommServiceId.SerialPort) | |
{ | |
var stream = serv.OpenStream(); | |
byte[] buff = System.Text.Encoding.ASCII.GetBytes("Testing\r\n"); | |
stream.Write(buff, 0, buff.Length); | |
stream.Flush(); | |
stream.Close(); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment