MyTerminal prog

For issues with communication ports, protocols, etc.
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: MyTerminal prog

Postby TJF » Oct 09, 2014 17:24

dasyar wrote:..., but if all of a sudden an FBC compiler for the Raspberry Pi shows up, ...

Some are available ...

The Git version (1.01.0) is ready for boot-straping on RPi. dkl made a guide, which we fine tuned a bit. Now it runs fine on BBB / Debian and should work on RPi as well. (And there's a package for RPi from D. J. Peters, based on older sources.)

dasyar wrote:That is a log in session to my Raspberry Pi using the LAN, so maybe in place of a com port selection I enter an IP address, could I do it with the FBC compiler?

I log in to my BBB using ssh (either LAN or USB).
dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 09, 2014 19:22

Below is updated code, now it compiles with the FBC 1.0 64-bit, not sure what will happen with a 32-bit version compile, hopefully nothing. I changed a few lines, and added some more com port selections, nothing major. If there is a problem, note it here and I will see what should be changed unless you are feeling good and you provide some updated code.

Somewhere along the line I will have to try to port FBC to the Raspberry Pi, the instructions in the WiKi looked very straight forward, but I have not done anything like that before. I have one Raspberry Pi B+ setup as my Linux desktop, so I may have to try an install of FBC on that unit.

I use Putty as my command line access to my Raspberry Pi from my Windows 7 desktop, I was just thinking, as a learning experiment, to see if I could add something like that to my FBterm.bas program. But, just thinking about it, it may be a little more than what I can do, not sure how SSH would be handled with the FBC.

Code: Select all

' FBterm.bas
' FBterm.exe
' 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 {}

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"}
Dim As String port(0 To 9) = {"COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","COM7:","COM8:","COM9:","COM10:"}
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()
    Locate 2,24
    Color 7,9
    Print port(p);
    Locate 2,37
    Print baud(b);

''''''''' Main Screen '''''''''''''''''         
Do
    res = GetMouse (x, y, , buttons)

    Key = InKey$
   
    If Key = Escape Then   
        Exit Do
    EndIf

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

'''''''''' Mouse over baud ''''''''''''
   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
'''''''''''''''''''''''''''''''''''''''
   
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;
    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)
    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))
End Sub

Sub InfoBar2()
   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   
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

dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 11, 2014 13:20

So, I went ahead and installed FBC for the Raspberry Pi, luckily I found the binaries over in the Linux forum. I also installed Geany on my Raspberry Pi and on my Windows 7 desktop, I might as well start being consistent in my IDE programs.

The first problem that I ran into when trying to compile a simple .bas program was, -lncurses. I suggest, on the Raspberry Pi, doing a 'sudo apt-cache search ncurses', it comes up with a long list of files, but in there you should find a listing for 'libncursese5-dev'. The next step, of course, is 'sudo apt-get install libncurses5-dev', which should install the missing -lncurses. Since I use 'fbc -s gui xxxx.bas' for my Windows 7 compile, will 'fbc -s gui xxxx.bas' work on the Raspberry Pi, or do I have to install more missing libs? And of course, what would be the preferred GUI solution for a .bas program on the RPi?

As a trial run, I have another program called SimTerm.bas which I went ahead and compiled using Geany, on the Raspberry Pi, which worked after adding the missing lib. On my test hardware setup I have an XBee module plugged into the RPi USB port(/dev/ttyUSB0) and another XBee module plugged into my Windows 7 desktop. I started my FBterm.bas program on the Windows desktop, and I started SimTerm.bas on the RPi, and they were communicating as expected. On the RPi and on the Linux installs I think you have to setup some dialout privileges in order to get access to the /dev/ttyXXXX ports, but I am not sure if FBC does that for you when you compile a program that uses the tty ports.

Now I will be porting my FBterm.bas program to the RPi and see if I run into any problems.
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: MyTerminal prog

Postby TJF » Oct 11, 2014 15:23

dasyar wrote:Since I use 'fbc -s gui xxxx.bas' for my Windows 7 compile, will 'fbc -s gui xxxx.bas' work on the Raspberry Pi, or do I have to install more missing libs? And of course, what would be the preferred GUI solution for a .bas program on the RPi?

Option -s gui has no effect on LINUX systems,

The prefered GUI solution is always GTK+ (on all systems, including RPi).

dasyar wrote:As a trial run, I have another program called SimTerm.bas which I went ahead and compiled using Geany, on the Raspberry Pi, which worked after adding the missing lib. On my test hardware setup I have an XBee module plugged into the RPi USB port(/dev/ttyUSB0) and another XBee module plugged into my Windows 7 desktop. I started my FBterm.bas program on the Windows desktop, and I started SimTerm.bas on the RPi, and they were communicating as expected. On the RPi and on the Linux installs I think you have to setup some dialout privileges in order to get access to the /dev/ttyXXXX ports, but I am not sure if FBC does that for you when you compile a program that uses the tty ports.

Usually the user has to be a member of the 'dialout' group to access /dev/ttyXXXX (this may vary in different LINUX ports).

I don't understand what you're trying to do.

To control the RPi from your PC, connect the RPi to your LAN and just execute ssh username@RPi_IP_Addr at the commanmd line of your PC. You'll get a login prompt from the RPi. After login you'll have command line access on the RPi.

On a LINUX PC you can use ssh -X username@RPi_IP_Addr and you can run grafic applications as well. (I don't know if there's a similar ssh option on other OSs as well.)
dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 12, 2014 11:37

I don't understand what you're trying to do.

This is just a test run to see how my serial terminal programs would work. It was easier for me to just hook up an XBee module on each computer as opposed to creating a null modem cable to connect between the computers. Now that I am satisfied with the FB terminal program on the RPi, now I will start to develop a project using the RPi and have an XBee installed as a redundant backup that could be used if I move the unit to an area where I do not have a LAN hookup. I also have a WiFi module that I use, but I did notice there are dead spots where the WiFi gets no reception, hence the XBee backup.

I do want to make note that working with the FB serial is much easier, and in my opinion, much better than trying to do it using Python serial or C for that matter.

Not trying to derail my own thread, but on the RPi I had a Sensirion sht11 module working with a C program, that was available for the RPi. I guess my question is, is there such a program written in FB, or is there a way of using some of the C code within FB to have FB access the RPi GPIO to get readings from the sht11 module? I did do a search for sht11 on this forum and got one hit, but there was no relevant code that I could look at. If I get some information that leads me to believe that it possible to do this with freeBASIC, then I will start a thread of its own to describe my adventure into all this, as to how this could be done using freeBASIC.
dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 17, 2014 10:07

To get back on topic, I just tried to compile FBterm.bas on my Raspberry Pi, and I get the following: cannot find -IX11, IXext, IXpm, IXrandr, IXrender. Not sure what this means, I thought the Raspberry Pi had an X11 system installed, or is this pertaining to something different?
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: MyTerminal prog

Postby dkl » Oct 17, 2014 12:05

Perhaps the development libraries for X11 are not installed. On many Linux distros they are separate from the main X11 packages (e.g. libx11 vs libx11-dev) because they're not needed by "normal" users (only developers).
dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 17, 2014 12:32

After installing libx11-dev, now I get the following: cannot find -IXext, IXpm, IXrandr, IXrender. Took care of one item, not sure how to get the rest.
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: MyTerminal prog

Postby dkl » Oct 17, 2014 12:57

libx11-dev libxext-dev libxrender-dev libxrandr-dev libxpm-dev


Also see: /wiki/CompilerInstalling
dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 17, 2014 13:52

Thanks dkl for the nudge in the right direction. I did another compile, and all went well. Now I need some suggestions as to how to keep just one source code file that will compile for Windows or Linux or Raspberry Pi or whatever. The other thing that becomes inconsistent is my selection bar (port and baud), for Windows it is COMxx:, which I allocated the correct space. Now for the Linux/Raspberry Pi stuff I have /dev/ttyUSBx: or /dev/ttyxx: or /dev'ttyAMA0. Is there a way to have a specific selection bar for a Windows compile and a specific selection bar for a Linux compile all within the same program. This is starting to look like some very complex programming code, if there even is a way to do it.
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: MyTerminal prog

Postby dkl » Oct 17, 2014 13:56

dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 17, 2014 14:55

I just did a test run using #ifdef __FB_WIN64__ ... #else ... #endif, since I have FBC 64-bit installed, did not work correctly. When I changed it too WIN32, then it worked correctly. So, I take it that WIN32 covers the FBC 64-bit version? Will this be the consistent form or will there be specific WIN32 and WIN64 declarations down the road at some point?
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: MyTerminal prog

Postby dkl » Oct 17, 2014 18:04

That's right, __FB_WIN32__ refers to Windows as a whole, both 32bit and 64bit, much like the _WIN32 predefine used by Windows C compilers. But we have an additional __FB_64BIT__ define which allows Win32 and Win64 to be distinguished.

Code: Select all

#ifdef __FB_WIN32__
   #print "Windows"
#elseif defined(__FB_LINUX__)
   #print "Linux"
#endif

#ifdef __FB_ARM__
   #ifdef __FB_64BIT__
      #print "64bit, AArch64"
   #else
      #print "32bit, ARM"
   #endif
#else
   #ifdef __FB_64BIT__
      #print "64bit, x86_64"
   #else
      #print "32bit, x86"
   #endif
#endif
dasyar
Posts: 363
Joined: Dec 04, 2008 15:31

Re: MyTerminal prog

Postby dasyar » Oct 18, 2014 11:44

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

ThisPlaceHere
Posts: 9
Joined: Dec 19, 2011 19:52
Location: Wisconsin

Re: MyTerminal prog

Postby ThisPlaceHere » Feb 27, 2015 20:35

I copied your code for a quick test of some serial connections.. but it didn't work as well I had hoped, so I spent some time making a few [okay, a lot of] changes to get things to work as I expected. I'm posting what I ended up with in case you want to take a look at some of the changes or corrections. I just went back in filled in notes up top by the revision comments so you can pinpoint my "few" changes.
I tried to preserve the original design as much as possible, but sometimes I get carried away making things they way I see fit.
Tested on FreeDos, Windows 2000, and Windows 7; and using RS485 for long distance between devices.

Code: Select all

' FBterm.bas
' FBterm.exe - Windows
' 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 ?something_new_if_you_so_choose_to_use_it?
' Fixed these items:
'   - no original color defined
'   - removed local line feed for each port read
'   - if echo is off, no more LF with CR
'   - changed variable named echo to be it's own setting, and to remember setting between modes
'   - origcolor routine removed - used direct Color instead
'   - fixed color change with echo setting change
'   - removed cursor setting since we're doing it manually
'   - shortened the cursor blinking routine
'   - fixed scrolling of screen with every cursor blink when at bottom of screen
'   - changed numtosend to integer to handle overflows
'   - fixed jumps (goto statements) to not cause multiple instances of Loops
'   - combined all mouse box tests into a single button press test
'       to shorten code, and allow easy way to keep from multi-clicking
'   - removed unused variables
'   - re-worked the send number function. Was not sending all numbers entered!
'   - changed send number to check for allowable range (0 to 255)
'       also changed local echo to show numbers (characters) less than 32 as the
'       number instead of the trying to execute the character. They will be shown
'       in a reverse-type (red background)
'   - sendnum() input line set to always be on empty line
'   - a few other changes to make sure echo off was indeed echo off



Screen 12
Width 80,30
Color 15,0

' Globals
Dim Shared As Integer Corig, Handle
Dim Shared As Integer column, row, spcPos, numtosend2
Dim Shared As String Key, buffer, numtosend
Dim Shared echo As String*3 'fixed length for menu setup
echo = "On"

''''''''' 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 TextCursor()
Declare Sub sendnum()

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

' Locals
Dim As Integer b, p
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 Escape = Chr(27)
Dim As Integer res, x, y, buttons, btnHold


Start:
''''''''' Start of Program ''''''''''''
    Cls
    Corig = Color()
    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   
        Goto Cend 'leave the program
        Exit Do
    End If

    If (buttons And 1) And (btnHold = 0) Then
        btnHold = 1 ' set this to button held in case we jump out of loop
   
        ''''''''''' Mouse over Quit '''''''''''
        If x > 1 And x <= 32 And y > 16 And y < 31 Then
            'Exit Do
            GoTo Cend
   
        '''''''''' Mouse over Connect '''''''''
        ElseIf x > 49 And x <= 112 And y > 16 And y < 31 Then
            Exit Do
   
        '''''''''' Mouse over port ''''''''''''
        #ifdef __FB_WIN32__
        ElseIf x > 144 And x <= 176 And y > 16 And y < 31 Then
            p += 1
            If p = 10 Then p = 0
            Locate 2,24
            Color 7,9
            Print port(p);
        #else
        ElseIf x > 144 And x <= 176 And y > 16 And y < 31 Then
            p += 1
            If p = 5 Then p = 0
            Locate 2,24
            Color 7,9
            Print port(p);
        #endif
   
        '''''''''' Mouse over baud ''''''''''''
        #ifdef __FB_WIN32__
        ElseIf x > 248 And x <= 280 And y > 16 And y < 31 Then
            b += 1
            If b = 8 Then b = 0
            Locate 2,37
            Print "      "
            Color 7,9
            Locate 2,37
            Print baud(b);
        #else
        ElseIf x > 288 And x <= 328 And y > 16 And y < 31 Then
            b += 1
            If b = 8 Then b = 0
            Locate 2,41
            Print "        "
            Color 7,9
            Locate 2,42
            Print baud(b);
        #endif
       
        End If
    Else
        ''''''''' no mouse buttons ''''''''''
    End If
    btnHold = (buttons And 1) 'This keeps us clicking again until released
'''''''''''''''''''''''''''''''''''''''
Loop
''''''''' End of Main Screen ''''''''''

''''''''' Live Terminal '''''''''''''''
   InfoBar2()
   Handle = FREEFILE
   Open Com port(p) & baud(b) & ",n,8,1,cs0,ds0,cd0,rs" as Handle
'   Open Com "COM1:115200,n,8,1,cs0,ds0,cd0,rs" As Handle
   Sleep 100 ' Give it a chance to open
   If Err <> 0 Then
    Print "Error opening",port(p);
    Sleep 2000,1
    Cls
    GoTo Start
   End If

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

    If (buttons And 1) And (btnHold = 0) Then
        btnHold = 1 ' set this to button held in case we jump out of loop
       
        '''''''''' Mouse over Disonnect '''''''''
        If x > 49 And x <= 136 And y > 16 And y < 31 Then
            Close Handle
            Color(LoWord(Corig),HiWord(Corig))
            Cls
            Exit Do
        ''''''''' Mouse over echo '''''''''''''
        ElseIf x > 336 And x <= 368 And y > 16 And y < 31 Then
            If echo = "On" THEN
                echo = "Off"
            else
                echo = "On"
            end if
           
            View Print 1 To HiWord(Width)
            Color 7,9
            Locate 2,48
            Print "    "
            Locate 2,48
            Print echo;
            View Print 3 To HiWord(Width)
            Color(LoWord(Corig), HiWord(Corig))
            Cls
        ''''''''' Mouse over Send Number ''''''
        ElseIf x > 424 And x <= 512 And y > 16 And y < 31 Then
            sendnum()
        ''''''''' Mouse over Cls ''''''''''''''
        ElseIf x > 520 And x <= 544 And y > 16 And y < 31 Then
            Cls
        End If

    Else
    ''''''''' no mouse buttons ''''''''''
    End If
    btnHold = (buttons And 1) 'This keeps us clicking again until released
       
'''''''''' Terminal Screen ''''''''''''
    If Key <> "" Then

       
        If Key = Chr$(13) Then   ' Check for CR
            Print #Handle, Chr$(10);   ' Send LF
            If echo = "On" Then Print Chr$(10); ' Local LF
        Else
            Print #Handle,Key;
               If echo = "On" Then
                   Print Key;
               Else
                   'Echo off
               End If
        EndIf
    EndIf
   
    While LOC(Handle) > 0
        buffer = Input$(1,Handle)
        Print buffer;
        'print #Handle, chr$(10); Not sure what this was for??
    Wend
'''''''''''''''''''''''''''''''''''''''

Sleep 1
Loop
''''''''' End of Live Terminal ''''''''

Goto Start ' ended live terminal, return to main screen

Cend: 'if program ended, we jump here

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,"                                       ")
    Color(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,"                                 ")
    Color(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,echo)
   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)
    Color(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,echo)
   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)
    Color(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 TextCursor()
    column = Pos
    row = CsrLin
    If Frac(Timer) > .5 Then
        Print "_";
    Else
        Print " ";
    End If
    Locate row,column
End Sub

Sub sendnum()
    If Pos > 1 Then Print "" 'Get us to the next clear line
    Input "Enter a number to send (0 - 255) space delimited";numtosend
   
    While numtosend <> ""
        spcPos = InStr(numtosend, " ")
        If (spcPos > 1) And (spcPos < len(numtosend)) Then
            numtosend2 = ValInt(Left$(numtosend,spcPos))
            numtosend = Mid$(numtosend,(spcPos+1))
        Else
            numtosend2 = ValInt(numtosend)
            numtosend = "" 'Clear this to get out of loop!
        End If
       
        If numtosend2 >= 0 And numtosend2 < 256 Then
            Print #Handle, Chr$(numtosend2);
            If echo = "On" Then
                If numtosend2 > 31 Then
                    Print Chr$(numtosend2);
                Else
                    Color 7,4
                    Print CUByte(numtosend2); 'type change to remove spaces
                    Color(LoWord(Corig), HiWord(Corig))
                End If
            End If
        End If
    Wend

''''''''' Get rid of garbage char '''''
'    row = CsrLin          ' Get row position
'    column = Pos          ' Get column position
'   Locate row,(column-1)
'   Print " "              ' Get rid of garbage char
'   Locate row,(column-1)
End Sub

 

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: MSN [Bot] and 0 guests