Virtual COM Port Sample

The SCA sample application illustrates the use of the Windows CE–based Bluetooth stack over the Virtual COM Port interface.

The compiled sample generates an Sca.exe application that can be started as server or client. When started as server, it creates a server COM port and waits for connections. When started as client, it creates a client COM port and initiates a connection. Once a connection is established, users can exchange text messages or files.

To view supported command line options, use SCA /?

Usage

sca server <rfcomm_chnl> <com_port>
sca client <server_bt_addr> <rfcomm_chnl> <com_port>

The following table describes the parameters needed when using the SCA sample application.

Parameters Description
server_bt_addr Bluetooth address of the server.
rfcomm_chnl RFCOMM channel (between 1 and 31).
com_port COM port to be assigned to Bluetooth.

Explanation

When the client or server starts, it creates a COM port to associate with the Bluetooth stack in the following manner.

HANDLE h = RegisterDevice (L"COM", index, L"btd.dll", (DWORD)&pp);

For the client, the Bluetooth server address (pp) is passed into the pp.device field in the PORTEMUPortParams structure.

For the server, the pp.flocal field must be set to TRUE.

If the COM port is created successfully, the port can be opened for communication using standard APIs in the following manner.

HANDLE hCommPort = CreateFile (
                   szComPort,
                   GENERIC_READ | GENERIC_WRITE,
                   0, NULL, OPEN_EXISTING, 0, NULL
                  );

A WriteThread and ReadThread are created to manage the data over the COM port in the following manner.

CloseHandle (CreateThread(NULL, 0, ReadThread, (LPVOID)hCommPort, 0, NULL));
WriteThread ((LPVOID)hCommPort);

The WriteThread sends data, entered by the user, over the virtual COM port, while the ReadThread, on the listening device, displays the received data on the screen.

Sample Location

%_WINCEROOT%\Public\Common\Oak\Drivers\Bluetooth\Sample\Sca

**Note   **This sample application has not been thoroughly tested and is not intended for production use.

See Also

Bluetooth | Bluetooth Samples

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.