-
Notifications
You must be signed in to change notification settings - Fork 4
Bluetooth
This is the base class for BluetoothServer and BluetoothClient.
public abstract class Bluetooth| 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 |
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.
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)
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.
Indicates whether the Bluetooth adapter is enabled or not.
public static bool IsEnabled { get; }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; }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; }Returns a list of the devices paired to the current device.
public static List<BluetoothDevice> GetBondedDevices()Gets the device of the specified MAC address.
public static BluetoothDevice GetDiscoveredDevices(string)Returns a list of the current discovered devices. This list starts to fill after [SearchDevices()] is called.
public static List<BluetoothDevice> GetDiscoveredDevices()Returns the UUID of a serial port.
public static string GetSerialUUID()This shows the user a messagebox requesting to enable Bluetooth.
public void RequestEnableBluetooth()This shows the user a messagebox requesting to make the device discoverable for 300 seconds.
public void RequestEnableDiscoverability()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()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";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";A message sent to the ServerObject indicating that the device is discoverable.
public const string MODE_DISCOVERABLE = "bluetooth.mode.discoverable";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";A message sent to the ServerObject indicating that the device is neither connectable nor discoverable.
public const string MODE_NONE = "bluetooth.mode.none";A message sent to the ServerObject indicating that the Bluetooth adapter has been turned on.
public const string ON = "bluetooth.on";A message sent to the ServerObject indicating that the Bluetooth adapter has been turned off.
public const string OFF = "bluetooth.off";A message sent to the ServerObject indicating that a socket has successfully established a connection.
public const string SOCKET_CONNECTED = "socket.connected";