I did some more changes to FBterm.bas, now the single code file compiles on Windows 7 PC and the Raspberry Pi. Since I do not have a "real" Linux box available, I could not test it there. I think I got all the bugs, but ...
Not sure if everybody knows, but for the Raspberry Pi, you only have miniterm as a choice, and in my opinion, it was an awkward piece of software to use. So I hope FBterm is a little bit better, and maybe easier to use. One of these days I might try to get a workable FBterm on a PC-BSD box, but am not sure if FBC is available for it. Now I am not sure what else can be done with FBterm, not even sure if anybody else is using it. Any problems with the program, like a bug, let me know here.
Code: Select all
' FBterm.bas
' FBterm.exe - Windows
' August 2, 2011
' Version 2.0 revision 02
' Oct 9, 2014
' Version 2.0 revision 03
' - Fixed code to run with 64-bit FBC
' - Lines 33,34,35 changed, using {}
' Oct 17, 2014
' Version 2.0 revision 04
' - Code adjustments for compiling Linux version
' - Ajustments for Linux screen
' - Works for Raspberry Pi
Screen 12
Width 80,30
Locate ,,1
' Globals
Dim Shared Corig As UInteger
Dim Shared t As Double
Dim Shared As Integer column, row, flag, pos1, pos2, row1, column1
Dim Shared As String Key, buffer, numtosend
Dim Shared As UByte numtosend2
''''''''' Headers for Functions and Subroutines '''''''''''
Declare Sub InfoBar()
Declare Sub InfoBar2()
Declare Sub PrtColText(ByVal x As Integer, ByVal y As Integer, ByVal color1 As Integer, ByVal color2 As Integer, ByRef text As String)
Declare Sub OrigColor(ByVal loval As UInteger, ByVal hival As UInteger)
Declare Sub TextCursor()
Declare Sub sendnum()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Locals
Dim As Integer b, p, e
Dim As String baud(0 To 7) = {"1200","2400","4800","9600","19200","38400","57600","115200"}
#ifdef __FB_WIN32__
Dim As String port(0 To 9) = {"COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","COM7:","COM8:","COM9:","COM10:"}
#else
Dim As String port(0 to 5) = {"/dev/ttyAMA0:","/dev/ttyUSB0:","/dev/ttyUSB1:","/dev/tty00: ","/dev/tty01: ","/dev/tty02: " }
#endif
Dim As String echo(0 To 1) = {"On"," Off"}
Dim As String Escape = Chr(27)
Dim As Integer res, x, y, buttons
Corig = Color()
''''''''' Start of Program ''''''''''''
Cls
begin:
InfoBar()
#ifdef __FB_WIN32__
Locate 2,24
Color 7,9
Print port(p);
Locate 2,37
Print baud(b);
#else
Locate 2,24
Color 7,9
Print port(p);
Locate 2,41
Print baud(b);
#endif
''''''''' Main Screen '''''''''''''''''
Do
res = GetMouse (x, y, , buttons)
Key = InKey$
If Key = Escape Then
Exit Do
End If
''''''''''' Mouse over Quit '''''''''''
If x > 1 And x <= 32 And y > 16 And y < 31 And buttons And 1 Then
'Exit Do
GoTo Cend
EndIf
'''''''''''''''''''''''''''''''''''''''
'''''''''' Mouse over Connect '''''''''
If x > 49 And x <= 112 And y > 16 And y < 31 And buttons And 1 Then
Sleep 200,1
Exit Do
EndIf
'''''''''''''''''''''''''''''''''''''''
'''''''''' Mouse over port ''''''''''''
#ifdef __FB_WIN32__
If x > 144 And x <= 176 And y > 16 And y < 31 And buttons And 1 Then
p += 1
If p = 10 Then p = 0
Locate 2,24
Color 7,9
Print port(p);
Sleep 200,1
EndIf
#else
If x > 144 And x <= 176 And y > 16 And y < 31 And buttons And 1 Then
p += 1
If p = 5 Then p = 0
Locate 2,24
Color 7,9
Print port(p);
Sleep 200,1
EndIf
#endif
'''''''''''''''''''''''''''''''''''''''
'''''''''' Mouse over baud ''''''''''''
#ifdef __FB_WIN32__
If x > 248 And x <= 280 And y > 16 And y < 31 And buttons And 1 Then
b += 1
If b = 8 Then b = 0
Locate 2,37
Print " "
Color 7,9
Locate 2,37
Print baud(b);
Sleep 200,1
EndIf
#else
If x > 288 And x <= 328 And y > 16 And y < 31 And buttons And 1 Then
b += 1
If b = 8 Then b = 0
Locate 2,41
Print " "
Color 7,9
Locate 2,42
Print baud(b);
Sleep 200,1
EndIf
#endif
'''''''''''''''''''''''''''''''''''''''
Loop
''''''''' End of Main Screen ''''''''''
''''''''' Live Terminal '''''''''''''''
InfoBar2()
Open Com port(p) & baud(b) & ",n,8,1,cs0,ds0,cd0,rs" as #1
' Open Com "COM1:115200,n,8,1,cs0,ds0,cd0,rs" As #1
If Err <> 0 Then
Print "Error opening",port(p);
Sleep 2000,1
Cls
GoTo begin
EndIf
Do
res = GetMouse (x, y, , buttons)
Key = InKey$
TextCursor()
'''''''''' Mouse over Disonnect '''''''''
If x > 49 And x <= 136 And y > 16 And y < 31 And buttons And 1 Then
Close #1
OrigColor(LoWord(Corig),HiWord(Corig))
Sleep 200,1
Cls
GoTo begin
EndIf
'''''''''''''''''''''''''''''''''''''''
''''''''' Mouse over echo '''''''''''''
If x > 336 And x <= 368 And y > 16 And y < 31 And buttons And 1 Then
e += 1
If e = 2 Then e = 0
View Print 1 To HiWord(Width)
Locate 2,48
Color 7,9
Print " "
Locate 2,48
Print echo(e);
View Print 3 To HiWord(Width)
Color 7,0
Cls
Sleep 200,1
EndIf
'''''''''''''''''''''''''''''''''''''''
''''''''' Mouse over Send Number ''''''
If x > 424 And x <= 512 And y > 16 And y < 31 And buttons And 1 Then
sendnum()
EndIf
'''''''''''''''''''''''''''''''''''''''
''''''''' Mouse over Cls ''''''''''''''
If x > 520 And x <= 544 And y > 16 And y < 31 And buttons And 1 Then
Cls
EndIf
'''''''''''''''''''''''''''''''''''''''
'''''''''' Terminal Screen ''''''''''''
If Key <> "" Then
If Key = Chr$(13) Then ' Check for CR
Print #1, Chr$(10); ' Send LF
Print Chr$(10); ' Local LF
Else
Print #1,Key;
If echo(e) = "On" Then
Print Key;
Else
'Echo off
End If
EndIf
EndIf
While LOC(1) > 0
buffer = Input$(LOC(1),#1)
Print buffer;
print #1, chr$(10);
Wend
'''''''''''''''''''''''''''''''''''''''
Sleep 1
Loop
''''''''' End of Live Terminal ''''''''
Cend:
Close
End
''''''''' End of Program ''''''''''''''
''''''''' Functions and Subroutines '''
Sub InfoBar()
#ifdef __FB_WIN32__
Cls
Locate 1,1
View Print 1 To HiWord(Width)
PrtColText(1,1,7,9," ")
PrtColText(1,36,7,9,"FBterm")
PrtColText(1,42,7,9," ")
PrtColText(2,1,0,4,"Quit")
PrtColText(2,5,7,9," ")
PrtColText(2,7,0,4,"Connect")
PrtColText(2,14,7,9," ")
PrtColText(2,19,0,4,"Port")
PrtColText(2,23,7,9," ")
PrtColText(2,24,7,9," ")
PrtColText(2,30,7,9," ")
PrtColText(2,32,0,4,"Baud")
PrtColText(2,36,7,9," ")
PrtColText(2,37,7,9," ")
PrtColText(2,42,7,9," ")
OrigColor(LoWord(Corig), HiWord(Corig))
#else
Cls
Locate 1,1
View Print 1 To HiWord(Width)
PrtColText(1,1,7,9," ")
PrtColText(1,36,7,9,"FBterm")
PrtColText(1,42,7,9," ")
PrtColText(2,1,0,4,"Quit")
PrtColText(2,5,7,9," ")
PrtColText(2,7,0,4,"Connect")
PrtColText(2,14,7,9," ")
PrtColText(2,19,0,4,"Port")
PrtColText(2,23,7,9," ")
PrtColText(2,24,7,9," ")
PrtColText(2,34,7,9," ")
PrtColText(2,37,0,4,"Baud")
PrtColText(2,41,7,9," ")
PrtColText(2,42,7,9," ")
PrtColText(2,48,7,9," ")
OrigColor(LoWord(Corig), HiWord(Corig))
#endif
End Sub
Sub InfoBar2()
#ifdef __FB_WIN32__
PrtColText(2,1,7,9," ")
PrtColText(2,7,0,4,"Disconnect")
PrtColText(2,23,7,9," ")
PrtColText(2,30,7,9," ")
PrtColText(2,36,7,9," ")
PrtColText(2,42,0,4,"Echo")
PrtColText(2,46,7,9," ")
PrtColText(2,48,7,9," On")
PrtColText(2,51,7,9," ")
PrtColText(2,53,0,4,"Send Number")
PrtColText(2,64,7,9," ")
PrtColText(2,66,0,4,"Cls")
PrtColText(2,69,7,9," ")
View Print 3 To HiWord(Width)
OrigColor(LoWord(Corig),HiWord(Corig))
Locate 3,1,0
#else
PrtColText(2,1,7,9," ")
PrtColText(2,7,0,4,"Disconnect")
'PrtColText(2,23,7,9," ")
'PrtColText(2,30,7,9," ")
PrtColText(2,37,7,9," ")
PrtColText(2,42,0,4,"Echo")
PrtColText(2,46,7,9," ")
PrtColText(2,48,7,9," On")
PrtColText(2,51,7,9," ")
PrtColText(2,53,0,4,"Send Number")
PrtColText(2,64,7,9," ")
PrtColText(2,66,0,4,"Cls")
PrtColText(2,69,7,9," ")
View Print 3 To HiWord(Width)
OrigColor(LoWord(Corig),HiWord(Corig))
Locate 3,1,0
#endif
End Sub
Sub PrtColText(ByVal x As Integer, ByVal y As Integer, ByVal color1 As Integer, ByVal color2 As Integer, ByRef text As String)
Locate x,y
Color color1,color2
Print text
End Sub
Sub OrigColor(ByVal loval As UInteger, ByVal hival As UInteger)
Color loval,hival
End Sub
Sub TextCursor()
column = Pos
row = CsrLin
If Timer - t > .5 Then
flag = Not(flag)
If flag Then
Print "_"
Else
Print " ";
EndIf
Locate row,column
t = Timer
EndIf
End Sub
Sub sendnum()
Input "Enter a number to send (0 - 255) space delimited";numtosend
pos1 = InStr(numtosend, " ")
If pos1 = 0 And Len(numtosend) > 0 Then
Print #1, Chr$(Val(numtosend));
Print Chr$(Val(numtosend));
Else
numtosend2 = Val(Left$(numtosend,pos1))
Print #1, Chr$(numtosend2);
Print Chr$(numtosend2);
Do While pos1 > 0
pos2 = pos1
pos1 = InStr(pos1+1, numtosend, " ")
numtosend2 = Val(Mid$(numtosend,pos2+1,pos1-pos2))
Print #1, Chr$(numtosend2);
Print Chr$(numtosend2);
Loop
EndIf
''''''''' Get rid of garbage char '''''
row1 = CsrLin ' Get row position
column1 = Pos ' Get column position
Locate row1,(column1-1)
Print " " ' Get rid of garbage char
Locate row1,(column1-1)
End Sub