Serial Ports, BASIC4PPC and the "SerialDevice.dll"

In order to write application programs that send & receive data using Serial Ports you must include the "SerialDevice.dll" in your project before compiling your code.  The following steps show you how to add the "SerialDevice.dll" to a project when using the Basic4ppc Compiler for the Pocket PC.
The application program only needs four program statements to send data
using the Pocket PC serial port.

This program statement initializes the Serial Port:


     serial.New2 (8,9600,"N",8,1)

          The COM Port is set to 8.
          The BAUD rate is set to 9600.
          There is "No" Parity.
          The number of bits is 8.
          There is only 1 Stop bit.


This program statement Opens the COM Port.

     serial.PortOpen=true

This program statement Closes the COM Port.

     serial.PortOpen=false

This program statement sends data out the COM Port.

     serial.Output ("A")
BASIC4PPC Application Program Code Listing.

The following program listing is the code for the Pocket PC application used in this example. 

Sub Globals
x=0
portflag = 0
strlabel0="COM 8 > 9600,N,8,1"
strlabel1=" [CLOSED]"
strlabel2=" [  OPEN ]"
strlabel3=" TX=   "
strlabeltemp=""
End Sub

Sub App_Start
Form1.show
label1.Text = strlabel0 & strlabel1 & strlabel3
strlabeltemp  = strlabel0 & strlabel1 & strlabel3
serial.New2 (8,9600,"N",8,1)
End Sub

Sub Button1_Click
If portflag = 0 Then
serial.PortOpen=true
portflag = 1
label1.Text = strlabel0 & strlabel2 & strlabel3
strlabeltemp=label1.Text
For x=0 To 3000
Next
serial.Output ("*")
End If
End Sub

Sub Button2_Click
If portflag = 1 Then
serial.Output ("^")
For x=0 To 3000
Next
serial.PortOpen=false
portflag = 0
label1.Text = strlabel0 & strlabel1 & strlabel3
strlabeltemp=label1.Text
End If
End Sub

Sub Button3_Click
serial.Output ("A")
label1.Text = strlabeltemp & "A"
End Sub

Sub Button4_Click
serial.Output ("B")
label1.Text = strlabeltemp & "B"
End Sub

Sub Button5_Click
serial.Output ("C")
label1.Text = strlabeltemp & "C"
End Sub

Sub Button6_Click
serial.Output ("D")
label1.Text = strlabeltemp & "D"
End Sub

Sub Button7_Click
serial.Output ("E")
label1.Text = strlabeltemp & "E"
End Sub

Sub Button8_Click
serial.Output ("F")
label1.Text = strlabeltemp & "F"
End Sub

Sub Button9_Click
serial.Output ("G")
label1.Text = strlabeltemp & "G"
End Sub

Sub Button10_Click
serial.Output ("H")
label1.Text = strlabeltemp & "H"
End Sub

Sub Button11_Click
serial.Output ("I")
label1.Text = strlabeltemp & "I"
End Sub

Sub Button12_Click
serial.Output ("J")
label1.Text = strlabeltemp & "J"
End Sub

Sub Button13_Click
serial.Output ("K")
label1.Text = strlabeltemp & "K"
End Sub

Sub Button14_Click
serial.Output ("L")
label1.Text = strlabeltemp & "L"
End Sub

Sub Button15_Click
serial.Output ("M")
label1.Text = strlabeltemp & "M"
End Sub

Sub Button16_Click
serial.Output ("N")
label1.Text = strlabeltemp & "N"
End Sub

Sub Button17_Click
serial.Output ("O")
label1.Text = strlabeltemp & "O"
End Sub

Sub Button18_Click
serial.Output ("P")
label1.Text = strlabeltemp & "P"
End Sub

Sub Button19_Click
serial.Output ("Q")
label1.Text = strlabeltemp & "Q"
End Sub

Sub Button20_Click
serial.Output ("R")
label1.Text = strlabeltemp & "R"
End Sub

Sub Button21_Click
serial.Output ("S")
label1.Text = strlabeltemp & "S"
End Sub

Sub Button22_Click
serial.Output ("T")
label1.Text = strlabeltemp & "T"
End Sub

Sub Button23_Click
serial.Output ("U")
label1.Text = strlabeltemp & "U"
End Sub

Sub Button24_Click
serial.Output ("V")
label1.Text = strlabeltemp & "V"
End Sub

Sub Button25_Click
serial.Output ("W")
label1.Text = strlabeltemp & "W"
End Sub

Sub Button26_Click
serial.Output ("X")
label1.Text = strlabeltemp & "X"
End Sub

Sub Button27_Click
serial.Output ("Y")
label1.Text = strlabeltemp & "Y"
End Sub

Sub Button28_Click
serial.Output ("Z")
label1.Text = strlabeltemp & "Z"
End Sub

Sub Button29_Click
serial.Output ("0")
label1.Text = strlabeltemp & "0"
End Sub

Sub Button30_Click
serial.Output ("1")
label1.Text = strlabeltemp & "1"
End Sub

Sub Button31_Click
serial.Output ("2")
label1.Text = strlabeltemp & "2"
End Sub

Sub Button32_Click
serial.Output ("3")
label1.Text = strlabeltemp & "3"
End Sub

Sub Button33_Click
serial.Output ("4")
label1.Text = strlabeltemp & "4"
End Sub

Sub Button34_Click
serial.Output ("5")
label1.Text = strlabeltemp & "5"
End Sub

Sub Button35_Click
serial.Output ("6")
label1.Text = strlabeltemp & "6"
End Sub

Sub Button36_Click
serial.Output ("7")
label1.Text = strlabeltemp & "7"
End Sub

Sub Button37_Click
serial.Output ("8")
label1.Text = strlabeltemp & "8"
End Sub

Sub Button38_Click
serial.Output ("9")
label1.Text = strlabeltemp & "9"
End Sub

Sub Button39_Click
serial.Output ("a")
label1.Text = strlabeltemp & "a"
End Sub

Sub Button40_Click
serial.Output ("b")
label1.Text = strlabeltemp & "b"
End Sub

Sub Button41_Click
serial.Output ("c")
label1.Text = strlabeltemp & "c"
End Sub

Sub Button42_Click
serial.Output ("d")
label1.Text = strlabeltemp & "d"
End Sub

Sub Button43_Click
serial.Output ("e")
label1.Text = strlabeltemp & "e"
End Sub

Sub Button44_Click
serial.Output ("f")
label1.Text = strlabeltemp & "f"
End Sub

Sub Button45_Click
serial.Output ("g")
label1.Text = strlabeltemp & "g"
End Sub

Sub Button46_Click
serial.Output ("h")
label1.Text = strlabeltemp & "h"
End Sub

Sub Button47_Click
serial.Output ("i")
label1.Text = strlabeltemp & "i"
End Sub

Sub Button48_Click
serial.Output ("j")
label1.Text = strlabeltemp & "j"
End Sub

Sub Button49_Click
serial.Output ("k")
label1.Text = strlabeltemp & "k"
End Sub

Sub Button50_Click
serial.Output ("l")
label1.Text = strlabeltemp & "l"
End Sub

Sub Button51_Click
serial.Output ("m")
label1.Text = strlabeltemp & "m"
End Sub

Sub Button52_Click
serial.Output ("n")
label1.Text = strlabeltemp & "n"
End Sub

Sub Button53_Click
serial.Output ("o")
label1.Text = strlabeltemp & "o"
End Sub

Sub Button54_Click
serial.Output ("p")
label1.Text = strlabeltemp & "p"
End Sub

Sub Button55_Click
serial.Output ("q")
label1.Text = strlabeltemp & "q"
End Sub

Sub Button56_Click
serial.Output ("r")
label1.Text = strlabeltemp & "r"
End Sub

Sub Button57_Click
serial.Output ("s")
label1.Text = strlabeltemp & "s"
End Sub

Sub Button58_Click
serial.Output ("t")
label1.Text = strlabeltemp & "t"
End Sub

Sub Button59_Click
serial.Output ("u")
label1.Text = strlabeltemp & "u"
End Sub

Sub Button60_Click
serial.Output ("v")
label1.Text = strlabeltemp & "v"
End Sub

Sub Button61_Click
serial.Output ("w")
label1.Text = strlabeltemp & "w"
End Sub

Sub Button62_Click
serial.Output ("x")
label1.Text = strlabeltemp & "x"
End Sub

Sub Button63_Click
serial.Output ("y")
label1.Text = strlabeltemp & "y"
End Sub

Sub Button64_Click
serial.Output ("z")
label1.Text = strlabeltemp & "z"
End Sub

Sub Button65_Click
serial.Output ("#")
label1.Text = strlabeltemp & "#"
End Sub

Sub Button66_Click
serial.Output ("$")
label1.Text = strlabeltemp & "$"
End Sub

Sub Button67_Click
serial.Output ("%")
label1.Text = strlabeltemp & "%"
End Sub

Sub Button68_Click
serial.Output ("[")
label1.Text = strlabeltemp & "["
End Sub

Sub Button69_Click
serial.Output ("]")
label1.Text = strlabeltemp & "]"
End Sub

Sub Button70_Click
serial.Output ("@")
label1.Text = strlabeltemp & "@"
End Sub

Sub Button71_Click
serial.Output ("|")
label1.Text = strlabeltemp & "|"
End Sub

Sub Button72_Click
serial.Output ("<")
label1.Text = strlabeltemp & "<"
End Sub

Sub Button73_Click
serial.Output (">")
label1.Text = strlabeltemp & ">"
End Sub

Sub Button74_Click
serial.Output ("(")
label1.Text = strlabeltemp & "("
End Sub

Sub Button75_Click
serial.Output (")")
label1.Text = strlabeltemp & ")"
End Sub
This example application was written in BASIC using the
Basic4ppc compiler for the Pocket PC.  It shows how to
open and close a Serial Com Port.  It shows how to send
single byte characters to the BlueSMiRF module.

The program code for this example is listed below.