Exemple #1
0
        public void Reset()
        {
            if (_connectThread != null)
            {
                _connectThread.Cancel();
                _connectThread = null;
            }

            for (int i = 0; i < _writeThread.Count; i++)
            {
                _writeThread [i].Cancel();
                _writeThread.RemoveAt(i);
            }

            for (int i = 0; i < _readThread.Count; i++)
            {
                _readThread [i].Cancel();
                _readThread.RemoveAt(i);
            }

            if (_listenThread != null)
            {
                _listenThread.Cancel();
                _listenThread = null;
            }

            _state = EnConnectionState.STATE_NONE;
        }
Exemple #2
0
        public void ConnectAsSlave(BluetoothDevice device)
        {
            //stops all existing thread
            Reset();

            //sets the state to CONNECTING and send message to indicate this change
            _state = EnConnectionState.STATE_CONNECTING;
            this.ObtainMessage((int)EnLocalMessageType.MESSAGE_STATE_CHANGE, (int)EnConnectionState.STATE_CONNECTING, -1).SendToTarget();

            // Start the thread to connect with the given device
            _connectThread = new BTConnectThread(device, MY_UUID);
        }
Exemple #3
0
        public void ConnectAsMaster()
        {
            //stops listening thread
            StopListen();

            // Start the thread to listen on a BluetoothServerSocket
            _listenThread = new BTListenThread(NAME, MY_UUID);

            //sets the state on STATE_LISTEN and send message to indicate this change
            _state = EnConnectionState.STATE_LISTEN;
            this.ObtainMessage((int)EnLocalMessageType.MESSAGE_STATE_CHANGE, (int)EnConnectionState.STATE_LISTEN, -1).SendToTarget();
        }
Exemple #4
0
        internal void ConnectedToMaster(BluetoothSocket socket, BluetoothDevice device)
        {
            //sets the state to CONNECTED_SLAVE
            _state = EnConnectionState.STATE_CONNECTED_SLAVE;

            // Start the thread to perform read service
            _readThread.Add(new BTReadThread(socket));

            // Start the thread to perform write service
            _writeThread.Add(new BTWriteThread(socket, _monitorSlave));

            //sends a message to the indicate the slave connection to a device
            this.ObtainMessage((int)EnLocalMessageType.MESSAGE_DEVICE_ADDR, (int)EnConnectionState.STATE_CONNECTED_SLAVE, -1, device.Address).SendToTarget();
        }
Exemple #5
0
        internal void ConnectedToSlave(BluetoothSocket socket, BluetoothDevice device)
        {
            //sets the state to CONNECTED_MASTER
            _state = EnConnectionState.STATE_CONNECTED_MASTER;

            // Start the thread to perform read service
            _readThread.Add(new BTReadThread(socket));

            // Start the thread to perform write service
            _writeThread.Add(new BTWriteThread(socket));

            //sends a message to the indicate the master connection to a device
            this.ObtainMessage((int)EnLocalMessageType.MESSAGE_DEVICE_ADDR, (int)EnConnectionState.STATE_CONNECTED_MASTER, -1, device.Address).SendToTarget();

            //stop listen thread
            StopListen();
        }