Guidance
指路人
g.yi.org
software / RapidQ / RQ Doc / html / qcomport.html

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Appendix A: QCOMPORT
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
FieldTypeR/WDefault




BaudRateINTEGERRWbr110
ConnectedINTEGERR
DataBitsINTEGERRW8
HandleINTEGERR
InQueINTEGERR
OutQueINTEGERR
ParityINTEGERRWprNone
PendingIOINTEGERR
PortINTEGERRW1
ReadBufSizeINTEGERRW1024
StopBitsINTEGERRWsbOneStopBit
WriteBufSizeINTEGERRW1024

QComPort Methods
MethodTypeDescriptionParams




AbortAllIOSUBAborts all asynchronous read/write operations0
CloseSUBCloses communication port0
OpenSUBOpens communication port0
PurgeInSUBClears input buffer and stops all input functions0
PurgeOutSUBClears output buffer and stops all output functions0
ReadSUB Read(QFile/QMemoryStream, Count%, Wait%)Reads stream data from com port, Count% < 320003
ReadStringFUNCTION ReadString$(Count%, Wait%)Returns a string representation bytes read from comport2
WaitForLastIOSUBBlocks until last IO is completed0
WriteSUB Write(QFile/QMemoryStream, Count%, Wait%)Writes stream to com port, Count% < 320003
WriteStringSUB WriteString(Str$, Wait%)Writes string to communication port2

QComPort Events
EventTypeOccurs when...Params




OnBreakVOIDA line break is detected, input and output is suspended until break is cleared0
OnCloseVOIDCom port is closed0
OnErrorVOIDA line error occurs0
OnOpenVOIDCom port is successfully opened0
OnRingVOIDA ring signal is detected, used only with modems.0
OnRxCharSUB (InQue AS INTEGER)A character(s) arrives in the input buffer.1
OnTxEmptyVOIDOutput buffer is flushed0


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 Component Contents Next Component
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2015-12-25 19:42:31