Date: 02-16-2022
Return to Index
created by gbSnippets
'For test purposes, it's sometimes useful to have a simple app that
'does nothing but receive information from a specified port. This app
'does that.
'Primary Code:
'This code returns the number of bytes available in the receive queue, then
'gets that numbers of bytes from the queue.
Qty& = Comm(hComm, RXQUE) 'check que to see how many bytes are available
Comm Recv hComm, Qty&, a$ 'get that many bytes
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg as DWord, hComm as Long
Function PBMain() As Long
Dialog New Pixels, 0, "Receive (Serial Port)",300,300,220,140, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Open ", 10,10,68,20
Control Add TextBox, hDlg, 200,"COM1", 100,10,60,20
Control Add Button, hDlg, 300,"Check for Bytes", 10,40,80,20
Control Add TextBox, hDlg, 400,"<bytes>", 100,40,60,20
Control Add Button, hDlg, 500,"Receive", 10,70,80,20
Control Add TextBox, hDlg, 600,"<data to receive>", 100,70,100,20
Control Add Button, hDlg, 700,"Close", 10,100,80,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
Local Qty&, buffer$
Select Case CB.Ctl
Case 100: OpenCOM
Case 300: Qty& = Comm(hComm,RxQue)
Control Set Text hDlg, 400, Str$(Qty&)
Case 500: Comm Recv hComm, Comm(hComm, RxQue), buffer$ 'put all available bytes in buffer$
Control Set Text hDlg, 600, buffer$
Case 700: Comm Close hComm
End Select
End Select
End Function
Sub OpenCOM()
Local temp$
Control Get Text hDlg, 200 To temp$
hComm = FreeFile
Comm Open temp$ As hComm
If ErrClear Then
MsgBox ("Failure to Open")
Else
MsgBox ("Opened")
Comm Set hComm, Baud = 9600
Comm Set hComm, Byte = 8
Comm Set hComm, Parity = 0
Comm Set hComm, Stop = 1
Comm Set hComm, TxBuffer = 1048576
Comm Set hComm, RxBuffer = 1048576
End If
End Sub
'gbs_00342
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm