Blassic - a Basic Interpreter for the Sweex/Edimax router and Debian Slug
Home site http://www.blassic.org/
The Manual in .doc format.......The same converted to a web page


I like basic - you can understand a line of code just by reading it!
And strings in basic are much easier to handle than in C!!!
I can edit Blassic basic using BBedit on a Mac and read and save to the router by the BBedit built in ftp commands.
No waiting to compile a C program - and Blassic runs plenty fast enough for control applications.

I thank Picprojects for introducing me to Blassic.
It runs on Linux and he has compiled a version for the Sweex/Edimax routers.
See his tutorial The following notes are based on his email answers to my questions.
These are my notes to aid my memory - if you use them to do interesting things please email me!

Get ready to install Blassic
Add picinternetprojects to the list of locations ipkg can install files - more info here
update /etc/ipkg.conf by adding -
src picprojects http://www.picinternetprojects.247n.com/packages
src picprojectsSDK http://www.picinternetprojects.247n.com/packages/sdk

Installing Blassic
(compiled without graphics functions and the sin/cos/tan functions)

In a Telnet session on a terminal type
ipkg update
ipkg install blassic

test it -(to exit and return to the command prompt type 'exit')

midge# blassic
Blassic 0.10.0
(C) 2001-2005 Julian Albo
Ok
now type -

10 for i=1 to 3
20 print i
30 next i
run
1
2
3
Ok
save "/var/blassic/count.bas"
Ok
exit


midge# blassic
Blassic 0.10.0
(C) 2001-2005 Julian Albo
Ok
load "/var/blassic/count.bas"
Ok
run
1
2
3
Ok

To load and save
use load "filename.bas" and save "filename.bas" as in the example above
Write your program in a text editor and save it as "program.bas"
In a script you can write "blassic program.bas" and the program will run.
Make the last line of your program something like '999 system' so that
the program will exit.
Whilst debugging, If you use -
save "filename.bas",a
- then the file will be saved in ascii text and you can still use your editor to edit it


To control the router's io and other ports, you can read and write files
using the file
open as

commands -

Read the LEDs
READ state of /dev/led0
10 open "/dev/led0" as #1
20 input #1,led$
30 print led$
40 close #1

(remember that for led0 alone ON =OFF and OFF=ON !)

Switch the LEDs
input a $ (a string) and WRITE it to /dev/led0
5 input "Type command for /dev/led0 ",ledcmd$
10 open "/dev/led0" for APPEND as #1
20 print #1,ledcmd$
30 close #1

and the 'shell' command will run any linux command line.
120 shell "echo 'LED ON' > /dev/led3"
130 for i=1 to 10000:next i
140 shell "echo 'LED OFF' > /dev/led3"


This will allow you to 'run' a linux command and direct the output
to a file. The Blassic program could then open this file and
extract some data.
The Blassic website has some examples of opening ports (nttp.bas and
htget.bas) and talking directly to other internet servers.

Official Blassic reference also see the Yahoo Blassic group

Send strings to a Blassic program from a web page and display the output of the program on the web page

Yo
u can do the whole thing in Blassic but I have an existing script system (menu tem 14) that can be adapted to call a Blassic program. It is easy then to add html generated by a WYSIWYG html editor rather than hand craft the basic to output every line of html code.

an example
- fill in a form on a web page with three strings called string1/string2/string3

The web page browser views the file http://xxx.xxx.xxx.xxx/b_test.cgi which displays b_test.html

that sends out 3 strings from a form back to b_test.cgi which calls

pg-b_test.sh

which runs

var/blassic/b_test.bas

Blassic code notes - some random notes


Have the program run using the command line format
./test.bas
place this on the first line of the Blassic program (NB there is no space after the # as the Blassic manual shows)
#!/usr/sbin/blassic


Blassic as a cgi scripting language (how easy can this get ?!!!)
Place this code in the /var/www/cgi-bin folder or in a sub folder of cgi-bin and call it count.cgi
#!/usr/sbin/blassic
FOR i=1 TO 3
PRINT i
NEXT i
SYSTEM

In a browser command line type -
http://192.168.0.3/cgi-bin/count.cgi
and see
1
2
3
in the window.


Sending data to a website as though from a Web Browser
I need to send
http://192.168.0.8:1025/ChangeResolution.cgi?ResType=2
to change the picture resolution of my Aviosys 9000 web connected camera

I am not sure how to place a link to it in a web page without closing the current page

However, I find that I can use htget.bas . This is designed to fetch a remote page but I find it also allows you to send any string to a server.

The link on my web page is
<a href="http://192.168.0.3/cgi-bin/loungecam/move_snap.cgi?page=picture_control&string=small">Small picture</a>

My move_snap.cgi script sends the string to a script pg-picture_control.sh

In there I included this line to make the picture small -
blassic /var/blassic/htget.bas http://192.168.0.8:1025/ChangeResolution.cgi?ResType=2
or ResType=3 for a big picture


Send "Hello" to the rs232 port
shell "echo 'hello' > /dev/ttyS0"


This also sends a string to the rs232 port
ttyS0_out$ = "hello from blassic again"
open "/dev/ttyS0" for APPEND as #1
print #1,ttyS0_out$
close #1


This sends the decimal value of a character to the rs232 port
A$ = "A"
open "/dev/ttyS0" for APPEND as #1
print #1,ASC(A$)

close #1

outputs 65 to Hyperterminal


send a single byte (input as decimal) to ttyS0
LABEL go_again
input "Type decimal value of byte to ttyS0 - 0 to end ",A
if A = 0 then goto end_it
open "/dev/ttyS0" for APPEND as #1
print #1,CHR$(A);
close #1
goto go_again
LABEL end_it
system


Send a string containing several words and spaces to the LCD panel
(special care needed with spaces)

=================================
fred$ = "wow fred"

shell "/usr/bin/lcd_out_4x20 -i"

shell "/usr/bin/lcd_out_4x20 "+CHR$(34)+fred$+CHR$(34)
=================================

NB! CHR$(34) is "
If they are not present the LCD just shows the first word "wow"

Also - to place a space between two strings on the bottom line,

SHELL "lcd_out_4x20 -4"
PAUSE 200
SHELL "lcd_out_4x20 'some text'"+string1$+CHR$34+CHR$32+CHR$34+string2$

+" "+ will not work, also +CHR$32+ will not work on it's own


Put the contents of file /var/www/ramdisk/myfile into string mystring$

OPEN "/var/www/ramdisk/myfile" FOR INPUT AS #1
INPUT #1,mystring$
CLOSE #1


Extract a string 3 bytes long starting at byte 2

mystring$ = MID$ (original_string$,2,3)


Create a shell command that contains a Blassic string mystring$ within the command sent

shell "echo -n "+mystring$+">/dev/ttyS1"


Send a non printing byte to the ttyS1 port

-n means do not add CR/LF
-e means expect an escape character after th \

use hex, \x13, or octal, \ 023 to represent decimal 19 and send itout on ttyS1

shell "echo -n -e '\x13'>/dev/ttyS1"


Catch the input from ttyS1

cat < /dev/ttyS1 >> /var/www/ramdisk/myfile &
# set catPID equal to PID of this command
catPid=$!

Wait for the input to be over
(the reply from the LCD/keypad is very rapid - a person might take a second)

# stop listening to ttyS1
kill $catPid

- do something with the saved data


Send a byte from a Blassic program to an ash script (via the ramdisk)

Blassic
'define_string.bas
' string from Blassic to ash
my_string$ = "my new Blassic created string"
' save the my_string$ to the ramdisk
shell "echo -n "+my_string$+" >/var/www/ramdisk/my_string"
system

ash
#!/bin/sh
#receive_blassic_string.sh
ash_string=`cat /var/www/ramdisk/my_string`
echo $ash_string


Run a c code program from within Blassic and use the output of the c program within Blassic
(an ash script within the shell command runs the c program and saves it's output to the ram disk -
Blassic then reads the file from the ram disk)


' create file /var/www/ramdisk/T72.txt containing the output of the i2c thermometer
' reading c program "lm75_address" that is at i2c address 72
' (this creates a new file or over-writes the file if it is already present)
' format is "19.5 Degrees Centigrade"

shell "echo -n `lm75_address 72`>/var/www/ramdisk/T72.txt"

' load it here as string T72$
OPEN "/var/www/ramdisk/T72.txt" FOR INPUT AS #1 : INPUT #1,T72$ : CLOSE #1

Temperature72 = VAL (T72$) 'just get the number part
PRINT Temperature72



To send a string from a bash script to a Blassic program then display it on the LCD panel
I use "export" to create an environmental variable that is available to any program
The ash script is -
=================================
#!/bin/sh
export message="this is a message"
=================================

the Blassic program includes -
=================================
rem in a script we created the global environmental variable "message"
text$ = ENVIRON$ ("message")
print "the blassic message is -> "; text$
=================================

(I can only get this to work if the Blassic program is called from the script after the export
- I find saving to and reading from the ramdisk is simpler) )


Read a byte from an RS232 port

You first need to get ttyS0 into raw mode - I run /usr/bin/rs232io_ttyS0_96 on the stick - then it acts like ttyS1 which works one character at a time in each direction. See the rs232 notes. I plan to study/test this but I know stty is odd in this router
http://lists.canonical.org/pipermail/kragen-hacks/1998-November/000129.html

This routine gets the input from ttyS0 and puts it into string A$

' serial in tests serial_in.bas
OPEN "/dev/ttyS0" FOR INPUT AS #1
LABEL Again
A$ = INKEY$(#1)
IF A$ = "Z" THEN GOTO AllDone
PRINT A$
GOTO Again
LABEL AllDone
CLOSE #1
SYSTEM

It works with Hyperterminal connected to ttyS0 - I have yet to test it with small ascii values - hex00 is very odd in ash scripts.
Yet to try the following offered by the author of Blassic (many thanks!)
OPEN "/dev/ttyS0" FOR BINARY INPUT AS #1


Some of my backup programs - they run but are not often efficient!

- saved here to copy and paste routines from.

file_reader_test.bas
days_between_dates.bas
byte_to_ttyS0.bas


 


 

 

 

 

 

 

That's all I have tried for now -
If you write a Blassic program for the Sweex please send me a copy by email