You are assuming wrong, it gets sent Byte by Byte.
REASON: my Ardino-Sketch is using a Short (16bit Integer) to store incoming stuff.
A String would 'blow' that ...
Code: Select all
' FB-Terminal.bas
' FB-Terminal.exe - Windows only
' original code by: dasyar, FreeBASIC-Forum
'
' =================================================
' MrSwiss changes: 2016-02-18 / 24
' - renamed from FBterm.bas to FB-Terminal.bas
' - Windows only (deleted all Linux related stuff)
' - NO more conditional compiling directives
' - reformated code for "readability"
' - rewritten Printing Routine ( colrPrtPos() )
' - changed colors for more contrast
' - changed Button Positions (better distribution)
' - 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 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 Long b=4, p=2, e=1 ' prefered startup: "9600", "COM3:", "On"
Dim As Boolean flag ' typical use of Boolean(s)
Dim As String baud(0 To 7) = {"1200","2400","4800","9600","19200","38400","57600","115200"}
Dim As String port(0 To 9) = {"COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","COM7:","COM8:","COM9:","COM10:"}
Dim As String echo(0 To 1) = {"Off"," On"}
Dim As String Escape = Chr(27)
Dim As Long res, x, y, buttons
''''''''' Headers for Functions and Subroutines '''''''''''
Declare Sub InfoBar ()
Declare Sub InfoBar2()
Declare Sub ColrPrtPos( ByVal row As Long, ByVal col As Long, ByVal Stg As String, _
ByVal CFG As ULong=&hFF000000, ByVal CBG As ULong=&hFFFFFFFF )
Declare Sub TextCursor( ByRef flag As Boolean ) ' hand flag over, instead of 'Shared' declaration
Declare Sub sendnum ()
''''''''' Start of Program ''''''''''''
Cls
begin:
InfoBar()
ColrPrtPos(2,24,port(p),15,9)
ColrPrtPos(2,41,baud(b),15,9)
''''''''' Main Screen '''''''''''''''''
Do
res = GetMouse (x, y, , buttons)
Key = InKey
If Key = Escape Then Exit Do
''''''''''' Mouse over Quit '''''''''''
If x > 1 And x <= 32 And y > 16 And y < 31 And buttons And 1 Then GoTo Cend
'''''''''' 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 ''''''''''''
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
ColrPrtPos(2,24,space(10),,9)
ColrPrtPos(2,24,port(p),15,9)
Sleep 200,1
End If
'''''''''' Mouse over baud ''''''''''''
If x > 280 And x <= 312 And y > 16 And y < 31 And buttons And 1 Then
b += 1
If b = 8 Then b = 0
ColrPrtPos(2,41,space(8),,9)
ColrPrtPos(2,41,baud(b),15,9)
Sleep 200,1
End If
Loop
''''''''' End of Main Screen ''''''''''
''''''''' Live Terminal '''''''''''''''
InfoBar2()
View Print 1 To HiWord(Width)
ColrPrtPos(2,54,echo(e),15,9)
View Print 3 To HiWord(Width)
Color 7, 0 : cls
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
ColrPrtPos(3,1,"Error opening " & port(p),14,0)
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 : Color 7, 0 : Cls
Sleep 200,1 : GoTo begin
End If
''''''''' Mouse over echo '''''''''''''
If x > 384 And x <= 416 And y > 16 And y < 31 And buttons And 1 Then
e += 1 : If e > 1 Then e = 0
View Print 1 To HiWord(Width)
ColrPrtPos(2,54,space(4),,9)
ColrPrtPos(2,54,echo(e),15,9)
View Print 3 To HiWord(Width)
Color 7,0 : Cls : Sleep 200,1
End If
''''''''' Mouse over Send Number ''''''
If x > 500 And x <= 582 And y > 16 And y < 31 And buttons And 1 Then sendnum()
''''''''' Mouse over Cls ''''''''''''''
If x > 600 And x <= 624 And y > 16 And y < 31 And buttons And 1 Then
View Print 3 To HiWord(Width)
Color 7, 0 : Cls : Sleep 200,1
End If
'''''''''' Terminal Screen ''''''''''''
Color 7, 0
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()
Cls
Locate 1,1
View Print 1 To HiWord(Width)
ColrPrtPos(2, 1,Space(80),15,9)
ColrPrtPos(1, 1,Space(80),15,9)
ColrPrtPos(1,36,"FB-Terminal",15,9)
ColrPrtPos(2, 1,"Quit",15,4)
ColrPrtPos(2, 7,"Connect",15,4)
ColrPrtPos(2,19,"Port",15,4)
ColrPrtPos(2,36,"Baud",15,4)
Color 7, 0
End Sub
Sub InfoBar2()
View Print 1 To HiWord(Width)
ColrPrtPos(2, 1,Space(80),15,9)
ColrPrtPos(2, 7,"Disconnect",15,4)
ColrPrtPos(2,49,"Echo",15,4)
ColrPrtPos(2,54,"Off",15,9)
ColrPrtPos(2,63,"Send Number",15,4)
ColrPrtPos(2,76,"Cls",15,4)
View Print 3 To HiWord(Width)
Color 7, 0
End Sub
Sub ColrPrtPos( ByVal row As Long, _
ByVal col As Long, _
ByVal Stg As String, _
ByVal CFG As ULong = &hFF000000, _
ByVal CBG As ULong = &hFFFFFFFF )
If CFG <> &hFF000000 OrElse CBG <> &hFFFFFFFF Then Color(CFG, CBG)
Locate row, col : Print Stg; ' NO LF invoked!
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