To test for an incoming string/char, I added GetInBuff() SUB, which prints out too the console screen the incoming string/char, not working as expected.
What is occurring is that I have to press a key in the GUI screen to get something too show up on the console screen. I thought that the incoming string/char would automatically show up in the console screen, not happening. So it seems like the Text Editor screen only responds to a keypress, in order to get things to move along. The one good thing is that when I do a keypress, it does display what was typed on the other end, so that is a good thing.
I am not sure as to how I can get GetInBuff() SUB to interact automatically within the Text Editor, in the test scenario of the console window, let alone getting the incoming string/char to work with the Text Editor directly.
Code: Select all
'FBGterm.bas
#INCLUDE "fltk-c.bi"
' Declarations
DECLARE SUB EndProgram CDECL(widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB About CDECL(widget AS Fl_Widget PTR, userData AS ANY PTR)
DECLARE SUB GetInBuff()
' Variables and etc
DIM SHARED AS Fl_Menu_Bar PTR Menu
' Text editor window control
sub ModifyCb cdecl (byval p as long, _
byval nInserted as long, _
byval nDeleted as long, _
byval nRestyled as long, _
byval deletedText as const zstring ptr, _
byval Editor as any ptr)
if nInserted=0 andalso nDeleted=0 then exit sub
dim as Fl_Text_Buffer ptr TextBuffer = Fl_Text_DisplayGetBuffer(Editor)
dim as zstring ptr Text
dim as long e , s=p , char = Fl_Text_BufferCharAt(TextBuffer,p)
if (nInserted > 0) then e = s + nInserted
if (nDeleted > 0) then e = s + nDeleted
s = Fl_Text_BufferLineStart(TextBuffer,s)
e = Fl_Text_BufferLength(TextBuffer)
Text = Fl_Text_BufferTextRange(TextBuffer,s,e)
' Check for just a CR
' If char=10 then
' Print #1, chr(13)
' End If
' Check for string and CR
if char=10 andalso len(*text)>1 then
Print #1,*Text + chr(13); ' Send Text Com #1
end if
' Get and display incoming string
'
GetInBuff()
Print chr(13)
end sub
SUB GetInBuff()
Dim As String inBuffer
While LOC(1)>0
inBuffer = Input$(LOC(1),#1)
Print inBuffer + chr(13);
Print #1, Chr(10);
Wend
END SUB
' End the program, close open COMs
SUB EndProgram CDECL(widget AS Fl_Widget PTR, userData AS ANY PTR)
close
END
END SUB
' Help mesage box
SUB About CDECL(widget AS Fl_Widget PTR, userData AS ANY PTR)
flMessageBox("About Information", _
"This is the FBGterm terminal program." + chr(10) + _
"Coded in freeBASIC" + chr(10) + _
"Enhanced with FLTK GUI toolkit.")
END SUB
'
' main
'
var win = Fl_Double_WindowNew(900,600,"FBGterm test")
var edt = Fl_Text_EditorNew(10,30,Fl_WidgetGetW(win)-20,Fl_WidgetGetH(win)-20)
var buf = Fl_Text_BufferNew()
' Add a menu bar
Menu = Fl_Menu_BarNew(0,0,900,20)
Fl_Menu_Add(Menu,"Quit",,@EndProgram())
Fl_Menu_Add(Menu,"About",,@About())
''''
' Open COM port
Open Com "COM4:115200,n,8,1,cs0,ds0,cd0,rs" as #1
'Test if COM available
If Err <> 0 Then
flMessageBox("COM Information","Error opening COM port!")
Endif
''''
Fl_Text_DisplaySetBuffer(edt,buf)
Fl_Text_BufferAddModifyCallback(buf,@ModifyCB,edt)
Fl_GroupSetResizable(win,edt)
Fl_WindowShow(win)
Fl_Run()