Skip to content
This repository was archived by the owner on Nov 22, 2021. It is now read-only.

Bluetooth

Víctor Daniel Guevara edited this page Aug 9, 2020 · 6 revisions

This is the base class for BluetoothServer and BluetoothClient.

public abstract class Bluetooth

Methods summary

Method Action
GetBondedDevices() Returns a list with the devices paired with the device
GetDevice(string) Gets the device of the specified MAC address
GetDiscoveredDevices() Returns a list with the current discovered devices
GetSerialUUID() Returns the UUID of a serial port
RequestEnableBluetooth() Request the user to enable the Bluetooth adapter
RequestEnableDiscoverability() Request the user to make the device discoverable for 300 seconds
SearchDevices() Starts an asynchronous operation to search for nearby Bluetooth devices

Events

Bluetooth.MessageReceived

Raised when a message is received.

public event EventHandler<MessageReceivedEventArgs> MessageReceived;

It takes a MessageReceivedEventArgs as the event arguments, which has the following fields:

  • BluetoothDevice Sender: who sent the message.
  • string message: the message sent.

Bluetooth.ModeChanged

Raised when the bluetooth discoverability is changed.

public event EventHandler<BluetoothModeChangedEventArgs> ModeChanged;

BluetoothModeChangedEventArgs has the following fields:

  • BluetoothMode mode: the new discoverability mode (Possible values are BluetoothMode.NONE, BluetoothMode.DISCOVERABLE, BluetoothMode.CONNECTABLE)

Bluetooth.StateChanged

Raised when the state of the Bluetooth adapter is changed.

public event EventHandler<BluetoothStateChangedEventArgs> StateChanged;

BluetoothStateChangedEventArgs has the following fields:

  • bool IsOn: whether the BluetoothAdapter is on.

Properties

Bluetooth.IsEnabled

Indicates whether the Bluetooth adapter is enabled or not.

public static bool IsEnabled { get; }

Bluetooth.PlayerObject

This is the name of the GameObject that the Bluetooth data is going to be sent to. This GameObject must have one or more scripts containing a method with the signature void OnMessage(string). The data is going to be sent through the string.

public string PlayerObject { get; set; }

Bluetooth.ServerObject

This is the name of the GameObject that the Bluetooth status is going to be sent to. This GameObject must have one or more scripts containing a method with the signature void OnMessage(string). The status is going to be sent through the string.

public string ServerObject { get; set; }

Methods

Bluetooth.GetBondedDevices()

Returns a list of the devices paired to the current device.

public static List<BluetoothDevice> GetBondedDevices()

Bluetooth.GetDevice(string)

Gets the device of the specified MAC address.

public static BluetoothDevice GetDiscoveredDevices(string)

Bluetooth.GetDiscoveredDevices()

Returns a list of the current discovered devices. This list starts to fill after [SearchDevices()] is called.

public static List<BluetoothDevice> GetDiscoveredDevices()

Bluetooth.GetSerialUUID()

Returns the UUID of a serial port.

public static string GetSerialUUID()

Bluetooth.RequestEnableBluetooth()

This shows the user a messagebox requesting to enable Bluetooth.

public void RequestEnableBluetooth()

Bluetooth.RequestEnableDiscoverability()

This shows the user a messagebox requesting to make the device discoverable for 300 seconds.

public void RequestEnableDiscoverability()

Bluetooth.SearchDevices()

This starts an asynchronous process of discovering devices. When a device is discovered, the ServerObject receives the message "bluetooth.found.device", where device is the MAC Address of the device found.

public static void SearchDevices()

Constants

Bluetooth.COULD_NOT_READ

A message sent to the ServerObject indicating that an error occurred when reading from a socket.

public const string COULD_NOT_READ = "socket.error.COULD_NOT_READ";

Bluetooth.COULD_NOT_WRITE

A message sent to the ServerObject indicating that an error occurred when writing to a socket.

public const string COULD_NOT_WRITE = "socket.error.COULD_NOT_WRITE";

Bluetooth.MODE_DISCOVERABLE

A message sent to the ServerObject indicating that the device is discoverable.

public const string MODE_DISCOVERABLE = "bluetooth.mode.discoverable";

Bluetooth.MODE_CONNECTABLE

A message sent to the ServerObject indicating that other devices can connect to the device but it is not discoverable.

public const string MODE_CONNECTABLE = "bluetooth.mode.connectable";

Bluetooth.MODE_NONE

A message sent to the ServerObject indicating that the device is neither connectable nor discoverable.

public const string MODE_NONE = "bluetooth.mode.none";

Bluetooth.ON

A message sent to the ServerObject indicating that the Bluetooth adapter has been turned on.

public const string ON = "bluetooth.on";

Bluetooth.OFF

A message sent to the ServerObject indicating that the Bluetooth adapter has been turned off.

public const string OFF = "bluetooth.off";

Bluetooth.SOCKET_CONNECTED

A message sent to the ServerObject indicating that a socket has successfully established a connection.

public const string SOCKET_CONNECTED = "socket.connected";