MyTerminal prog

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

Post by dasyar »

I just tested it out with the dim double, and it works as expected. I ran a win version of FBterm on one side, and DOS version on the other side, I liked it but I am bias. One thing I noticed that with Hyperterm, when I was typing in the chars it reacted very slow, in other words if I typed in 5 chars only two chars would pop on the Hyperterminal side, then the third one, and then the forth one, and then finally the fifth char. With FBterm the reaction time was much faster.

Now I am going to clean up the code, make some comments, and see what else has to be done before I post the code.


Merry Christmas everyone.
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

Hmm, I wasn't able to test the dos compiled version. I did test it compiled with windows and didn't see the character delays you saw.

I have a few of suggestions for possible additions to your program.
1. A selection for local echo on or off.
2. A selection to capture data to a file.
3. Macro recorder and function to send the macro of common character sequences to send.
4. Detection in you program source to detect whether your compiling for windows. If your compiling for windows the you can enumerate your available ports and have the port selection changed accordingly.
5. (more difficult) Implement a scroll buffer.
6. (way more difficult) Implement terminal emulations (i.e. ANSI, VT100, etc.).
7. Debug mode that shows the ascii code (i.e. a CR/LF would show as <13><10> or as <0D><0A>). This is very useful for serial communications debugging.

These are just ideas. I'm not saying they are completely necessary.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Post by dasyar »

This is the latest version of FBterm, now it has a text cursor in the terminal area thanks to phishguy. Now I am going to think some more about what the next step should be.

Since I will be running this on a DOS system using DOS-C, maybe the next step should be is to have a way of moving files back and forth. Of course the files will be larger than what would fit on a floppy disk. At a 115200 BAUD hookup, I wonder how long it would take to transfer a 5MB file, or for that matter a 15MB file? Does this sound feasible for FBterm?

Thanks

Code: Select all

' FBterm.bas
' FBterm.exe
' Started on December 6, 2008
' December 25, 2008 Ver .07


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Grabs the exiting values of the command prompt window
'1 = cursor on, and 0 = cursor off
locate ,,1              'This locates the cursor at 0,0 position
  dim as integer oldcolor = color
  dim as integer oldwidth = width
cls

'New code goes here
Screen 12                       'Selects the screen resolution

Dim Corig As Uinteger
Dim As Integer pos1,pos2,b,p,column,row,flag
Dim As String Key,buffer
Dim numtosend As String
Dim numtosend2 As Ubyte
Dim t As Double

Dim As String baud(0 To 9) = {"110","300","1200","2400","4800","9600","19200","38400","57600","115200"}
Dim As String port(0 To 3) = {"COM1:","COM2:","COM3:","COM4:"}

Corig = Color()

'Variables for the mouse info '''''''''''''''''''''
Dim x As Integer, y As Integer, buttons As Integer
Dim res As Integer
'''''''''''''''''''''''''''''''''''''''''''''''''''

'Subroutines, Functions, and etc ''''''''''''''''''
Sub PrtColText(Byval x As Integer, Byval y As Integer,Byval colour1 As Integer, Byval colour2 As Integer ,Byref text As String)
  Locate x,y
  Color colour1,colour2
  Print text
End Sub

Sub OrigColor(Byval loval As Uinteger,Byval hival As Uinteger)
  Color loval,hival
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

begin:
Locate 1,1
View Print 1 To hiword(Width)
'This displays the Title bar
'PrtColText(locate y,locate x,color foreground, color background, " text "
'          y x f b
PrtColText(1,1,7,9,"RBterm")
PrtColText(1,7,7,9,"                                                                          ")
PrtColText(2,1,0,4,"F1")
PrtColText(2,3,7,9," - ")
PrtColText(2,6,7,9,"      ")
PrtColText(2,12,0,4,"F2")
PrtColText(2,14,7,9," - ")
PrtColText(2,17,7,9,"      ")
PrtColText(2,23,0,4,"F3")
PrtColText(2,25,7,9," - ")
PrtColText(2,27,7,9,"          ")
PrtColText(2,37,0,4,"F10")
PrtColText(2,40,7,9," - Quit")
PrtColText(2,47,7,9,"                                  ")
Locate 2,6
Print baud(b);
Locate 2,17
Print port(p);
Locate 2,27
Print "Connect";
OrigColor(loword(Corig),hiword(Corig))

Do

'Mouse cursor location code ''''''''''''''''''''
  res = getmouse (x, y, ,buttons)

'''''''''''''''''''''''''''''''''''''''''''''''''
'loop while inkey = ""
  Key = Inkey$
'''''''''''''''''''' F10 ''''''''''''''''''''''''''''''''''''
  If Key = Chr$(255) & Chr$(68) Then    'F10 Quit the program
      Close #1
      View Print 1 To hiword(Width)
      Cls
      Goto cend
  End If
   If x > 288 And x < 312 And y > 15 And y < 30 And buttons And 1 Then  'Mouse
      Close #1
      View Print 1 To hiword(Width)
      Cls
      Sleep 5,1
      Goto cend   
   End If
'''''''''''''''''''''''' F3 ''''''''''''''''''''''''''''''''''''
  If Key = Chr$(255) & Chr$(61) Then     'F3 Connection
     Exit Do
  End If
  If x > 176 And x < 191 And y > 15 And y < 30 And buttons And 1 Then 'Mouse
      Sleep 255,1
      Exit Do
  End If
'''''''''''''''''''''''' F1 ''''''''''''''''''''''''''''''''''''
  If Key = Chr$(255) & Chr$(59) Then      'F1 Baud selection
      b += 1
      If b = 10 Then b = 0
      Locate 2,6
      Color 7,9
      Print "      "
      Locate 2,6
      Print baud(b);
   End If
   If x > 0 And x < 16 And y > 15 And y < 30 And buttons And 1 Then  'Mouse
      b += 1
      If b = 10 Then b = 0
      Locate 2,6
      Color 7,9
      Print "      "
      Locate 2,6
      Print baud(b);
      Sleep 250,1
   End If
''''''''''''''''''''''''' F2 ''''''''''''''''''''''''''''''''''''
   If Key = Chr$(255) & Chr$(60) Then        'F2 Port selection
      p += 1
      If p = 4 Then p = 0
      Locate 2,17
      Color 7,9
      Print "      "
      Locate 2,17
      Print port(p);
   End If
   If x > 87 And x < 104 And y > 15 And y < 30 And buttons And 1 Then  'Mouse
      p += 1
      If p = 4 Then p = 0
      Locate 2,17
      Color 7,9
      Print "      "
      Locate 2,17
      Print port(p);
      Sleep 250,1
   End If


  Sleep 1
Loop
PrtColText(2,1,7,9,"Baud")
PrtColText(2,12,7,9,"Port")
PrtColText(2,27,7,9,"Disconnect")
'PrtColText(3,1,0,4,"F4")
'PrtColText(3,3,7,9," - send a number")
PrtColText(2,60,0,4,"F4")
PrtColText(2,62,7,9," - send a number")

View Print 3 To hiword(Width)
OrigColor(loword(Corig),hiword(Corig))
'locate 1,3,1
Locate 1,3,0

Open Com port(p) & baud(b) & ",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

'This is the Main do ... loop
t = Timer
Do
'Mouse cursor location code ''''''''''''''''''''
  res = getmouse (x, y, ,buttons)

'''''''''''''''''''''''''''''''''''''''''''''''''
   Key = Inkey$

'''''''''''''''''''''' Text cursor ''''''''''''''
column = Pos
row = Csrlin
  if Key = chr$(13) then
     print #1, chr$(10);
     print chr$(10);
  end if

  if timer - t > .5 then
     flag = not(flag)
    if flag then
      Print "_";
    else
      print " ";
    end if
          
    Locate row,column
    t = timer
  end if
 
       
'''''''''''''''''''''''''' F10 ''''''''''''''''''''''
   If Key = Chr$(255) & Chr$(68) Then    'F10 Quit
      Close #1
      View Print 1 To hiword(Width)
      Cls
      Sleep 5,1
      Goto cend
'   Exit Do
   End If
   If x > 288 And x < 312 And y > 15 And y < 30 And buttons And 1 Then  'Mouse
      Close #1
      View Print 1 To hiword(Width)
      Cls
      Sleep 5,1
      Goto cend
   End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''
   If Key = Chr$(255) & Chr$(61) Then    'F3 Disconnect
      Close #1
      View Print 1 To hiword(Width)
      PrtColText(2,60,7,9,"                  ")
      OrigColor(loword(Corig),hiword(Corig))
      Cls
      Goto begin
   End If
   If x > 176 And x < 191 And y > 15 And y < 30 And buttons And 1 Then 'Mouse
      Close #1
      View Print 1 To hiword(Width)
      PrtColText(2,60,7,9,"                  ")
      OrigColor(loword(Corig),hiword(Corig))
      Sleep 240,1
      Cls
      Goto begin
   End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   If Key = Chr$(255) & Chr$(59) Then
      Print "ERROR - Do a DISCONNECT first!"
      Key = Chr$(8)
   End If
   If Key = Chr$(255) & Chr$(60) Then
      Print "ERROR - Do a DISCONNECT first!"
      Key = Chr$(8)
   End If

   If x > 470 And x < 488 And y > 15 And y < 30 And buttons And 1 Then
      Goto F4code
   End If
   If Key = Chr$(255) & Chr$(62) Then     'F4 key
F4code:
      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
   End If

   If Key <> "" Then
       Locate row,column
       Print " ";
       Locate row,column
      If Key = Chr$(13) Then
          Print #1, Chr$(13);
          Print Chr$(10);
     Else
      Print #1,Key;
      Print Key;
      End If
   End If

   While Loc(1) > 0
       buffer = Input$(Loc(1),#1)
       Print buffer;
   Wend

Sleep 1

Loop
'End of Main do ... loop

cend:
View Print 1 To hiword(Width)

Cls


' Restore the command prompt window to the old settings
  width oldwidth and &hFFFF, oldwidth shr 16
  color oldcolor and &hFFFF, oldcolor shr 16
  view print 1 to oldwidth shr 16


vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

5,000,000 / (115200 / 8) = 347 seconds (5.78 minutes)

-Vince
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

@vdecampo
Since in serial communication you would have 8 data bits, 1 start bit, and 1 stop bit, there ends up being 10 bits to send 1 byte of data. So, the calulation would be:

5,000,000 / (115200/10) = 434 seconds = 7 Min, 14 seconds.

This would be best case and wouldn't be taking into account any handshaking or error detection.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Post by dasyar »

I have a new project that I just started, which involves using my FBterm program to communicate with my Parallax Propeller via BlueTooth. What I need to do is create some commands that FBterm will use for screen control. From the Propeller side I would like to be able to send some screen control commands, like clear screen, cursor movement, and other stuff.

I need some suggestions as to what would be the best way to accomplish this. Do I just start to trap the characters in my input section, and handle the request with a specific subroutine? Or is there a better way to approach this?

What I have in mind right now is, when I connect with the Propeller, I need a menu to be presented, when requested with a 'help' command. I do not want the menu to keep scrolling off the screen, I would like the screen to be cleared, and the menu to be refreshed at the top. But, I do not want it to be a permanent menu. There will be a dialog that will be occurring with the Propeller, and commands will be typed in, which the Propeller will be responding too.

So, does anybody have any ideas as to how I should approach this? All ideas are welcome.

Thanks
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

Since you are using a graphics screen for your terminal, you should be able to create a simple GUI menu. You could trap a certain key to pull up the GUI menu.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Post by dasyar »

Just ran into an interesting problem, on my main desktop computer I have a Zoom BlueTooth USB adapter, and my program works just fine. I installed billionton BlueTooth adapter with BlueSoleil ver 1.6 on another computer, and my program can not open the port. But, when I try Hyperterminal, it has no problem making the connection. Has anybody run into this problem? Any ideas as to how to solve it?

Thanks
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

I know that this sounds weird, but set the receive buffer to around 10000 nor so. I ran into the same exact issue when using Blue Soleil drivers and I spent several days trying to figure out why it didn't work. I really dislike the Blue Soleil Bluetooth drivers as I've run into multiple problems getting them to work with various programs. I much prefer to use Bluetooth adapters that can use the default XP or Vista drivers.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Post by dasyar »

Thanks phishguy, that did the trick. Out of curiosity, how did you come up with 10000 as the number? Was it luck, or some heavy math?
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

Probably just about any number would work. I just stuck with the first number that I tried because I didn't want to mess with it any more when it started working.
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Post by dasyar »

After looking at this long thread, I think it needs a simple example of a working terminal program. So, I cleaned up some code, and this should be a good start for the beginner. I have not tried it, but it should compile for DOS, and Linux, also.

Code: Select all

'SimTerm.bas
'Simple terminal program
'October 18, 2009

Dim As String Key,buffer

'Change the Com port and BAUD rate to what you need
Open Com "COM1:9600,n,8,1,cs0,ds0,cd0,rs" As #1

Print "SimTerm, a simple terminal program."

'main serial send/receive routine
Do

   Key = Inkey$

	If Key = Chr$(27) Then    'Esc key
		Exit Do                'End the program
	End If

   If Key <> "" Then
   	If Key = Chr$(13) Then  'This handles CR/LF
   		Print #1, Chr$(13);
   		Print Chr$(10);
   	Else
   		Print #1,Key;        'Send the char 
   		Print Key;           'This is the echo
   	End If
   End If

'Check for input
    While Loc(1) > 0
        buffer = Input$(Loc(1),#1) 'Grab a char
        Print buffer;              'Print the char
    Wend

Sleep 1,0
Loop

'close the port(s)
Close

Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Post by Dinosaur »

Hi all

dasyar, it does work, but one minor improvement.
I never rely on a filehandle (#1) being available.

Code: Select all

'SimTerm.bas
'Simple terminal program
'October 18, 2009

Dim As String Key,buffer
Dim As Integer cp

'Change the Com port and BAUD rate to what you need
cp = FreeFile
Open Com "COM1:9600,n,8,1,cs0,ds0,cd0,rs" As #cp

Print "SimTerm, a simple terminal program."

'main serial send/receive routine
Do

   Key = Inkey$

        If Key = Chr(27) Then    'Esc key
                Exit Do                'End the program
        End If

   If Key <> "" Then
           If Key = Chr(13) Then  'This handles CR/LF
                   Print #cp, Chr(13);
                   Print Chr(10);
           Else
                   Print #cp,Key;        'Send the char
                   Print Key;           'This is the echo
           End If
   End If

'Check for input
    While Loc(cp) > 0
        buffer = Input(Loc(cp),#cp) 'Grab however many there are.
        Print buffer;              'Print the char
    Wend

Sleep 1,0
Loop

'close the port(s)
Close
This worked in Windows without a problem. It also helped me solve my problem. I have done a lot of serial port programming in asm, but never in FB. So replacing my open statement,

Code: Select all

Open "Com3:9600,N,8,1,RS,DS0,CS0" For Random As #CP
with yours, solved the problem.

Regards
DJS2009
Posts: 5
Joined: Nov 19, 2009 12:21
Location: Germany

You made my day

Post by DJS2009 »

Thanks a lot for this little Terminal Program it helped a lot.

Btw : I had to change this

From:

Code: Select all

Print #cp, Chr(13);
Print Chr(10);


to:

Code: Select all

Print #cp, Chr(13);
Print #cp, Chr(10);
Print Chr(10);
otherwise the CR / LF does not work properly on my system.


Regards
DJ
dasyar
Posts: 372
Joined: Dec 04, 2008 15:31

Post by dasyar »

I had to use my FBterm program for a project that I just started. So, I looked at the code, made some revisions, and tried to make it easier to read. I am not sure if anybody is using this, but here it goes anyway.

The original intent of this program was to have it run on a DOS machine, possibly without a mouse. That is why I use the red tabs labeled F1, F2, F3, F10, and F4. If it is compiled using FBC for DOS, it should run as described. I do not have a DOS machine setup, so I cannot test it. When this code is compiled with FBC for windows, this also works. The F1, F2, F3, F10, and F4 keys are non functional as a function key press, only a mouse click works. I tried to keep this as simple, and intuitive as possible. Obviously their is a lot of stuff that could be added, like an echo/non-echo selection, for one example.

A brief description of the red tabs:
F1 - Baud Selection. Baud rate goes up to 230400.

F2 - Port Selection. Now has COM1: ... COM10:, and COM20:, COM21:.

F3 - Connect/Disconnect

F10 - Quit. This quits the program, the red square with an |X| does not work!

F4 - This is for sending pure numbers (0-255), and not alphanumeric characters. For a series of numbers, use a space as the delimiter.

Since I use Win 7, and it does not come with a free Hyperterminal program, I am thinking that my next project will be a terminal program written in Visual C#, because I want it to be a GUI program. For prototype work, that requires a quick and dirty solution, I will still be using freeBASIC.

Enjoy, if that is possible.


Code: Select all

' FBterm.bas
' FBterm.exe
' Original Started 0n December 6, 2008
' November 30, 2010 Ver .01

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' For DOS
' Grabs the existing values of the Command Prompt Window
' 1 = cursor on, and 0 = cursor off
Locate ,,1     'This locates the cursor at 0,0 position
  Dim As Integer oldcolor = Color
  Dim As Integer oldwidth = Width
Cls

' New code goes here
Screen 12

Dim Corig As UInteger
Dim As Integer b,p,pos1,pos2,column,row,flag
Dim As String Key,buffer
Dim numtosend As String
Dim numtosend2 As UByte
Dim t As Double

Dim As String baud(0 to 10) = {"110","300","1200","2400","4800","9600","19200","38400","57600","115200","230400"}
Dim As String port(0 To 11) = {"COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","COM7:","COM8:","COM9:","COM10:","COM20:","COM21:"}

''''' Vaiables for mouse ''''''''''
Dim x As Integer, y As Integer, buttons As Integer
Dim res As Integer
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Corig = Color()


''''' Subroutines, Functions, and etc, '''''''''''
Sub PrtColText(ByVal x As Integer, ByVal y As Integer, ByVal colour1 As Integer, ByVal colour2 As Integer, ByRef text As String)
	Locate x,y
	Color colour1, colour2
	Print text
End Sub

Sub OrigColor(ByVal loval As UInteger,ByVal hival As UInteger)
	Color loval,hival
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''' Program Start ''''''''''
begin:
Locate 1,1
View Print 1 To HiWord(Width)

'PrtColText(locate y,locate x,color foreground, color background," text "
'          y x f b    text
PrtColText(1,1,7,9,"FBterm")
PrtColText(1,7,7,9,"                                                                          ")
PrtColText(2,1,0,4,"F1")
PrtColText(2,3,7,9," - ")
PrtColText(2,6,7,9,"      ")
PrtColText(2,12,0,4,"F2")
PrtColText(2,14,7,9," - ")
PrtColText(2,17,7,9,"      ")
PrtColText(2,23,0,4,"F3")
PrtColText(2,25,7,9," - ")
PrtColText(2,27,7,9,"          ")
PrtColText(2,37,0,4,"F10")
PrtColText(2,40,7,9," - Quit")
PrtColText(2,47,7,9,"                                  ")
Locate 2,6
Print baud(b);
Locate 2,17
Print port(p);
Locate 2,28
Print "Connect";
OrigColor(loword(Corig),hiword(Corig))

''''' Main do ... loop '''''
Do

' Mouse cursor location code '''''''''
  res = GetMouse (x,y, ,buttons)
''''''''''''''''''''''''''''''''''''''
	
' loop while inkey = ""
  Key = InKey$

'''''''''' F10 ''''''''''
''''' Checks for a Function key press, then a mouse click '''''''''
  If Key = Chr$(255) & Chr$(68) Then   ' F10 Quit the program
  	 Close #1
  	 View Print 1 To HiWord(Width)
  	 Cls
  	 GoTo cend
  EndIf
  If x > 288 And x < 312 And y > 15 And y < 30 And buttons And 1 Then
  	Close #1
  	View Print 1 To HiWord(Width)
  	Cls
  	Sleep 5,1
  	GoTo cend
  EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''' F3 ''''''''''
  If Key = Chr$(255) & Chr(61) Then    ' F3 - Connection
  	Exit Do
  EndIf
  If x > 176 And x < 191 And y > 15 And y < 30 And buttons And 1 Then
  	Sleep 255,1
  	Exit Do
  EndIf
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 

'''''''''' F1 ''''''''''
  If Key = Chr$(255) & Chr$(59) Then    ' FI - Baud Selection
  	b += 1
  	If b = 11 Then b = 0
  	Locate 2,6
  	Color 7,9
  	Print "      "
  	Locate 2,6
  	Print baud(b);
  EndIf
  If x > 0 And x < 16 And y > 15 And y < 30 And buttons And 1 Then
  	b += 1
  	If b = 11 Then b = 0
  	Locate 2,6
  	Color 7,9
  	Print "      "
  	Locate 2,6
  	Print baud(b);
  	Sleep 250,1
  EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''' F2 ''''''''''
  If Key = Chr$(255) & Chr$(60) Then     ' F2 - Port Selection
  	p += 1
  	If p = 12 Then p = 0
  	Locate 2,17
  	Color 7,9
  	Print "      "
  	Locate 2,17
  	Print port(p);
  EndIf
  If x > 87 And x < 104 And y > 15 And y < 30 And buttons And 1 Then
  	p += 1
  	If p = 12 Then p = 0
  	Locate 2,17
  	Color 7,9
  	Print "      "
  	Locate 2,17
  	Print port(p);
  	Sleep 250,1
  EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sleep 1
Loop

''''' Activate the RED tabs ''''''''''
PrtColText(2,1,7,9,"Baud")
PrtColText(2,12,7,9,"Port")
PrtColText(2,27,7,9,"Disconnect")
PrtColText(2,37,7,9,"          ")  'Blocks out quit
PrtColText(2,60,0,4,"F4")
PrtColText(2,62,7,9," - send a number")

View Print 3 To HiWord(Width)
OrigColor(LoWord(Corig),HiWord(Corig))
Locate 1,3,0

Open Com port(p) & baud(b) & ",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

' This is the main do ... loop
t = Timer
Do
	res = GetMouse(x,y, ,buttons)
	
	Key = InKey$

''''' Text cursor '''''
column = Pos
row = CsrLin
  If Key = Chr$(13) Then
  	Print #1, Chr$(10);
  	Print Chr$(10);
  EndIf
  
  If Timer - t > .5 Then
  	flag = Not(flag)
  	If flag Then
  		Print "_";
  	Else
  		Print " ";
  	EndIf
  	
  	Locate row,column
  	t = timer
  EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	
	
'''''''''' F10 '''''''''''
  If Key = Chr$(255) & Chr$(68) Then     ' F10 - Quit
  	Close #1
  	View Print 1 To HiWord(Width)
  	Cls
  	Sleep 5,1
  	GoTo cend
  EndIf
  If x > 288 And x < 312 And y > 15 And y < 30 And buttons And 1 Then
  	Close #1
  	View Print 1 To HiWord(Width)
  	Cls
  	Sleep 5,1
  	GoTo cend
  EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''' F3 '''''''''''
If Key = Chr$(255) & Chr$(61) Then      'F3 - Disconnect
	Close #1
	View Print 1 To HiWord(Width)
	PrtColText(2,60,7,9,"                 ")
	OrigColor(LoWord(Corig),HiWord(Corig))
	Cls
	GoTo begin
EndIf
If x > 176 And x < 191 And y > 15 And y < 30 And buttons And 1 Then
	Close #1
	View Print 1 To HiWord(Width)
	PrtColText(2,60,7,9,"                 ")
	OrigColor(LoWord(Corig),HiWord(Corig))
	Sleep 240,1
	Cls
	GoTo begin
EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''' F4 related code '''''''''''
  If x > 470 And x < 488 And y > 15 And y < 30 And buttons And 1 Then
  	GoTo F4code
  EndIf
  
  If Key = Chr$(255) & Chr$(62) Then
F4code:
    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
  EndIf

''''' Capture the Key press ''''''''''
  If Key <> "" Then
  	Locate row,column
  	Print " ";
  	Locate row,column
  	If Key = Chr$(13) Then
  		Print #1, Chr$(13);
  		Print Chr$(10);
  	Else
  		Print #1,Key;
  		Print Key;
  	EndIf
  EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''' Display incoming characters ''''''''''  
  While LOC(1) > 0
  	buffer = Input$(LOC(1),#1)
  	Print buffer;
  Wend
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Loop


' End of Main do ... loop

cend:
View Print 1 To HiWord(Width)

Cls

' Restore the Command Prompt Window
Width oldwidth And &hFFFF, oldwidth Shr 16
Color oldcolor And &hFFFF, oldcolor Shr 16
View Print 1 To oldwidth Shr 16


Post Reply