Rapid-Q Documentation by William Yu (c)1999 Appendix A: QCOMPORT


QCOMPORT Component

QComPort provides an easy to use interface to communicate with the com ports. This component was made possible by Dejan Crnila. This component is currently being tested for stability, more functionality is expected in the future. Make sure to download the optional comport libraries to use this component.

QComPort Properties
Field Type R/W Default




BaudRate INTEGER RW br110
Connected INTEGER R
DataBits INTEGER RW 8
Handle INTEGER R
InQue INTEGER R
OutQue INTEGER R
Parity INTEGER RW prNone
PendingIO INTEGER R
Port INTEGER RW 1
ReadBufSize INTEGER RW 1024
StopBits INTEGER RW sbOneStopBit
WriteBufSize INTEGER RW 1024

QComPort Methods
Method Type Description Params




AbortAllIO SUB Aborts all asynchronous read/write operations 0
Close SUB Closes communication port 0
Open SUB Opens communication port 0
PurgeIn SUB Clears input buffer and stops all input functions 0
PurgeOut SUB Clears output buffer and stops all output functions 0
Read SUB Read(QFile/QMemoryStream, Count%, Wait%) Reads stream data from com port, Count% < 32000 3
ReadString FUNCTION ReadString$(Count%, Wait%) Returns a string representation bytes read from comport 2
WaitForLastIO SUB Blocks until last IO is completed 0
Write SUB Write(QFile/QMemoryStream, Count%, Wait%) Writes stream to com port, Count% < 32000 3
WriteString SUB WriteString(Str$, Wait%) Writes string to communication port 2

QComPort Events
Event Type Occurs when... Params




OnBreak VOID A line break is detected, input and output is suspended until break is cleared 0
OnClose VOID Com port is closed 0
OnError VOID A line error occurs 0
OnOpen VOID Com port is successfully opened 0
OnRing VOID A ring signal is detected, used only with modems. 0
OnRxChar SUB (InQue AS INTEGER) A character(s) arrives in the input buffer. 1
OnTxEmpty VOID Output buffer is flushed 0


QComPort Examples
$TYPECHECK ON

CONST sbOneStopBit = 0
CONST prNone = 0

DECLARE SUB CommRxChar (InQue AS INTEGER)
DECLARE SUB OpenClick
DECLARE SUB SendClick
DECLARE SUB FormClose

DIM Comm AS QComPort
    Comm.OnRxChar = CommRxChar
    Comm.DataBits = 8
    Comm.StopBits = sbOneStopBit
    Comm.Parity = prNone

CREATE Form AS QFORM
    Caption = "Form1"
    Width = 302
    Height = 240
    Center
    CREATE Label1 AS QLABEL
        Caption = "Com Port:"
        Left = 5
        Top = 9
        Width = 51
    END CREATE
    CREATE ComboBox1 AS QCOMBOBOX
        AddItems "COM1", _
                 "COM2", _
                 "COM3", _
                 "COM4"
        Left = 55
        Width = 65
        Top = 5
        ItemIndex = 0
    END CREATE
    CREATE ComboBox2 AS QCOMBOBOX
        AddItems "110", "300", "600", "1200", "2400", "4800", "9600", _
                 "14400", "19200", "38400", "56000", "57600", "115200"
        Left = 130
        Width = 70
        Top = 5
        ItemIndex = 0
    END CREATE
    CREATE OpenButton AS QBUTTON
        Caption = "&Open"
        Left = 210
        Top = 4
        OnClick = OpenClick
    END CREATE
    CREATE Edit1 AS QEDIT
        Text = ""
        Left = 12
        Top = 40
        Width = 186
    END CREATE
    CREATE SendButton AS QBUTTON
        Caption = "&Send"
        Left = 210
        Top = 38
        Enabled = 0
        OnClick = SendClick
    END CREATE
    CREATE RichEdit1 AS QRICHEDIT
        Left = 11
        Top = 73
        Width = 274
        Height = 132
        PlainText = 1
        ReadOnly = 1
        ScrollBars = 3
        WordWrap = 0
    END CREATE
    OnClose = FormClose
END CREATE


SUB OpenClick
    IF Comm.Connected THEN
       PRINT Comm.InQue
       EXIT SUB
    END IF
    Comm.Port = ComboBox1.ItemIndex + 1
    Comm.BaudRate = ComboBox2.ItemIndex
    Comm.Open
    IF Comm.Connected THEN
       SendButton.Enabled = 1
    ELSE
       ShowMessage("Cannot open port, try another")
    END IF
END SUB

SUB SendClick
    Comm.WriteString(Edit1.Text+CHR$(13)+CHR$(10), 1)
    Comm.WaitForLastIO
END SUB

SUB CommRxChar (InQue AS INTEGER)
    RichEdit1.AddStrings(Comm.ReadString(InQue, 1))
END SUB

SUB FormClose
    IF Comm.Connected THEN
       Comm.Close
    END IF
END SUB

Form.ShowModal


Prev ComponentContentsNext Component