Page 1
Page 2
This example demonstrates the use of the COMM control within embedded Visual Basic.
Serial communications is fundamental to allowing a PC (or in this case a PDA) to talk to
modems or other devices. Modems all generally use the Hayes "AT" command set for
setup. This set of ASCII text-based commands allows the PC to initialize the modem, tell
it to dial a number, hang-up, etc. Other devices use serial communications for diagnostics
and troubleshooting purposes. For example, all cars made since the advent of computer
based diagnostics have a diagnostic port. Generally these ports are located under the
dash, the hood, within the fuse box, or any other number of places. While not RS-232
based, a conversion can be used to allow a PC to connect to the car's diagnostic port to
allow troubleshooting and diagnosis. Unlike the modem commands, these serial buses all
use binary communications. Basically, this means that all 256 possible characters are
interpreted as their binary value and not their text value.
Embedded Visual Basic's Comm control supports both text-based and binary-based RS-
232 communications. However, the documentation provided with eVB is incorrect when
it comes to binary-based communications. This tutorial will walk through a text-based
communications and a binary-based communications. It will demonstrate where the
documentation doesn't work for binary-based communications, and what the work-
around for binary-based communications is. Note, however, that under Visual Basic 6.0
for the PC, binary-based communications does work properly.
The set-up I am using is an iPaq with a CF sleeve and a CF serial card made by Socket.
On my setup, this device uses COM4. You will need to determine what COM port your
Pocket PC serial device uses for its communication. This tutorial requires that you have
access to a PC with Visual Basic 6.0 installed on it. This allows the Pocket PC device to
communicate with something. You will also need a null modem cable to connect the
Pocket PC device to the PC.
Because this can get a little confusing as to which item I am referring to, when I mention
the PC, this is going to refer to the Visual Basic 6.0 application to talk to the Pocket PC.
When I am mentioning the Pocket PC, this is going to refer to the eVB application.
Because it is much easier to simulate, I will extensively discuss text-based
communications. Binary-based communications will be discussed as to how to make
them work, along with a few code fragments to get you on your way.
Text-based Communications
Let's begin with text-based communications and we will begin
with the PC side of things. Follow these steps in order:
1) Create a new project.
2) Go into the Project menu, select components, and add the Microsoft
Comm Control 6.0 to the project. You should now see a telephone icon in
the component window.


3) Place two text boxes on the form.
4) Place a label above each text box.
5) Change one of the label's captions to Received Data and the other to
Data To Transmit.
6) Rename the text box below the Received Data label to ReceivedDataTextBox.
7) Rename the text box below the Data To Transmit label to DataToTransmitTextBox.
8) Create a command button on the form and change its caption to Transmit.
9) Select the Comm control and place it on the form.
10) Set the Comm Port property to the port you are using for communications
on the PC.
11) Set the settings property to 19200,n,8,1.
12) Set the Rthreshold property to 1. This will cause an OnComm event
any time a character is received on the serial port.
13) Fill in the form's code as shown:
Private Sub Command1_Click()
MSComm1.Output = DataToTransmitTextBox.Text
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
ReceivedDataTextBox.Text = MSComm1.Input
Case comEvSend
' do nothing here for now
End Select
End Sub
When all done, the PC project should look like:

We will now move to the Pocket PC side of things.
Follow these steps for the Pocket PC application:
1) Create a new project.
2) Go into the Project menu, select components, and add the Microsoft
CE Comm Control 3.0 to the project. You should see a telephone icon in
the components window.
Next Page