4/6/2017 2:06 PM © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
4/6/2017 2:06 PM Building Bluetooth Applications On The Windows CE 5.0 And Windows Mobile Platforms Gaurav Khanna gkhanna@microsoft.com Developer Evangelist Microsoft India © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
OEM Hardware and Standard Drivers Standard PC Hardware and Drivers 4/6/2017 2:06 PM Hardware/Drivers OEM/IHV Supplied BSP (ARM, SH4, MIPS) OEM Hardware and Standard Drivers Standard PC Hardware and Drivers Windows XP DDK Device Building Tools Platform Builder Windows Embedded Studio Data Lightweight Relational EDB SQL Server 2005 Express Edition SQL Server 2005 Mobile Edition SQL Server 2005 Native Managed Server Side Win32 Programming Model MFC 8.0, ATL 8.0 .NET Compact Framework .NET Framework ASP.NET Mobile Controls ASP.NET Multimedia Windows Media DirectX Location Services MapPoint Development Tools Visual Studio 2005 Internet Security and Acceleration Server Communications & Messaging Exchange Server Live Communications Server Speech Server Device Update Agent Management Tools Image Update Software Update Services Systems Management Server Microsoft Operations Manager © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Agenda Technology Overview Bluetooth Application Concepts 4/6/2017 2:06 PM Agenda Technology Overview Bluetooth Application Concepts Windows CE Development Windows Mobile Development Demo Q&A © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Technology Overview A short range wireless communication technology 4/6/2017 2:06 PM Technology Overview A short range wireless communication technology 10-100 meter range Operates in 2.4 GHz band using frequency hopping Ad-Hoc network topology Supports voice and data through separate channels Support for device discovery Devices can be queried for capabilities Standardized services © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Typical Usage Scenarios 4/6/2017 2:06 PM Typical Usage Scenarios Audio Services Hands Free devices Wireless Stereo Headsets Wireless Data services Share Internet Connections Ad-Hoc Data Exchange Business card transfer File exchange Printing Cable Replacement Keyboard, Mouse, Printer © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Agenda Technology Overview Bluetooth Application Concepts 4/6/2017 2:06 PM Agenda Technology Overview Bluetooth Application Concepts Windows CE Development Windows Mobile Development Demo Q&A © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Devices Identified by unique address 4/6/2017 2:06 PM Bluetooth Devices Identified by unique address Advertise to others in discoverable mode Class of device field Devices maintain list of supported services Use Service Discovery for querying list on other devices © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Services Describe data exchange protocols 4/6/2017 2:06 PM Bluetooth Services Describe data exchange protocols Identified by a unique GUID Standardized services called “profiles” for common use cases File Transfer (FTP) Dial-Up networking (DUN) Stereo Audio (A2DP) © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
General Tips Keep users informed Conserve the juice 4/6/2017 2:06 PM General Tips Keep users informed Use OS UI for device discovery, pairing Application should handle latency Don’t block UI threads Handle errors gracefully Conserve the juice Limit time in discoverable mode Keep Bluetooth Off when not in use 5 step process for application development © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
The 5 Step Process Find devices in range 4/6/2017 2:06 PM The 5 Step Process Find devices in range Choose a device to connect with Establish a secure connection (pairing) Choose a service Transfer Data © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Step 1: Find Devices In Range 4/6/2017 2:06 PM Step 1: Find Devices In Range Target devices must be in discoverable mode Client device listens to broadcasts from discoverable devices © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Step 2: Choose A Device To Connect With 4/6/2017 2:06 PM Step 2: Choose A Device To Connect With OS usually provides GUI to connect with another device Each device identified by a unique address © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Step 3: Establish A Secure Connection 4/6/2017 2:06 PM Step 3: Establish A Secure Connection Process called “pairing” Requires both end points to use the same pin key Usually part of connecting UI © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Step 4: Choose A Service Each service identified by unique GUID 4/6/2017 2:06 PM Step 4: Choose A Service Each service identified by unique GUID Set of “standard” services for well-known profiles New applications can publish own GUID Services usually chosen through device UI © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Step 5: Transfer Data Point to point style 2-way communication 4/6/2017 2:06 PM Step 5: Transfer Data Point to point style 2-way communication Applications use service/profile protocols to communicate effectively © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Agenda Technology Overview Bluetooth Application Concepts 4/6/2017 2:06 PM Agenda Technology Overview Bluetooth Application Concepts Windows CE Development Windows Mobile Development Demo Q&A © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Application Programming 4/6/2017 2:06 PM Bluetooth Application Programming Winsock API is extended to support Bluetooth New Protocol Family for Bluetooth AF_BTH New Protocol Option BTPROTO_RFCOMM New socket options for Bluetooth Enable/disable encryption Control send/receive buffer size Set power level © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Creating a socket 4/6/2017 2:06 PM Bluetooth Creating a socket SOCKET s = socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM); © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Windows CE: Native Approach 4/6/2017 2:06 PM Windows CE: Native Approach Windows Sockets APIs Device and Service Discovery: WSALookupServiceBegin(), WSALookupServiceNext(), WSALookupServiceEnd() Use standard socket connection APIs bind(), listen(), accept(), connect() Data Transfer APIs send(), recv() © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Connecting a socket 4/6/2017 2:06 PM Bluetooth Connecting a socket SOCKADDR_BTH sa; memset (&sa, 0, sizeof(sa)); sa.addressFamily = AF_BT; sa.btAddr = b; sa.port = channel; connect (s, (SOCKADDR*)&sa, sizeof(sa)); © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Listening on a socket 4/6/2017 2:06 PM Bluetooth Listening on a socket SOCKADDR_BTH sa; memset (&sa, 0, sizeof(sa)); sa.addressFamily = AF_BT; sa.port = BT_PORT_ANY; bind (server, (SOCKADDR *)&sa, sizeof(sa); getsockname(server, (SOCKADDR *)&sa, &namelen); listen (server, 5); SOCKET s2 = accept (server, (SOCKADDR *)&sa2, &size); © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth getsockname 4/6/2017 2:06 PM Bluetooth getsockname Use getsockname to retrieve server channel allocated to socket by a call to bind and Bluetooth address of local device. SOCKADDR_BTH sab; int len = sizeof(sab); if (0 == getsockname (s, &sab, &len)) { wprintf (L”Local Bluetooth device is %04x%08x, server channel = %d\n”, GET_NAP(sab.btAddr), GET_SAP(sab.btAddr), sab.port); } © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth getpeername 4/6/2017 2:06 PM Bluetooth getpeername Use getpeername on connected socket to retrieve Bluetooth address of peer Bluetooth device. SOCKADDR_BTH sab; int len = sizeof(sab); if (0 == getpeername (s, &sab, &len)) { wprintf (L”Remote Bluetooth device is %04x%08x, connected to %d\n”, GET_NAP(sab.btAddr), GET_SAP(sab.btAddr), sab.port); } © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
4/6/2017 2:06 PM Bluetooth getsockopt Queries various parameters associated with server channel or connection. The parameters are as follows: s must be Bluetooth socket level must be SOL_RFCOMM SO_BTH_GET_MTU_MAX,… © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
4/6/2017 2:06 PM Bluetooth setsockopt Configures various parameters associated with server channel or connection. The parameters are as follows: s must be Bluetooth socket level must be SOL_RFCOMM SO_BTH_AUTHENTICATE, SO_BTH_ENCRYPT, … © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Discovering Devices 4/6/2017 2:06 PM Bluetooth Discovering Devices WSAQUERYSET wsaq; wsaq.dwNameSpace = NS_BTH; WSALookupServiceBegin (&wsaq, LUP_CONTAINERS, &hLookup); WSALookupServiceNext (hLookup, LUP_RETURN_ADDR, &dwSize, pwsaResults); pNew->b = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Querying for names 4/6/2017 2:06 PM Bluetooth Querying for names Change WSALookupServiceNext to WSALookupServiceNext (hLookup, LUP_RETURN_NAME | LUP_RETURN_ADDR, &dwSize, pwsaResults) … wcscpy (pRes->szName, pwsaResults->lpszServiceInstanceName); © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Enabling Legacy Applications: Registering COM ports 4/6/2017 2:06 PM Bluetooth Enabling Legacy Applications: Registering COM ports PORTEMUPortParams pp; memset( &pp, 0, sizeof( pp ) ); // connect to serial port profile on device identified by // remoteDeviceAddr pp.device = remoteDeviceAddr; pp.uuidService = SerialPortServiceClass_UUID; pp.uiportflags = RFCOMM_PORT_FLAGS_REMOTE_DCB; HANDLE h = RegisterDevice (L"COM", index, L"btd.dll", (DWORD)&pp); © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Enabling Legacy Applications: Serial Data Transfer 4/6/2017 2:06 PM Bluetooth Enabling Legacy Applications: Serial Data Transfer WCHAR szComPort[30]; // open previously registered COM port for reading and writing wsprintf( szComPort, L"COM%d:", index ); HANDLE hCommPort = CreateFile( szComPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL ); WriteFile( hCommPort, …); ReadFile( hCommPort, …); // cleanup CloseHandle( hCommPort ); DeregisterDevice( h ); © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Agenda Technology Overview Bluetooth Application Concepts 4/6/2017 2:06 PM Agenda Technology Overview Bluetooth Application Concepts Windows CE Development Windows Mobile Development Demo Q&A © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Bluetooth Application Development On Windows Mobile Native Can leverage WinCE Winsock APIs Windows Mobile specific utility methods BthGetMode()/BthSetMode() Managed Code Bluetooth Class Library © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Windows Mobile: Managed Approach 4/6/2017 2:06 PM Windows Mobile: Managed Approach Use UI for pairing Publish Service new BluetoothService( GUID ) List of Paired Devices BluetoothRadio.PairedDevices Connect to a service BluetoothDevice.Connect( GUID ) Use NetworkStream objects for data transfer © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Windows Mobile Managed Approach Benefits 4/6/2017 2:06 PM Windows Mobile Managed Approach Benefits Simplicity Intuitive class interface for all levels of managed developers Focus on the application, not on the technology Easy to build custom services Leverage NETCF APIs for object serialization Flexible, high level networking APIs Powerful NetworkStream class Rich threading support Shared Source Add and change under the hood © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Agenda Technology Overview Bluetooth Application Concepts 4/6/2017 2:06 PM Agenda Technology Overview Bluetooth Application Concepts Windows CE Development Windows Mobile Development Demo Q&A © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Inside the Managed Bluetooth Library 4/6/2017 2:06 PM Inside the Managed Bluetooth Library © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Enumerating Paired Devices 4/6/2017 2:06 PM Enumerating Paired Devices © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Windows Mobile Managed Library Download 4/6/2017 2:06 PM Windows Mobile Managed Library Download http://msdn.microsoft.com/embedded/usewinemb/ce/sharedsrccode/west/default.aspx © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
4/6/2017 2:06 PM Conclusion Bluetooth is a ubiquitous, powerful ad-hoc networking technology Rich support on Windows CE and Windows Mobile Windows Sockets API Managed Class Library for Windows Mobile Leverage Visual Studio 2005 for native and managed development © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Tools & Resources Build Develop Websites Newsgroups Blogs Tools 4/6/2017 2:06 PM Tools & Resources Build Develop Websites msdn.microsoft.com/ embedded msdn.microsoft.com/ mobility Newsgroups microsoft.public. windowsxp.embedded windowsce.platbuilder windowsce.embedded.vc microsoft.public. pocketpc.developer smartphone.developer dotnet.framework.compactframework Blogs blogs.msdn.com/ mikehall blogs.msdn.com/ windowsmobile vsdteam netcfteam Tools Windows CE 5.0 Eval Kit Windows XP Embedded Eval Kit Windows Mobile 5.0 Eval Kit © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Your Feedback is Important! 4/6/2017 2:06 PM Your Feedback is Important! Please Fill Out the feedback form Questions? gkhanna@microsoft.com © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
© 2005 Microsoft Corporation. All rights reserved. 4/6/2017 2:06 PM © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.