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 send information from a specified port. This app
'does that.
'Primary Code:
'This code sends a text string to a specified serial port.
Comm Send iPort, "My serial port test!" 'Send from opened serial port
'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, "Send (Serial Port)",300,300,220,140, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Open ", 10,10,80,20
Control Add TextBox, hDlg, 200,"COM1", 100,10,60,20
Control Add Button, hDlg, 300,"Send", 10,40,80,20
Control Add TextBox, hDlg, 400,"<data to send>", 100,40,100,20
Control Add Button, hDlg, 500,"Close", 10,70,80,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
Local buffer$
Static iCount&
Select Case CB.Ctl
Case 100: OpenCOM
Case 300: Control Get Text hDlg, 400 TO buffer$ : Incr iCount&
Comm Send hComm, "Msg" + Str$(iCount&) + $crlf + buffer$ +$crlf 'Send from opened serial port
Case 500: 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 = 4096
Comm Set hComm, RxBuffer = 4096
End If
End Sub
'gbs_00343
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm