MyTerminal prog

For issues with communication ports, protocols, etc.
Post Reply
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

@ThisPlaceHere, glad to see that someone has found some interest in this program, and maybe it helped out, or at least shortened the programming part. I have not compiled and run the program yet; I bet you probably fixed some noticeable bugs, that I have not gotten around to fix yet.

The original intent of this program was to learn how too program using freebasic, I guess I got some things right, and other concepts still elude me. I was trying to come up with a very basic terminal program that could be used across different platforms.

Since I have started on a new project, using the MicroMite, and have been using the serial part of putty, it may be time to revisit my program for better use with or for the MicroMite. Not sure as to what the next step will be.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

In my previous post I mentioned my new project, using the MicroMite chip. It has a built in full screen editor which requires a VT100 terminal emulator to work properly, plus a cut and paste feature. Does anybody have any suggestions as to how I could implement those features to my terminal program? The documentation, for the MicroMite, suggest that TeraTerm would be a good terminal program to use, but because I would like to be able to use this across different platforms, maybe a custom terminal program should be developed. So, I would like to have some suggestions as to how to go about doing something like this.

Thanks
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

While I was using MyTerminal prog, I noticed some things I did not like, so I made some changes. One item was the extra CR in the terminal screen, fixed that. The other item was making the 'echo' a no echo as default. Also there were some discrepancies between the Windows and Raspberry Pi (Linux) menu panels, fixed that.

While working with the menu selection code, I found that to be a real PIA. Does anybody know of a prebuilt menu selection program for FBC? I guess what I would need is a menu skeleton program where you would attach your freeBasic code to your own named menu panels, in the skeleton program. Not sure that I have seen anything like that in this forum, correct me if I am wrong.
Since I think, in my humble opinion, that it would easier to do a good terminal program in a non GUI method, I would like to try something like what they used to have in the DOS days.

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
' Version 2.0 revision 05
' - Corrected menu panel to match 
' - what is needed for Raspberry Pi (Linux).
' - Corrected live lerminal CR spacing.
' - Corrected 'End If' that were 'endif'
' - for 'If Then' loops.
' - Changed 'echo' to default 'off'.

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/ttyUSB2:","/dev/tty00:"}
#endif
Dim As String echo(0 To 1) = {"Off"," On"}

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
	End If
'''''''''''''''''''''''''''''''''''''''

'''''''''' 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
	End If
'''''''''''''''''''''''''''''''''''''''

'''''''''' 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
	End If
#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
		print "            "
		Color 7,9
		Locate 2,24
		Print port(p);
		Sleep 200,1
	End If
#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
	End If
#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,41
		Print baud(b);
		Sleep 200,1
	End If
#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
End If



Do
res = GetMouse (x, y, , buttons)
Key = InKey$
TextCursor()



'''''''''' Mouse over Disconnect '''''''''
	If x > 49 And x <= 128 And y > 16 And y < 31 And buttons And 1 Then 
		Close #1
		OrigColor(LoWord(Corig),HiWord(Corig))
		Sleep 200,1
		Cls
		GoTo begin
	End If
'''''''''''''''''''''''''''''''''''''''

#ifdef __FB_WIN32__
''''''''' Mouse over echo '''''''''''''
	If x > 328 And x <= 360 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
	End If
'''''''''''''''''''''''''''''''''''''''

''''''''' Mouse over Send Number ''''''
	If x > 416 And x <= 500 And y > 16 And y < 31 And buttons And 1 Then
		sendnum()
	End If
'''''''''''''''''''''''''''''''''''''''

''''''''' Mouse over Cls ''''''''''''''
	If x > 520 And x <= 544 And y > 16 And y < 31 And buttons And 1 Then
		Cls
	End If
'''''''''''''''''''''''''''''''''''''''
#else
	If x > 368 And x <= 400 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,51
		Color 7,9
		Print "    "
		Locate 2,53
		Print echo(e);
		View Print 3 To HiWord(Width)
		Color 7,0
		Cls
		Sleep 200,1
	End If
'''''''''''''''''''''''''''''''''''''''

''''''''' Mouse over Send Number ''''''
	If x > 448 And x <= 532 And y > 16 And y < 31 And buttons And 1 Then
		sendnum()
	End If
'''''''''''''''''''''''''''''''''''''''

''''''''' Mouse over Cls ''''''''''''''
	If x > 544 And x <= 568 And y > 16 And y < 31 And buttons And 1 Then
		Cls
	End If


#endif


'''''''''' Terminal Screen ''''''''''''
	If Key <> "" Then


		If Key = Chr$(13) Then ' Check for CR
			Print #1, Chr$(13); ' Send LF
			'Print Chr$(10); ' Local LF 'Local not needed 6/28/15
		Else
			Print #1,Key;
			If echo(e) = "Off" Then
				'Print Key;
			Else
				'Echo on
				Print Key;
			End If
		End If
	End If

	While LOC(1) > 0
		buffer = Input$(LOC(1),#1)
		Print buffer;
		'print #1, chr$(10); 'Removed 6/28/15 - fixed line add in term
	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,35,7,9,"  ")
PrtColText(2,37,0,4,"Baud")
PrtColText(2,41,7,9," ")
PrtColText(2,42,7,9,"      ")
PrtColText(2,46,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,"Off")
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,47,0,4,"Echo")
PrtColText(2,52,7,9," ")
PrtColText(2,53,7,9,"Off")
PrtColText(2,56,7,9," ")
PrtColText(2,57,0,4,"Send Number")
PrtColText(2,68,7,9," ")
PrtColText(2,69,0,4,"Cls")
PrtColText(2,72,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 " ";
	End If
	Locate row,column
	t = Timer
End If
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
End If
''''''''' 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

jmg
Posts: 89
Joined: Mar 11, 2009 3:42

Re: MyTerminal prog

Post by jmg »

Since I think, in my humble opinion, that it would easier to do a good terminal program in a non GUI method, I would like to try something like what they used to have in the DOS days.
This looks cool.
I did not read all the posts, but I'd suggest two terminal designs.

A VT100 type with cursor address, and a simpler command screen style

a)
Simple command-line, and very portable, that can do useful mix of Kbd/File/Com/screen
eg
Kbd -> COMx and COMx -> screen
File -> COMx and COMx -> screen
FileA -> COMx and COMx -> FileB
Kbd -> COMx and COMx -> FileC (etc)

The screen side of this supports CrLf, but no cursor address. It would display VT100 streams, but not parse them.

Basically uses simple PRINT, in a choice of CHR and HEX modes.
The code will be simple and very portable, and in many cases, enough for users.

b) VT100 - Adds Cursor and other VT100 features to a) - not as simple, and slower, but more powerful.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: MyTerminal prog

Post by MrSwiss »

A somewhat updated version of FBterm:

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
' Version 2.0 revision 05
' - Corrected menu panel to match
' - what is needed for Raspberry Pi (Linux).
' - Corrected live lerminal CR spacing.
' - Corrected 'End If' that were 'endif'
' - for 'If Then' loops.
' - Changed 'echo' to default 'off'.
' =================================================
' MrSwiss changes: 2016-02-18
' - reformated code for "readability"
' - converted If Then Else EndIf to single Line IF
'   (where it makes sense)
' - added comments (where needed)
' - replaced Integer(s) with Long(s), for FBC x64
' - deleted all unneccessary "$" on keywords
' =================================================

Screen 12
Width 80,30
Locate ,,1

' Globals
Dim Shared As ULong		Corig	' Color is always a UINT32 !!!
Dim Shared As Double	t
Dim Shared As Long		column, row, pos1, pos2, row1, column1
Dim Shared As String	Key, buffer, numtosend
Dim Shared As UByte		numtosend2
' Locals
Dim As Boolean			flag	' typical use of Boolean(s)

''''''''' Headers for Functions and Subroutines '''''''''''
Declare Sub InfoBar()
Declare Sub InfoBar2()
Declare Sub PrtColText(ByVal x As Long, ByVal y As Long, ByVal color1 As ULong, ByVal color2 As ULong, ByRef text As String)
Declare Sub OrigColor(ByVal loval As ULong, ByVal hival As ULong)
Declare Sub TextCursor(ByRef flag As Boolean)	' hand flag over, instead of 'Shared' declaration
Declare Sub sendnum()

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Locals
Dim As Long b=7, p=2, e=0	' prefered startup: "115200", "COM3:", "Off"

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/ttyUSB2:","/dev/tty00:"}
#EndIf

Dim As String echo(0 To 1) = {"Off"," On"}

Dim As String Escape = Chr(27)
Dim As Long 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
   End If
'''''''''''''''''''''''''''''''''''''''

'''''''''' 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
   End If
'''''''''''''''''''''''''''''''''''''''

'''''''''' 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
   End If

#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
      print "            "
      Color 7,9
      Locate 2,24
      Print port(p);
      Sleep 200,1
   End If

#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
   End If

#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,41
      Print baud(b);
      Sleep 200,1
   End If

#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
End If


Do
	res = GetMouse (x, y, , buttons)
	Key = InKey
	TextCursor(flag)
	'''''''''' Mouse over Disconnect '''''''''
	If x > 49 And x <= 128 And y > 16 And y < 31 And buttons And 1 Then
		Close #1
		OrigColor(LoWord(Corig),HiWord(Corig))
		Sleep 200,1
		Cls
		GoTo begin
	End If
	'''''''''''''''''''''''''''''''''''''
#ifdef __FB_WIN32__
''''''''' Mouse over echo '''''''''''''
   If x > 328 And x <= 360 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
   End If
'''''''''''''''''''''''''''''''''''''''

''''''''' Mouse over Send Number ''''''
   If x > 416 And x <= 500 And y > 16 And y < 31 And buttons And 1 Then sendnum()
'''''''''''''''''''''''''''''''''''''''

''''''''' Mouse over Cls ''''''''''''''
   If x > 520 And x <= 544 And y > 16 And y < 31 And buttons And 1 Then Cls
'''''''''''''''''''''''''''''''''''''''
#Else

   If x > 368 And x <= 400 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,51
      Color 7,9
      Print "    "
      Locate 2,53
      Print echo(e);
      View Print 3 To HiWord(Width)
      Color 7,0
      Cls
      Sleep 200,1
   End If

''''''''' Mouse over Send Number ''''''
   If x > 448 And x <= 532 And y > 16 And y < 31 And buttons And 1 Then sendnum()
'''''''''''''''''''''''''''''''''''''''

''''''''' Mouse over Cls ''''''''''''''
   If x > 544 And x <= 568 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(13);	' Send CR
		Else
			Print #1,Key;
			If echo(e) <> "Off" Then Print Key + " ";	' add a space after command
		End If
	End If

	While LOC(1) > 0
		buffer = Input(LOC(1),#1)
		Print buffer;
	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,35,7,9,"  ")
	PrtColText(2,37,0,4,"Baud")
	PrtColText(2,41,7,9," ")
	PrtColText(2,42,7,9,"      ")
	PrtColText(2,46,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,"Off")
	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,47,0,4,"Echo")
	PrtColText(2,52,7,9," ")
	PrtColText(2,53,7,9,"Off")
	PrtColText(2,56,7,9," ")
	PrtColText(2,57,0,4,"Send Number")
	PrtColText(2,68,7,9," ")
	PrtColText(2,69,0,4,"Cls")
	PrtColText(2,72,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 Long, ByVal y As Long, ByVal color1 As ULong, ByVal color2 As ULong, ByRef text As String)
	Locate x,y
	Color color1,color2
	Print text
End Sub

Sub OrigColor(ByVal loval As ULong, ByVal hival As ULong)
	Color loval,hival
End Sub

Sub TextCursor(ByRef flag As Boolean)	' recoded MrSwiss
	column = Pos
	row = CsrLin
	If Timer - t > .5 Then
		flag = Not(flag)
		If flag Then Print "_" Else Print " ";
		Locate row,column
		t = Timer
	End If
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
	End If
	''''''''' 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
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

I have not been here for a while, and I noticed there has been some changes to the forum. So I had to try out some stuff.

First off, Thank You, MrSwiss, for some improvement to the program. I went ahead and compiled the updated program, using FB for linux, and it seemed to compile without any errors. It also started up when I clicked on the FBterm icon.

It seems like this thread has a lot of hits, I am just wondering if anybody is getting anything useful out of all this? I have been using a linux set up for a while, and when I have to use a serial program, I have been resorting to using putty or GTKterm or I just installed Tera Term via WINE. All of these are good programs, but, not bragging or anything, FBterm seems to be simple and easy to use, or it seems like that to me. I think I fixed all the bugs, or least there have not been any complaints.

Now I am not sure what else to do with this program, is it satisfactory for the intended use?
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: MyTerminal prog

Post by caseih »

The normal go-to serial terminal on Linux is minicom. If you were ever comfortable with Telix or similar programs from the DOS days, minicom will feel quite comfortable to you.

As to FBTerm, if anything it's a useful example of serial port programming in FB. And it's very short so it's easy to understand. I note that the main loop needs a sleep statement in it. As it was posted it spins 100% of the CPU. Adding a sleep 1 statement before the "loop" statement took care of that.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: MyTerminal prog

Post by MrSwiss »

@dasyar,

the latest updated Version of FBterm - renamed to FB-Terminal (WIN only) can be found here: FreeBasic and Arduino ...
All LIN stuff removed, also the preProcessor stuff, in Order to better "see" what's "going on".
New Color Scheme, more Contrast.
Quite heavy Re-Coding and Elimination of "not really useful" Sub's, Corig stuff (common knowledge: Color 7, 0).
Re-Coded NEW Printing Routine (different Parameter ordering, analogue to Draw String() ).

It is common to want Code "up and running" as soon as possible.
However, there are some pitfalls using this Approach:
  • optimizing later on, is a lot more difficult
    this is specially TRUE, if it is to be "cross compatible"
    using of "later" implemented Procedures, tends to be "forgotten" to be implemented in "MAIN" too
IMHO a better Approach is:
  • get it to run on one Target-OS first.
    Finalize UI-Code once, for all Targets the same. (IMPORTANT)
    Optimize Code until you can't do any better, then and only then:
    Add Pre-Processor Statements and the necessary Code for second Target.
I'm aware that the: /dev/tty/... stuff is longer than simply COM1: however, this is fixed by using a second
String Array that "holds" the actual Device Name only, for the "Display" (NOT the whole Path-Info).
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

I just tried compiling the new updated FBterm on my Raspberry Pi, and it came up with some errors. The errors were with the use of 'boolean', for flag and in Sub TextCursor(). I changed it to 'long' and it compiled it without errors.

On my Raspberry Pi I am using freeBASIC 1.01, so I am not sure where the problem is occurring. Since the Raspberry Pi is a 32 bit version, does that mean that FB does not support boolean in that version, or is there something else that is going on? Not sure how important the use of boolean is in the new FBterm version, since I only compiled it, without errors, and started FBterm, without really using it, I wonder what will happen next with the program, when I try to use it.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MyTerminal prog

Post by fxm »

Boolean came with version 1.04.0.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: MyTerminal prog

Post by MrSwiss »

Another good Reason to keep the Compiler current: ATM ver. 1.05.0 ...
A lot of other Bugs have been fixed, since ver. 1.01.0! (see changelog)
Appart from the Addition of Boolean Variables.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

Another good Reason to keep the Compiler current: ATM ver. 1.05.0 ...
I am using what is available, which is the package that TJF had put together for the Raspberry Pi and it has FB 1.01. Now that there is a Raspberry 3 available, hopefully somebody will put something together that uses the latest version of FB.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: MyTerminal prog

Post by St_W »

dasyar wrote:I am using what is available, which is the package that TJF had put together for the Raspberry Pi and it has FB 1.01. Now that there is a Raspberry 3 available, hopefully somebody will put something together that uses the latest version of FB.
You can find cutting-edge nightly builds of FBC here:
http://users.freebasic-portal.de/stw/builds/
For Raspberry Pi 1 choose "linux-armv6-rpi"; for Raspberry Pi 2 and 3 choose "linux-armv7a-hf-debian".
The package does contain the compiler+runtime only, so take additional headers and libraries from other sources. e.g. use the package to update (overwrite) the old compiler and runtime from TJF's package.

A note regarding RPI3: Although the Raspberry Pi 3 Hardware would support 64-Bit (ARMv8) systems, there is no suitable operating system (linux kernel) available yet. FreeBasic is ready for the day when such a system will be provided, but as of now RPI3 only supports 32-bit (as does RPI2). See also http://freebasic.net/forum/viewtopic.ph ... 77#p216977
[offtopic @Joshy: you see; your information is not useless at all ;-) ]

Unfortunately there are no official releases for RPI/ARM, so you can only use custom builds.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

I just came across this thread, and I noticed that it is a ten year old thread. Wow, how time flies … I also noticed, that the thread has a few views, which makes me think, did anybody get anything out of reading the whole thread.

I would like to thank, phishguy, again, for all the help that he had given me to develop the program. It was a very good way of getting to learn what FreeBASIC is all about. Unfortunately, I have noticed that phishguy does not frequent the forum anymore. He was an excellent tutor for this project. I guess I was very lucky, that he was around when I started to learn FreeBASIC. At this time, I do not see anybody that is doing anything like that any more.

Now, I look at this program and keep thinking what kind of improvements I could make to the program, if any, while still keeping the code and program as simple as possible. Probably I will wait and see where the forum ends up in terms of some new changes, like moderator(s). I have to say, ten years ago this site had a very different feel to it then it does today. Trying to be as objective as I can, it is a less friendly site than it used to be. So, I will leave it at that.

Thanks to everyone who helped me with this program.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Post by dasyar »

I am revisiting "MyTerminal prog", I tried to compile it using '-S gui', and I get:
C:\fbc\fbc -w -S gui all "fbterm.bas" (in directory: E:\programs\fbc\fbterm)
error 81: Invalid command-line option, "gui"
Compilation failed.
I am using Geany as my IDE, and I have 'FreeBASIC-1.07.1-win64' installed on my Widows 10 Pro system.

Thanks
Post Reply