Download presentation
Presentation is loading. Please wait.
Published byRoberta Logan Modified over 8 years ago
2
Ryan McMahan Senior Software Engineer Shared Technology Intermec Bluetooth Integration Building Bridges to Bluetooth Enabled Peripherals
3
Presentation Focus Code Tight Integration with Your App Wireless Printing Wireless Scanning Microsoft APIs
4
Multiblue A sample application Bluetooth Printing setup Switching printers Bluetooth Scanning setup Scanner setup via ISCP (Intermec Scanner Control Protocol) Device Discovery Found device event Scanning Printing
5
Multiblue – Application Flow 1. Startup 2. Scanner setup 3. Printer setup 4. Scan 5. Print 6. Switch printers 7. Print 8. Shutdown
6
Multiblue - Startup Turn the radio on Intermec Bluetooth Library IBT_On() Available in Intermec Developer Library (IDL) Why would you leave it off? Power savings Security policies No radio zones
7
Be a Good Radio Citizen Try to maintain the previous radio state when exiting your app Knowing when not to turn off is easier than knowing when it is safe to turn off Intermec APIs for Bluetooth IBT_On IBT_Off
8
Multiblue – Scanner Setup Add to Data Collection – Handles all of the connection maintenance Related session – “Accelerating Development with the Intermec Data Collection Engine” COM port connections are possible as well How do we know which scanner to connect to? Device Address is the key for connections Device Discovery Barcode scan Read from a file Manually entry
9
Avoiding Device Discovery Very powerful and useful Can take longer than you’d like, especially in populated areas Inquiry is traditionally fixed (approximately 10s) Device name lookup is variable (0-10s) and handled one device at a time You can skip name lookup, but results are less valuable Approximate total time in seconds 10 + (num_devices * 3)
10
Barcode Scan Scanner – SF51 Route Printer – PB41 Depot Printer – PB42
11
Reading Local Device Address 3 Steps Initialize Winsock Create and bind a socket getsockname()
12
Reading Local Device Address Step 1: Initialize Winsock WSADATA wsaData; WORD wVer = MAKEWORD( 2, 2 ); if(WSAStartup(wVer, &wsaData) != 0) AfxMessageBox(_T("Could not initialize"));
13
Reading Local Device Address Step 2: Create and bind a socket SOCKET s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); SOCKADDR_BTH sab; memset(&sab, 0, sizeof(sab)); sab.addressFamily = AF_BTH; sab.port = 0; int len = sizeof(sab); bind(s, (sockaddr *)&sab,len);
14
Reading Local Device Address Step 3: getsockname if(0 == getsockname(s, (sockaddr *)&sab, &len)) code.Format(_T("%04x%08x"), GET_NAP(sab.btAddr), GET_SAP(sab.btAddr)); closesocket(s); code.MakeUpper(); m_cDeviceAddress.SetWindowText(code);
15
Bluetooth Scanner in Intermec Settings Live Display
16
Multiblue – Printer Setup Prepare two printers – one COM port How do we know which printer to connect to? Device Address is the key for connections Device Discovery Barcode scan – leverage our scanner connection Read from a file Manually entry
17
Printer Self-test Contains useful setup information Newer products contain a Code 128 representation of the Bluetooth Device Address
18
Device Address Separators Common separator forms AA:BB:CC:11:22:33 AA.BB.CC.11.22.33 AA-BB-CC-11-22-33 AA BB CC 11 22 33 Good for humans, less interesting to computers Suggestion – include code to filter out device address separators
19
Barcode Scan Code Note: I modify the postamble Route Printer – PB41 Depot Printer – PB42
20
COM Port Registration Things You Need Remote Device Address Port index – COM6 is a good choice Port prefix – COM or BSP Service UUID or RFCOMM channel Could be on different COM ports We’ll make them share to illustrate deregistration The dreaded 2404 The device is in use by an active process and cannot be disconnected. Something is already registered on that port Choose another port or deregister
21
Registration Code PORTEMUPortParams pp; TCHAR prefix[3+1];// COM or BSP pp.device = bdaddr; pp.channel = 0; // Let it auto-SDP memcpy(&pp.uuidService, &SerialPortServiceClass_UUID, sizeof(GUID)); tcscpy(prefix, L"COM"); int index = 6; hBluetoothPort = RegisterDevice(prefix, index, L"btd.dll", (DWORD)&pp);
22
Deregistration Code DeregisterDevice(hBluetoothPort);
23
COM Port APIs Same as traditional COM Ports CreateFile & CloseFile ReadFile & WriteFile GetCommMask & SetCommMask GetCommState & SetCommState WaitCommEvent DCB Structure Be careful with uiportflags parameter
24
Confirmation Print Common technique to verify setup It can be bad Requires printer to be in range and turned on Could be wasteful depending on frequency of setup and app design
25
Device Discovery Background thread to detect location Allows us to auto-switch the default printer Bluetooth GPS is perfect for this Multiblue will use this to recognize when our depot printer is ready
26
Device Discovery Code iRet = WSALookupServiceBegin (&wsaq, LUP_CONTAINERS, phLookup); iRet = WSALookupServiceNext(*phLookup, LUP_RETURN_ADDR, &dwSize, pwsaResults); if(iRet == ERROR_SUCCESS) { wsprintf(szDevice, _T("%04x%08x"), GET_NAP(((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer- >RemoteAddr.lpSockaddr)->btAddr), GET_SAP(((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer- >RemoteAddr.lpSockaddr)->btAddr)); RETAILMSG(1,(_T("\r\n %s"), szDevice)); if(_tcsicmp(szDevice, me->m_printer2) == 0) { found = TRUE; RETAILMSG(1,(_T("\r\n DING! Match on %s"), szDevice)); } WSALookupServiceEnd(phLookup);
27
Multiblue in action Demo
28
Learn More Bluetooth Resource Kit in Intermec Developer Library Wp_sample2 Microsoft’s Sample Program Btsearch Installs as part of the Pocket PC 2003 SDK \Program Files\Windows CE Tools\wce420\Pocket PC 2003\Samples\Win32\Bluetooth Windows Embedded Source Tools for Bluetooth Technology A Win32 API Wrapper that developers can expose in Visual Studio.NET or the.NET Compact Framework
29
Questions? Yes, I will make this code available
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.