Пример #1
0
        /// <summary>
        /// Create a client port for connection to a remote device.  Auto allocates a port from the COM0-9 range.
        /// </summary>
        /// <param name="endPoint">Remote device to connect to.</param>
        /// <returns></returns>
        public static BluetoothSerialPort CreateClient(BluetoothEndPoint endPoint)
        {
            BluetoothSerialPort bsp = new BluetoothSerialPort("COM", 9);

            bsp.pep.flocal      = false;
            bsp.pep.device      = endPoint.Address.ToInt64();
            bsp.pep.uuidService = endPoint.Service;

            for (int iPort = 8; iPort > -1; iPort--)
            {
                try
                {
                    bsp.Register();
                    break;
                }
                catch
                {
                    bsp.portIndex = iPort;
                }
            }
            if (bsp.portIndex == 0)
            {
                throw new SystemException("Unable to create a Serial Port");
            }
            return(bsp);
        }
Пример #2
0
		/// <summary>
		/// Create a virtual server port to listen for incoming connections.
		/// </summary>
		/// <param name="portName">Port name e.g. "COM4"</param>
		/// <param name="service">Bluetooth service to listen on.</param>
		/// <returns></returns>
		public static BluetoothSerialPort CreateServer(string portName, Guid service)
		{
            string portPrefix;
            int portIndex;
            SplitPortName(portName, out portPrefix, out portIndex);

			BluetoothSerialPort bsp = new BluetoothSerialPort(portPrefix, portIndex);
			bsp.pep.Local = true;
			bsp.pep.Service = service;
			bsp.Register();
			return bsp;
		}
Пример #3
0
        /// <summary>
        /// Create a virtual server port to listen for incoming connections.
        /// </summary>
        /// <param name="portName">Port name e.g. "COM4"</param>
        /// <param name="service">Bluetooth service to listen on.</param>
        /// <returns></returns>
        public static BluetoothSerialPort CreateServer(string portName, Guid service)
        {
            string portPrefix;
            int    portIndex;

            SplitPortName(portName, out portPrefix, out portIndex);

            BluetoothSerialPort bsp = new BluetoothSerialPort(portPrefix, portIndex);

            bsp.pep.flocal      = true;
            bsp.pep.uuidService = service;
            bsp.Register();
            return(bsp);
        }
Пример #4
0
        /// <summary>
        /// Create a client port for connection to a remote device.
        /// </summary>
        /// <param name="portName">Port name e.g. "COM4"</param>
        /// <param name="endPoint">Remote device to connect to</param>
        /// <returns>A BluetoothSerialPort.</returns>
        public static BluetoothSerialPort CreateClient(string portName, BluetoothEndPoint endPoint)
        {
            string portPrefix;
            int    portIndex;

            SplitPortName(portName, out portPrefix, out portIndex);
            BluetoothSerialPort bsp = new BluetoothSerialPort(portPrefix, portIndex);

            bsp.pep.flocal      = false;
            bsp.pep.device      = endPoint.Address.ToInt64();
            bsp.pep.uuidService = endPoint.Service;

            bsp.Register();

            return(bsp);
        }
Пример #5
0
 /// <summary>
 /// Create a virtual server port to listen for incoming connections. Auto allocates a port from the COM0-9 range.
 /// </summary>
 /// <param name="service">Service GUID to listen on.</param>
 /// <returns></returns>
 public static BluetoothSerialPort CreateServer(Guid service)
 {
     BluetoothSerialPort bsp = new BluetoothSerialPort("COM", 9);
     bsp.pep.Local = true;
     bsp.pep.Service = service;
     for (int iPort = 8; iPort > -1; iPort--)
     {
         try
         {
             bsp.Register();
             break;
         }
         catch
         {
             bsp.portIndex = iPort;
         }
     }
     return bsp;
 }
Пример #6
0
        /// <summary>
        /// Create a virtual server port to listen for incoming connections. Auto allocates a port from the COM0-9 range.
        /// </summary>
        /// <param name="service">Service GUID to listen on.</param>
        /// <returns></returns>
        public static BluetoothSerialPort CreateServer(Guid service)
        {
            BluetoothSerialPort bsp = new BluetoothSerialPort("COM", 9);

            bsp.pep.flocal      = true;
            bsp.pep.uuidService = service;
            for (int iPort = 8; iPort > -1; iPort--)
            {
                try
                {
                    bsp.Register();
                    break;
                }
                catch
                {
                    bsp.portIndex = iPort;
                }
            }
            if (bsp.portIndex == 0)
            {
                throw new SystemException("Unable to create a Serial Port");
            }
            return(bsp);
        }
Пример #7
0
		/// <summary>
		/// Create a client port for connection to a remote device.
		/// </summary>
		/// <param name="portPrefix">Port name e.g. "COM4"</param>
		/// <param name="endPoint">Remote device to connect to</param>
		/// <returns>A BluetoothSerialPort.</returns>
		public static BluetoothSerialPort CreateClient(string portName, BluetoothEndPoint endPoint)
		{
            string portPrefix;
            int portIndex;
            SplitPortName(portName, out portPrefix, out portIndex);
			BluetoothSerialPort bsp = new BluetoothSerialPort(portPrefix, portIndex);
			bsp.pep.Local = false;
			bsp.pep.Address = endPoint.Address;
			bsp.pep.Service = endPoint.Service;

            bsp.Register();

			return bsp;
		}
Пример #8
0
 /// <summary>
 /// Create a client port for connection to a remote device.  Auto allocates a port from the COM0-9 range.
 /// </summary>
 /// <param name="endPoint">Remote device to connect to.</param>
 /// <returns></returns>
 public static BluetoothSerialPort CreateClient(BluetoothEndPoint endPoint)
 {
     BluetoothSerialPort bsp = new BluetoothSerialPort("COM", 9);
     bsp.pep.Local = false;
     bsp.pep.Address = endPoint.Address;
     bsp.pep.Service = endPoint.Service;
     
     for (int iPort = 8; iPort > -1; iPort--)
     {
         try
         {
             bsp.Register();
             break;
         }
         catch
         {
             bsp.portIndex = iPort;
         }
     }
     return bsp;
 }