Beispiel #1
0
        //private static int pport=5005;

        /// <summary>
        /// The constructor sets up a Bluetooth stream object with refrences to the send and receive buffers
        /// </summary>
        /// <param name="buffer">Handle to a circular receive buffer</param>
        /// <param name="sbuffer">Handle to a circular send buffer</param>
        /// <param name="address">A machine independent (Little or Big Endian) byte array of the bluetooth address </param>
        /// <param name="pin">A pin for the remote bluetooth device</param>
        public MicrosoftBluetoothStream(CircularBuffer buffer, CircularBuffer sbuffer, byte[] address, string pin)
            : base(buffer, sbuffer, address, pin)
        {
            try
            {
#if (PocketPC)
                _RemoteEP = new MicrosoftBluetoothEndPoint(this.address, BluetoothStream._SerialPort);
#else
                BluetoothAddress btaddress = new BluetoothAddress(this.address);
                //Set BT Device Address

                //Set BT Device Pin
                //BluetoothSecurity.SetPin((BluetoothAddress)btaddress, "1234");

                // Create a connection channel specifying the Bluetooth-Serial end-points
                _RemoteEP = new BluetoothEndPoint((BluetoothAddress)btaddress, BluetoothService.SerialPort);
#endif
            }
            catch (Exception e)
            {
                CurrentWockets._LastError        = ErrorCodes.REMOTE_ENDPOINT_CREATION_FAILED;
                CurrentWockets._LastErrorMessage = "Failed to setup connection endpoint for " + this._HexAddress + ". " + e.ToString();
                if (CurrentWockets._Configuration._SoftwareMode == SoftwareConfiguration.DEBUG)
                {
                    Logger.Error("MicrosoftBluetoothStream: Constructor: <" + ErrorCodes.REMOTE_ENDPOINT_CREATION_FAILED + ">: Failed to setup connection endpoint for " + this._HexAddress + ". " + e.ToString());
                }
                throw new Exception("MicrosoftBluetoothStream: Constructor: <" + ErrorCodes.REMOTE_ENDPOINT_CREATION_FAILED + ">: Failed to setup connection endpoint for " + this._HexAddress + ". " + e.ToString());
            }
        }
        /// <summary>
        /// Compares two <see cref="BluetoothEndPoint"/> instances for equality.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            MicrosoftBluetoothEndPoint bep = obj as MicrosoftBluetoothEndPoint;

            if (bep != null)
            {
                return(this.Address.Equals(bep.Address) && this.Service.Equals(bep.Service));
            }

            return(base.Equals(obj));
        }