This equipment h as been tested a nd found to compl y with the limits fo r a Class B Digit al Device, pursuant to
Part 15 of the FCC rules. These limits are designed to provide reasonable protection against harmful
interferenc e in a residential installation. Th is equipment gen erates, uses a nd can radiate r adio frequency
energy and, if not i nstal led and us ed in acc ord ance with the instr uction, may c ause harm ful inter feren ce to
radio communication. However, there is no guarantee that interference will not occur in a particular
installation. If this equipm ent doe s cause h armful interfer ence to r adio or televi sion r eceptio n, whic h can
be determined by turning the equipment off and on, the user is encouraged to try to correct the
interference by one of more of the following measures: -
- Reorient or relocate the receiving antenna.
- Increase the separation between the equipm e nt and rec ei ver.
- Connect the eq uipment i nto an outle t on a c ircuit dif ferent from that to which the receiver is
connected.
- Consult the dealer or an experi enced Radio/TV technician for help.
Use only shielded cables to connect I/O devices to this equipment. You are cautioned that change or
modifications no t expressl y approved by th e party respon sible for compli ance could void yo ur authority to
operate the equipment.
THIS DEVICE COMPLIES WITH PART 15 OF FCC RULES. OPERATION IS SUBJECT TO THE
FOLLOWING TWO CONDITIONS: -
1. This device may not cause harmful interferenc e and
2. This device must accept any interference received, including interference that may cause undesired
operation.
The antenna used for this transmitter must not be collocated or operation in conjunction
with any other antenna or transmitter.
TIDE and Tibbo BASIC User ManualI
Table of Contents
Taiko R2
................................................................................................................................... 1Legal Information
Overview4
................................................................................................................................... 4Our Language Philosophy
................................................................................................................................... 9Preparing Your Hardware
................................................................................................................................... 10Starting a New Project
................................................................................................................................... 14Building, Uploading and Running
................................................................................................................................... 15Compiling a Final Binary
............................................................................................................................................................... 15The Structure of a Project
............................................................................................................................................................... 17Creating, Opening and Saving Projects
............................................................................................................................................................... 22Coding Your Project
.......................................................................................................................................................... 26Supported HTML Tags
............................................................................................................................................................... 26Making, Uploading and Running an Executable Binary
............................................................................................................................................................ 27Two Modes of Target Execution
............................................................................................................................................................... 28Debugging Your Project
............................................................................................................................................................ 28Target States
.......................................................................................................................................................... 37Scopes in Watch
............................................................................................................................................................... 43Introduction to Variables, Constants and Scopes
............................................................................................................................................................ 43Variables And Their Types
............................................................................................................................................................ 48Type conversion in expressions
............................................................................................................................................................ 57Understanding the Scope of Variables
............................................................................................................................................................... 62Introduction to Procedures
............................................................................................................................................................ 64Passing Arguments to Procedures
............................................................................................................................................................ 66Memory Allocation for Procedures
............................................................................................................................................................... 67Introduction to Control Structures
............................................................................................................................................................ 73Scope of Preprocessor Directives
............................................................................................................................................................... 74Working with HTML
............................................................................................................................................................ 76Embedding Code Within an HTML File
............................................................................................................................................................... 86For... Next Statement
............................................................................................................................................................... 115Menu Bar
............................................................................................................................................................ 115File Menu
............................................................................................................................................................ 116Edit Menu
............................................................................................................................................................ 117View Menu
............................................................................................................................................................ 117Project Menu
............................................................................................................................................................ 118Debug Menu
............................................................................................................................................................ 119Image Menu
............................................................................................................................................................ 119Window Menu
............................................................................................................................................................... 126Status Bar
............................................................................................................................................................... 131Language Element Icons
IVContents
............................................................................................................................................................ 120Help Menu
............................................................................................................................................................ 128Add File to Project
................................................................................................................................... 131Compilation Unit
............................................................................................................................................................ 134Memory Space
............................................................................................................................................................ 136Platform-dependent Programming Information
............................................................................................................................................................... 139EM1000 and EM1000W Platforms
............................................................................................................................................................ 140Memory Space
............................................................................................................................................................ 145Platform-dependent Programming Information
............................................................................................................................................................... 149EM1202 and EM1202W Platforms
............................................................................................................................................................ 149Memory Space
............................................................................................................................................................ 154Platform-dependent Programming Information
............................................................................................................................................................... 158EM1206 and EM1206W Platforms
............................................................................................................................................................ 158Memory Space
............................................................................................................................................................ 163Platform-dependent Programming Information
............................................................................................................................................................ 167Memory Space
............................................................................................................................................................ 171Platform-dependent Programming Information
............................................................................................................................................................ 175Memory Space
............................................................................................................................................................ 179Platform-dependent Programming Information
............................................................................................................................................................... 182Common Information
.......................................................................................................................................................... 187Device Explorer
............................................................................................................................................................... 189Asc Function
............................................................................................................................................................... 190Bin Function
............................................................................................................................................................... 190Cfloat Function
............................................................................................................................................................... 191Chr Function
............................................................................................................................................................... 191Date Function
............................................................................................................................................................... 192Daycount Function
............................................................................................................................................................... 192Ddstr Function
............................................................................................................................................................... 193Ddval Function
............................................................................................................................................................... 194Ftostr Function
............................................................................................................................................................... 195Hex Function
............................................................................................................................................................... 195Hours Function
............................................................................................................................................................... 196.Insert Function
............................................................................................................................................................... 197Instr Function
............................................................................................................................................................... 197Lbin Function
............................................................................................................................................................... 198Left Function
............................................................................................................................................................... 198Len Function
............................................................................................................................................................... 199Lhex Function
............................................................................................................................................................... 199Lstr Function
............................................................................................................................................................... 200Lstri Function
............................................................................................................................................................... 200Lval Function
............................................................................................................................................................... 201Md5 Function
............................................................................................................................................................... 202Mid Function
............................................................................................................................................................... 203Mincount Function
............................................................................................................................................................... 203Minutes Function
............................................................................................................................................................... 204Month Function
............................................................................................................................................................... 205Random Function
............................................................................................................................................................... 205Right Function
............................................................................................................................................................... 205Sha1 Function
............................................................................................................................................................... 207Str Function
............................................................................................................................................................... 207Strgen Function
............................................................................................................................................................... 208Stri Function
............................................................................................................................................................... 209Strsum Function
............................................................................................................................................................... 209Strtof Function
............................................................................................................................................................... 210Val Function
............................................................................................................................................................... 210Vali Function
............................................................................................................................................................... 211Weekday Function
............................................................................................................................................................... 211Year Function
.......................................................................................................................................................... 216Serial Number
............................................................................................................................................................ 224What's new in V1.1
.......................................................................................................................................................... 225Anatomy of a Serial Port
.......................................................................................................................................................... 225Three Modes of the Serial Port
.......................................................................................................................................................... 239Sending and Receiving Data (TX and RX buffers)
....................................................................................................................................................... 239Allocating Memory for Buffers
....................................................................................................................................................... 240Buffer Memory Status
....................................................................................................................................................... 241Receiving Data
....................................................................................................................................................... 243Sending Data
....................................................................................................................................................... 245Sinking Data
.......................................................................................................................................................... 269Checking Ethernet Status
.......................................................................................................................................................... 276Anatomy of a Socket
....................................................................................................................................................... 283Understanding UDP Reconnects and Port Switchover
....................................................................................................................................................... 286Incoming Connections on Multiple Sockets
....................................................................................................................................................... 292Checking Connection Status
....................................................................................................................................................... 294More On the Socket's Asynchronous Nature
.......................................................................................................................................................... 297Sending and Receiving data
....................................................................................................................................................... 297Allocating Memory for Buffers
....................................................................................................................................................... 298Using Buffers in TCP Mode
....................................................................................................................................................... 299Using Buffers in UDP Mode
....................................................................................................................................................... 300TX and RX Buffer Memory Status
....................................................................................................................................................... 301Receiving Data in TCP Mode
....................................................................................................................................................... 303Receiving Data in UDP Mode
....................................................................................................................................................... 304Sending TCP and UDP Data
....................................................................................................................................................... 306"Split Packet" Mode of TCP Data Processing
....................................................................................................................................................... 309Sinking Data
.......................................................................................................................................................... 309Working With Inband Commands
....................................................................................................................................................... 309Inband Message Format
....................................................................................................................................................... 310Inband-related Buffers (CMD, RPL, and TX2)
....................................................................................................................................................... 317Setting the Socket for HTTP
....................................................................................................................................................... 318Socket Behavior in the HTTP Mode
....................................................................................................................................................... 319Including BASIC Code in HTTP Files
....................................................................................................................................................... 320Generating Dynamic HTML Pages
....................................................................................................................................................... 323Working with HTTP Variables
....................................................................................................................................................... 323Simple Case (Small Amout of Variable Data)
....................................................................................................................................................... 324Complex Case (Large Amount of Variable Data)
....................................................................................................................................................... 326Details on Variable Data
............................................................................................................................................................ 327Properties, Methods, and Events
.......................................................................................................................................................... 366Line/Port Manipulation With Pre-selection
.......................................................................................................................................................... 367Line/Port Manipulation Without Pre-selection
.......................................................................................................................................................... 369Working With Interrupts
.......................................................................................................................................................... 395Preparing the Display for Operation
.......................................................................................................................................................... 395Working With Pixels and Colors
.......................................................................................................................................................... 396Lines, Rectangles, and Fills
.......................................................................................................................................................... 397Working With Text
....................................................................................................................................................... 400Raster Font File Format
............................................................................................................................................................ 412Properties and Methods
.......................................................................................................................................................... 434Sharing Flash Between Your Application and Data
.......................................................................................................................................................... 435Fd. Object's Status Codes
....................................................................................................................................................... 436Formatting the Flash Disk
....................................................................................................................................................... 437Disk Area Allocation Details
....................................................................................................................................................... 439Mounting the Flash Disk
....................................................................................................................................................... 440File Names and Attributes
....................................................................................................................................................... 441Checking Disk Vitals
....................................................................................................................................................... 441Creating, Deleting, and Renaming Files
....................................................................................................................................................... 442Reading and Writing File Attributes
....................................................................................................................................................... 442Walking Through File Directory
....................................................................................................................................................... 444Writing To and Reading From Files
....................................................................................................................................................... 445Removing Data From Files
....................................................................................................................................................... 452Upgrading the Firmware/Application
.......................................................................................................................................................... 453File-based and Direct Sector Access Coexistence
.......................................................................................................................................................... 453Prolonging Flash Memory Life
.......................................................................................................................................................... 454Ensuring Disk Data Integrity
............................................................................................................................................................ 456Properties and Methods
............................................................................................................................................................ 486Key States and Transitions
............................................................................................................................................................ 487Preparing the Keypad for Operation
............................................................................................................................................................ 498Migrating From the WA1000
.......................................................................................................................................................... 500Wi-Fi Parlance Primer
.......................................................................................................................................................... 503Wln State Transitions
.......................................................................................................................................................... 504Brining Up Wi-Fi Interface
....................................................................................................................................................... 507Setting MAC Address (Optional)
....................................................................................................................................................... 508Booting Up the Hardware
....................................................................................................................................................... 509Setting IP, Gateway, and Netmask (Optional)
....................................................................................................................................................... 509Setting TX Power (Optional)
.......................................................................................................................................................... 509Scanning for Wi-Fi Networks
.......................................................................................................................................................... 510Setting WEP Mode and Key
.......................................................................................................................................................... 511Associating With Selected Network
.......................................................................................................................................................... 512Creating Own Ad-hoc Network
.......................................................................................................................................................... 512Communicating via Wln Interface
.......................................................................................................................................................... 512Disassociating From the Network
.......................................................................................................................................................... 512Terminating Own Ad-hoc Network
.......................................................................................................................................................... 513Detecting Disassociation or Offline State
Taiko is a solution which allows you to create programs for Tibbo modules capable
of running TiOS (Tibbo Operating System), and products based on these modules.
With Taiko, you write your program in a language called Tibbo Basic (a close
relative of any other BASIC you might already know), using a PC software called
TIDE - Tibbo Integrated Development Environment. Your program is then compiled
into a binary file and uploaded onto a Tibbo module. The Virtual Machine of TiOS
then executes this binary.
Taiko allows you to easily create programs for a variety of Tibbo-based products.
These may include:
Alarm Panels
Security Systems (Access control terminals, etc)
Data Collection terminals, such as time clocks
Sensor monitors
Interface converters
Vending machines
Industrial process controllers
The solutions created with Taiko are very flexible. They are written using a
language similar to BASIC, and are stored on a Tibbo module separately from the
core OS of the module (TiOS). This allows for simple modification of your device
functionality, even by the end-user (if you so allow).
Tibbo Basic itself is exactly the same for all TiOS-enabled devices. Hardware
differences are expressed through so-called platforms. Change the platform, and
you're programming for a different device.
Last update: 29JUL2009
Legal Information
Manual Update History
1
530
Documentation Map
The documentation for Taiko includes:
Overview - The theory and background behind Taiko.
4
Getting Started - An example starter project.
Programming with TIDE -- An overview of TIDE itself, debug facilities, etc.
Language Reference -- Systematically covers Tibbo Basic statements, keywords
and operators.
Development Environment -- Systematically covers TIDE GUI elements.
Glossary of Terms -- Contains some basic terms used in Taiko.
Platforms -- Platform-specific documentation for each target device.
133
Legal Information
Tibbo Technology ("TIBBO") is a Taiwan corporation that designs and/or
manufactures a number of hardware products, software products, and applications
("PRODUCTS"). In many cases, Tibbo PRODUCTS are combined with each other
and/or third-party products thus creating a PRODUCT COMBINATION.
Whereas you (your Company) wish to purchase any PRODUCT from TIBBO, and/or whereas you
(your Company) wish to make use of any documentation or technical information published by
TIBBO, and/or make use of any source code published by TIBBO, and/or consult TIBBO and
receive technical support from TIBBO or any of its employees acting in an official or unofficial
capacity,
You must acknowledge and accept the following disclaimers:
1. Tibbo does not have any branch office, affiliated company, or any other form of
presence in any other jurisdiction. TIBBO customers, partners and distributors in
Taiwan and other countries are independent commercial entities and TIBBO does
not indemnify such customers, partners or distributors in any legal proceedings
related to, nor accepts any liability for damages resulting from the creation,
manufacture, importation, advertisement, resale, or use of any of its PRODUCT or
PRODUCT COMBINATION.
2. BASIC-programmable devices ("PROGRAMMABLE DEVICES") manufactured by
TIBBO can run a variety of applications written in Tibbo BASIC ("BASIC
APPLICATIONS"). Combining a particular PROGRAMMABLE DEVICE with a specific
BASIC APPLICATION, either written by TIBBO or any third party, may potentially
create a combinatorial end product (”END PRODUCT”) that violates local rules,
regulations, and/or infringes an existing patent granted in a country where such
combination has occurred or where the resulting END PRODUCT is manufactured,
exported, advertised, or sold. TIBBO is not capable of monitoring any activities by
its customers, partners or distributors aimed at creating any END PRODUCT, does
not provide advice on potential legal issues arising from creating such END
PRODUCT, nor explicitly recommends the use of any of its PROGRAMMABLE
DEVICES in combination with any BASIC APPLICATION, either written by TIBBO or
any third party.
3. TIBBO publishes a number of BASIC APPLICATIONS and segments thereof ("CODE SNIPPETS").
The BASIC APPLICATIONS and CODE SNIPPETS are provided “as is” without warranty of any
kind, either expressed or implied, including, but not limited to, the implied warranties of
merchantability and fitness for a particular purpose. The entire risk as to the quality and
performance of BASIC APPLICATIONS and CODE SNIPPETS resides with you. BASIC
APPLICATIONS AND CODE SNIPPETS may be used only as a part of a commercial device based
on TIBBO hardware. Modified code does not have to be released into the public domain, and
does not have to carry a credit for TIBBO. BASIC APPLICATIONS and CODE SNIPPETS are
provided solely as coding aids and should not be construed as any indication of the
predominant, representative, legal, or best mode of use for any PROGRAMMABLE DEVICE.
4. BASIC-programmable modules ("PROGRAMMABLE MODULES"), such as the EM1000 device,
are shipped from TIBBO in either a blank state (without any BASIC APPLICATION loaded), or
with a simple test BASIC APPLICATION aimed at verifying correct operation of
PROGRAMMABLE MODULE's hardware. All other BASIC-programmable products including
boards, external controllers, and developments systems ("NON-MODULE PRODUCTS"), such
as the DS1000 and NB1000, are normally shipped with a BASIC APPLICATION pre-loaded. This
is done solely for the convenience of testing by the customer and the nature and function of
pre-loaded BASIC APPLICATION shall not be construed as any indication of the predominant,
representative, or best mode of use for any such NON-MODULE PRODUCT.
5. All specifications, technical information, and any other data published by TIBBO are
subject to change without prior notice. TIBBO assumes no responsibility for any
errors and does not make any commitment to update any published information.
6. Any technical advice provided by TIBBO or its personnel is offered on a purely technical basis,
does not take into account any potential legal issues arising from the use of such advice, and
should not be construed as a suggestion or indication of the possible, predominant,
representative, or best mode of use for any Tibbo PRODUCT.
7. Neither TIBBO nor its employees shall be held responsible for any damages resulting from the
creation, manufacture, or use of any third-party product or system, even if this product or
system was inspired, fully or in part, by the advice provided by Tibbo staff (in an official
capacity or otherwise) or content published by TIBBO or any other third party.
8. TIBBO reserves the right to halt the production or availability of any of its
PRODUCTS at any time and without prior notice. The availability of a particular
PRODUCT in the past is not an indication of the future availability of this PRODUCT.
The sale of the PRODUCT to you is solely at TIBBO's discretion and any such sale
can be declined without explanation.
9. TIBBO makes no warranty for the use of its PRODUCTS, other than that expressly
contained in the Standard Warranty located on the Company's website. Your use of
TIBBO PRODUCTS is at your sole risk. TIBBO PRODUCTS are provided on an "as is"
and "as available" basis. TIBBO expressly disclaims the warranties of
merchantability, future availability, fitness for a particular purpose and
non-infringement. No advice or information, whether oral or written, obtained by
you from TIBBO shall create any warranty not expressly stated in the Standard
Warranty.
10.LIMITATION OF LIABILITY. BY USING TIBBO PRODUCTS YOU EXPRESSLY AGREE
THAT TIBBO SHALL NOT BE LIABLE TO YOU FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING,
BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, OR OTHER
INTANGIBLE LOSSES (EVEN IF TIBBO HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES) RESULTING FROM THE USE OR THE INABILITY TO USE OF TIBBO
PRODUCTS.
11."Tibbo" is a registered trademark of Tibbo Technology, Inc.
12.Terms and product names mentioned on TIBBO website or in TIBBO
documentation may be trademarks of others.
Below is a summary of the major fundamentals and theory behind TIDE. This may
sound intimidating, but it's actually quite simple. You should at least skim over the
material herein, because it explains much of what comes next. In here you will
find:
Our Language Philosophy
System Components
Objects (a very brief overview)
Events
8
8
Our Language Philosophy
Several principles have guided us through the development process of Tibbo Basic.
Understanding them would help you understand this manual better, and also the
language itself. See below:
A Bit of History
Years ago, programming for the PC was the nearly exclusive domain of engineers.
The languages traditionally available, such as C, simply required you to be an
engineer to program.
However, one day something interesting happened. Visual Basic* and Delphi**
saw the light of day. And that changed quite a lot on the PC front. Suddenly,
people who were not engineers were finding out that they could actually create
something cool on their PC. You could say VB* and Delphi democratized the PC
software market.
The situation on the embedded systems market today is quite similar to the
situation which existed for the PC market in the pre-VB era. Many embedded
systems vendors do offer customizable or programmable solutions -- but to
implement those solutions, you would really have to be an engineer and know C/C
++ quite well. So, there was clearly a need for an easy-to-use programming
system which would democratize this market, as well.
7
4Overview
4
Principle One: Easy To Write, Easy to Debug
Choosing BASIC as our inspiration was the natural thing to do, for us. It's a
language which doesn't require you to be a professional engineer. It is easy to
understand. This is why it is embedded into many non-programmer products, such
as the Office suite. So we went for BASIC.
Another part of the user experience, and a major one, too, is debugging. Writing
your application is just half the job. You also need to debug it and for embedded
systems, this is where things typically start getting rough around the edges. Many
times you have to buy expensive tools, such as ICE machines (In-Circuit
Emulators), just to figure out what your code is doing. Sometimes you don't even
have the luxury of such a machine, and you actually debug by guessing and trying
different things in your code.
With our system, one of our major goals was to offer a user experience which is
close to debugging on the PC -- without the need for special tools, such as an ICE
machine.
While your program is running on the target (embedded device), you actually see
how it runs on your PC. You can step through it, jump to specific functions, check
values of variables etc -- all from the comfort of your own PC.
Some modern programming languages use certain techniques to make life 'easier'
for programmers. They might not require the programmer to explicitly declare the
variables he's going to use ('implicit declaration'), or might do away with the need
to specify the type for the variable (i.e, use 'variant variables' which can contain
anything).
This has several disadvantages. For one, it is just sloppy. After several days of
writing code like that, a programmer might not have a very clear-cut idea of what
his program is doing, or where things come from. While this is something which
may be subject to debate, the next disadvantage is quite real:
This is simply wasteful programming. These techniques can consume quite a lot of
resources, specifically memory. On the PC, a variant used to store just 2 bytes of
data might take up to 100 bytes. This isn't a problem, because PCs have so much
memory these days that it is barely felt.
However, embedded systems are often low-cost and bare-bones, so physical
memory is a truly valuable resource. Waste too much of it -- and you would find
that your code can do very little. But manage it prudently, and your code will be
capable of quite impressive feats even on your 'low-power' embedded system.
So our systems requires you to be more organized. The effort is worth it.
Principle Three: The Purity of Language
Programming systems on the PC usually make no clear distinction between the
'pure' language constructs which perform calculations and control program flow,
and hardware-dependant input/output. For example, many languages contain a
print statement which prints something to the screen.
Since all PCs in the world are similar, this works. However, this makes little sense
for embedded platform, which have vastly different input/output resources.
Depending on the device, it may or may not have a screen, a serial port,
networking etc etc.
In our system, we separated the language itself (what we call the core language)
from the input/output of a particular device. Thus, the language itself remains the
same, no matter what device you are programming for. The input/output part is
hardware dependant, and changes from platform to platform.
When writing for a specific platform, you are provided with a set of platformspecific objects. These provide rich functionality and allow you to do 'real' work,
such as printing messages to the serial port, communicating on the Internet or
controlling motors and sensors.
Ideally, Tibbo Basic could run on a fridge just as well as it could run on a time and
attendance terminal.
Principle Four: Thin and Agile
A lot of embedded systems are built by scaling down larger desktop systems, and
it shows. What's the point of using a super-fast processor if you load it with dozens
of layers of nested calls?
All the code TiOS includes has been designed from scratch for running on a very
simple processor, and optimized for control applications. It has been crafted to
have the minimum possible ROM and RAM footprint and to run as fast as possible.
We built TiOS with Pareto's principle in mind. In other words, if a certain
functionality is required by only 5% of applications and yet its existence adds 90%
overhead, we did not include it. For example, our BASIC only supports integer
calculations. Most other BASIC versions, by default, operate using floating point
arithmetic, but these are not usually useful to embedded control (and even get in
the way). Another decision was to use a static memory model for procedure
variables. Memory is not allocated and deallocated dynamically -- It is assigned on
compile-time, which results in great performance improvements.
Principle Five: No B.S
... that is, no babysitting. Development systems intended for rapid application
development on the PC will often try to handle every little error or problem the
programmer may encounter. If a variable overflows, for example, they will halt
execution and pop up an error to let him know. This makes sense for a PC-based
product, because you are right there to see it halt.
However, when you are creating an embedded system, you expect it to run at alltimes, without halting. Nobody will be there to see any errors and babysit your
system. Your device is simply expected to work.
This is a major difference also for the development process. In essence, since the
whole language is built this way, you will also get much less errors even when
doing seemingly 'strange' things, such as putting large values into variables that
cannot hold them. The language will deal with it silently, in a very predictable and
logical way -- but will not pop up an error.
Principle Six: Event-Driven Programming
Users of VB and Delphi and other Windows-based tools will find this principle
familiar. However, if most of your experience with BASIC was under DOS, you
might find this slightly odd. Under DOS, you would expect a program to begin from
the beginning, then continue and stop. They execute from top to bottom. This may
be called linear execution.
For Tibbo Basic, this is not the case. The programs you will write will be event-driven. Your program will consist of a number of event handlers which will be fired
(invoked) in response to specific things which happen to your system in real life. If
your platform was a fridge, you might want to write a handler for a 'door opening'
event. When the door is opened, an event is generated, and an event handler, with
your code in it, is fired.
So, you could say that your event-driven application has no beginning and no end.
Event handlers are called when events are generated, and in the order in which
they were generated.
* Windows, Visual Basic and VB are registered trademarks of Microsoft Corporation
Inc.
** Delphi is a registered trademark of Borland Inc.
Taiko is a compound system. It consists of the following components:
TIDE is an acronym for Tibbo Integrated Development Environment. This is the PC
program in which you will write your applications and compile them, and from
which you will upload them to your target and debug them.
The compiler is a utility program, used by TIDE. The compiler processes your
project files and creates an executable binary file (with a .tpc suffix, for Tibbo
PCode).
The target is a separate hardware device, on which your program actually runs.
When debugging code, it is connected to your computer running TIDE (see the link
above) and TIDE can monitor and control it. This is called cross-debugging.
As covered under Our Language Philosophy, Tibbo Basic is capable of running
on various hardware devices. Each type of hardware device on which Tibbo Basic
runs is called a platform.
And now, the anatomy of the target:
4
The target runs an operating system called TiOS (Tibbo Operating System).
TiOS runs two processes. One is the Master Process. This is the process which is
in charge of communications (including communications with TIDE) and of
generating events. The second process, which is under the control of the Master
Process, is called the VM (Virtual Machine).
The VM is what actually executes your application. In essence, the VM is a
processor implemented in firmware, which executes the compiled form of your
application. The instructions it understands are called P-Code, which is short for
pseudo-code. This is what the compiler produces. It is called pseudo-code because
it is not native binary code which the hardware processor can understand directly;
instead, it is interpreted by the VM.
Since the VM is under the complete control of the Master Process, the actual
hardware processor will not crash because of an error in your Tibbo Basic
application. Your application may operate incorrectly, but you still will be able to
debug it. The Master Process can stop or restart the Virtual Machine at will, and
can exchange debug information with TIDE, such as report current execution state,
variable values, etc.
Simply put, you can think of the VM as a sort of a 'sandbox' within the processor.
Your application can play freely, without the possibility of crashing or stalling TiOS
due to some error.
The queue is used to 'feed' your program with events which it should handle.
The Master Process monitors the various interfaces of the platform and generates
events, putting them into the queue. The Virtual Machine extracts these events
from the other side of the queue and feeds your program with them. Various parts
of your program execute in response to events.
Objects
Objects represent the various component part of your platform. For example, a
platform with a serial port might have a ser object. A platform can be described as
a collection of objects.
Under Tibbo Basic, the set of object you get for each platform is fixed. You cannot
add new objects or create multiple instances of the same object.
Objects have properties, methods and events. A property can be likened to an
attribute of the object, and a method is an action that the object can perform.
Events are described in the next section.
Objects are covered in further detail under Objects, Events and Platform Functions
78
8Overview
8
8
.
Events
An event is something which happens to an object. Plain and simple. A fridge
might have door object with an on_door_open event, and a paper shredder might
have a detector object with an on_paper_detected event.
Events are a core concept in Tibbo Basic. They are the primary way in which code
gets executed.
The target device maintains an event queue. All events registered by the system
go into this queue. On the other end of the queue, the Virtual Machine takes out
one event at a time and calls an event handler for each event.
Event handlers are subroutines in your code which are 'fired' (executed) to handle
an event. Often, event handlers contain function calls which run other parts of the
program.
While processing an event, other events may happen. These events are then
queued for processing, and patiently wait for the first event to complete before
beginning execution.
All Tibbo Basic programs are single-threaded, so there is only one event queue. All
events are executed in the exact order in which they were queued.
It may sometimes seem that some events should get priority over other events.
This functionality is not supported under Tibbo Basic. This is not crucial, as events
This project would actually run also on the EM202, EM200 and EM120
modules. However, these modules cannot work on their own, and you
cannot easily test with them.
Of course, once you upload a device with the TiOS firmware, it is no
longer a Device Server! So you cannot see it under DS Manager. You
could program it so it would respond to DS Manager -- but by default it
is a 'clean slate', and does not respond to DS Manager broadcasts.
tend to execute very quickly, and the queue ensures events are not forgotten.
Getting Started
Below is a walk-through for a starter project which is written specifically for the
EM202-EV and DS202.
Once you are done with this project, you will be able to press the button on the
EM202-EV or DS202 and watch the LEDs blink "Hello World!" in Morse code.
Preparing Your Hardware
Preparing a DS202
Before starting to use TIDE, you should upload the correct firmware to a DS202.
Perform the following steps:
Get tios_EM202_xxx.bin firmware file (the latest version) from the Tibbo
website. _100 in this filename stands for version 1.00, for example.
Connect the DS202 to power (preferably, use adaptor supplied by Tibbo).
Connect the DS using a network cable (WAS-1499 or similar) to the same hub
your computer is connected to, or directly to the computer with a cross network
cable (WAS-1498 or similar).
Make sure your local firewall (such as the XP SP2 firewall) is disabled or does not
block broadcast UDP messages. This is essential for communications between
TIDE and the DS202 while debugging.
Run Device Explorer (Start > Programs > Tibbo > Tibbo IDE > Device Explorer).
You should see your device on the list. Select it.
Click Upload > Load Firmware Through the Network.
Select the firmware file, and click OK.
The firmware will now be uploaded.
For some firmware versions, you now have to manually reboot the DS
(Disconnect and reconnect the power cable). The red Status LED should now
blink rapidly. This is OK -- it means the TiOS firmware is loaded and the
application program memory is empty.
If for some reason you cannot perform a network upload, you can
perform a serial upload by selecting Upload > Load firmware Through
the Serial Port. You will then be prompted to select a COM port, turn
the device off and turn it back on while pressing the SETUP button.
Upload will then commence.
Starting a New Project
To begin a new project, select File > New. You will be presented with the following
dialog:
10Getting Started
Platform: Select EM202(you can use EM1000 as well)
Available project types: Select Empty Project.
Project name: Type 'Hello World'.
Location: Leave untouched, unless you have a good reason to change it.
Transport: leave it as is ("Taiko UDP Broadcast Transport")
Target Address: Click Browse. You will be presented with the following dialog:
If you see nothing in this dialog, it means your target isn't in
communication with the computer. This is probably a power problem,
or a networking problem. Perhaps you have a local firewall on the
computer which blocks UDP broadcasts, such as the Windows XP
Firewall. To fix this, disable the firewall or configure it to open a
specific port.
The number (hopefully) displayed is the MAC address of your target. If you select
it and click Buzz, you should see the LED pattern on your target switch off
momentarily. This means it is correctly detected.
Once you have located your target, click Select. You will be returned to the
previous dialog, and the MAC address for your target will appear under Target
Address.
You have now specified all of the required settings for a new project. Click OK and
proceed.
Writing Code
Once you have started your new project, you will be presented with a blank file
(main.tbs).
We will now begin writing the actual code in this file. We will construct this project
from beginning to end, step by step. For your convenience, the end of this section
contains a complete copy of the project without comments. You can copy and
paste the whole thing into TIDE, or just copy and paste the commented sections
one by one as they appear below.
' Comments cannot spill over to the next line. If you see this happening
in this manual, it is a result of the help system -- not an actual
feature.
Dim hello_world AsString' define a variable which will hold the whole
pattern we will play.
Dim length, play_position AsInteger' length is a calculated integer
which will contain the whole length of the string we will play, and
play_position will contain our current position in this string (how much
we have played so far).
Const PAT_PLAY_CHUNK_LENGTH = 15 ' define a constant for the size of the
chunk we will play. We will play one chunk of the pattern at a time, and
then move on to the next chunk. Each chunk is 15 'steps' long.
DeclareSub play_Next' let the compiler know that there is a sub called
play_next. This sub will be used in code before being created so we must
declare it.
sub on_sys_init ' event handler for the init event. Fires whenever the
device powers on.
hello_world = ' here we define the contents of our string, in morse.
'R is Red LED, G is Green LED. GGG means a long pulse of the
green LED (line). R means a short pulse of the Red LED (dot). Line (-)
means both off.
length = len(hello_world) ' Calculate total length of string.
play_position = 1' Initialize play_position as we haven't played
anything yet.
endsub
Notice that we are defining a chunk above. The reason for this is that we are going
to play quite a long and complex pattern (over 130 steps in length), but the
pattern object (pat.) used to play the pattern only supports patterns of up to 16
steps. So we have to play our pattern in parts, one after the other, and track our
progress through the pattern (this is what the counters are for).
So far, we have prepared the ground. Let us move to the first piece of executable
code:
We will now write the event handlers for our code.
First, we want the pattern to start playing whenever you press the button. For this,
our platform offers a button object, which generates an on_button_pressed event.
Instead of typing, you can create the event handler for this event by doubleclicking on the event name in the project tree.
130
13TIDE and Tibbo BASIC User Manual
sub on_button_pressed ' event handler fired whenever the button is pressed
play_position = 1' start playing from the beginning of the pattern
play_next ' call the routine which plays the next chunk (the first
chunk, in this case)
endsub
sub on_pat' this fires whenever a pattern (a chunk, in our case)
finishes playing.
play_next ' call the routine which plays the next chunk
endsub
sub play_next ' plays the next chunk of our large pattern.
if length < play_position thenexitsub' if we have reached the end
of the pattern, stop.
dim chunk_len asinteger' internal integer for the length of current
chunk to be played.
chunk_len = length - play_position + 1' calculate how much of the
large string is left.
if chunk_len > PAT_PLAY_CHUNK_LENGTH then chunk_len =
PAT_PLAY_CHUNK_LENGTH ' if too much is left, we bite off only a chunk we
can process.
dim chunk asstring' will contain the chunk which will actually play
now.
chunk = mid(hello_world, play_position, chunk_len) ' chunk is the
part of hello_world which begins at play_position and is as long as
chunk_len.
pat.play(chunk, YES) ' Play this chunk. YES means the pattern may be
interrupted -- you can press the button while the pattern is playing, and
it will start again from the top.
play_position = play_position + chunk_len ' advance play_position to
account for the chunk we played.
endsub
Notice that the play_next routine is not yet defined. In our code, it is first used and
then defined. This is why we have to declare it at the beginning.
Now, let us move on to the next event handler:
We have now completed writing our event handlers. Our program now knows what
it's supposed to do whenever you press the button, and whenever a chunk of the
pattern finishes playing. It just doesn't know how to do it yet. This comes next: