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 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