TheByteWorks

    Quality ready made and affordable custom software

Home

Software

PHP Serial
rsterm
Easy Control
Rack Designer
EzCom2Web

Quick Texts
Wallpaper Slideshow

Articles

All articles
WS2300 weather station PHP project
Your own terminal in 17 lines
PC PIC Voltmeter
Network messenger in 22 lines
Phone Dialer

Download
Purchase

Support

Details
E-mail

Copyright 2001-2024
© Cosmin Buhu

  Articles - MyTerm

MyTerm - quick serial terminal application


#    To demonstrate how simple is to build an Windows application to handle
# a serial port I propose you a simple RS232 terminal. Tools used:
# Easy Control: the script engine and application builder
# Rack Designer: the graphic user interface builder
# Using Rack Designer build the GUI, something like this:
# <insert image>
# Please use for the control elements the following names:
#    Send button : pbutton1
#    Add CRLF button : pbutton2
#    Field for to send data: edit1
#    Numeric input for setting how many times to send data : num1
#
# The script uses the latest features of Easy Control Basic language,
# procedures being one of them. These are pieces of code enclosed between
# procedure and procend words. This code is executed only when the procedure
# is called somewhere in the main code, starting after the last procedure body.
#
# Let see the code:
# This is executed only when called
procedure setup
    err="no error"
    # Open the GUI built with Rack Designer
    openrack("c:\easycontrol\serial_ex\myterm.res")
    # Check errors
    if (error==1)
        err="Error opening rack !"
        exit
    endif
    # Put Add CRLF button in ON state
    pbutton2=1
    # Initialize how many times will send data
    num1=1
    # Open serial port
    myport="com1"
    openport(myport,9600,8,"n",1)
    # Show a 400x300 pixels terminal window to watch data
    showterm(myport,400,300,8)
    # If we talk to a modem it might be need to set RTS line
    setrts (myport)
    # Check errors again
    if (error==1)
        err="Error opening serial port !"
        exit
    endif
procend
# This is executed only when called
procedure send
    # Load in the tosend variable the content of edit1 text field
    tosend=edit1
    # And get its length
    ltosend=len (tosend)
    # If is something to send
    if (ltosend>>1)
        # If Add CRLF button is ON add these characters to the end of data
        if (pbutton2==1)
            tosend=tosend&chr(13)&chr(10)
        endif
        # Now send data, a number of times given by the num1 value
        for (i,1,num1,1)
            # This actually sends data to the serial port
            send (myport,tosend)
        next
    endif
    # Reste the Send button back in OFF state
    pbutton1=0
procend
# Here begins the main program
# Run setup procedure, to open serial port and terminal
setup
# If no errors
if (err=="no error")
    # Enter the forever program loop
    while (1)
        # Wait here
        while (pbutton1==0)
            # until Send button is pressed, switching its state from OFF to ON
        wend
        # Run send procedure, which will take data from edit1 text field
        # and send it to the serial port
        send
    wend
else
    # There was an error, print it in the log
    writelog (err)
endif
# Code ends here
# Is that simple to build it? Yes !
# This example is included in the trial distribution of Easy Control,
# along other examples.
# The nice looking syntax highlighting and coloring you see here is exactly how
# it looks in Easy Control built-in editor. Other features are code competition
# and syntax hints.
# Get Easy Control from here