Friday, April 27, 2012
Before Make Magazine
In the corner of the factory there was a rather large machine sitting there unused. There was a sort of hodgepodgeness (if that's a word) about it. My boss Bob explained to me that this was a CNC machine that he had built himself. Wow! So before the company had money to purchase the industry standard Excellon drilling and routing machines he had decided it was possible to build his own, and it worked. I think that's really impressive!
Tuesday, April 03, 2012
BASIC for the Raspberry Pi?
What's Raspberry Pi? It is a cool new single board computer about the size of a credit card. It runs Linux (it can run other things) and it only costs $35, or $25 if you don't care about networking. You only need a micro USB charger or batteries to power it, a keyboard and mouse, and an HDMI compatible monitor or TV set.
This new device is aimed at schools, but the appeal of such a device is obviously very broad. I went to their forum and mentioned the idea of producing a version of BASIC for the RP. The reactions were mixed. Seems like that crowd is strongly committed to Python. That's okay, I've got my hands full right now with Liberty BASIC and Run BASIC.
Perhaps in the future I will have a chance to do something. It would probably be my first open source project, based on Squeak Smalltalk.
This new device is aimed at schools, but the appeal of such a device is obviously very broad. I went to their forum and mentioned the idea of producing a version of BASIC for the RP. The reactions were mixed. Seems like that crowd is strongly committed to Python. That's okay, I've got my hands full right now with Liberty BASIC and Run BASIC.
Perhaps in the future I will have a chance to do something. It would probably be my first open source project, based on Squeak Smalltalk.
Labels:
basic,
linux,
python,
raspberry pi,
raspberrypi,
smalltalk,
squeak
Tuesday, March 13, 2012
The Arduino Phenomenon
Seems like there is a lot of interest lately in using microcontrollers such as the BASIC Stamp and the new Arduino products. To my surprise, even a long retired electrical engineer friend knew about Arduino when I asked him. I get email from users of these products asking if they can use Liberty BASIC to program them. The answer is no, and yes.
These devices come with their own programming tools. Liberty BASIC is a Windows only (and soon also Mac and Linux) language, so it cannot be used to program microcontrollers. However I've been told that they have found a use for Liberty BASIC with microcontrollers. Some people have created a GUI control panel (including running graphics for example) for their microcontroller projects using Liberty BASIC because Liberty BASIC can be used to monitor devices using serial, parallel and network ports.
For more information about this, see the following link (you will need to register with the forum to read the posts).
http://libertybasic.conforums.com/index.cgi?board=comport
These devices come with their own programming tools. Liberty BASIC is a Windows only (and soon also Mac and Linux) language, so it cannot be used to program microcontrollers. However I've been told that they have found a use for Liberty BASIC with microcontrollers. Some people have created a GUI control panel (including running graphics for example) for their microcontroller projects using Liberty BASIC because Liberty BASIC can be used to monitor devices using serial, parallel and network ports.
For more information about this, see the following link (you will need to register with the forum to read the posts).
http://libertybasic.conforums.com/index.cgi?board=comport
Saturday, March 12, 2011
Automatic file backup - using a timer
Once our file backup utility is running and our window is open we need to be able to use the start and stop buttons to control the activity of program.
Here is the code for the start action. It ties into the [start] label in the Start button.
When the button is clicked we disable the Start button and enable the Stop button to show which operations are valid. We call [checkInitialFiles] which we haven't written yet (we'll get into that later). We show in the statusLog texteditor that we are starting the backup process. Then we get the contents of the interval textbox and start the timer. The reason we multiply the interval by 1000 is that the timer measures time in milliseconds so if we want 5 a second interval we need to give the timer a value of 5000. Finally we stop and wait for a timer tick or for user interaction.
Once our timer is running we need to be able to stop it. Here is our stop handler:
This is real simple. First thing is to stop the timer with timer 0. Then we reverse the enabling of the Start and Stop buttons. Compare this to the way that [start] does it. Then we log to the statusLog texteditor that we are stopping. Finally we wait.
The purpose of the [checkInitialFiles] subroutine is to create a description of the files we are interested in and the time and date they were last modified. Then each time the timer ticks after this we create a new description of these files. If the date and time changes on any of these files then it's time to make a new backup.
Just for now let's just create an empty [checkInitialFiles] subroutine:
The routine doesn't do anything yet, so we only have a RETURN statement.
Now we'll create a [checkFiles] routine which will be called each time the timer ticks. For now the routine will not do much. We will write the full routine in a later section.
The first thing we do is log the word "tick" to the statusLog. This is for instructive purposes only and will be removed later. We do this so that we can see that the timer is working. After this we disable the timer. This might seem like a strange idea, but the reason we do it is because the next thing we do is check the files to see if they changed (we'll write this part later). If they change we don't want the timer to be running because if it takes a while to backup the files and the timer is still running then the timer events can build up. Once the file check and possible backup are finished we reenable the timer.
The entire listing so far is posted below. Try running it. When you click Start it will begin logging its activity. Notice that the word tick gets logged every five seconds. Click the Stop button and change the interval to 1. Start it again and the logging will happen once per second.
Here is the code for the start action. It ties into the [start] label in the Start button.
[start] 'startup the backup timer
#main.start "!disable"
#main.stop "!enable"
gosub [checkInitialFiles]
#main.statusLog "Starting backup"
#main.interval "!contents? interval"
timer interval * 1000, [checkFiles]
wait
When the button is clicked we disable the Start button and enable the Stop button to show which operations are valid. We call [checkInitialFiles] which we haven't written yet (we'll get into that later). We show in the statusLog texteditor that we are starting the backup process. Then we get the contents of the interval textbox and start the timer. The reason we multiply the interval by 1000 is that the timer measures time in milliseconds so if we want 5 a second interval we need to give the timer a value of 5000. Finally we stop and wait for a timer tick or for user interaction.
Once our timer is running we need to be able to stop it. Here is our stop handler:
[stop] 'stop the backup timer
timer 0
#main.start "!enable"
#main.stop "!disable"
#main.statusLog "Stopping backup"
wait
This is real simple. First thing is to stop the timer with timer 0. Then we reverse the enabling of the Start and Stop buttons. Compare this to the way that [start] does it. Then we log to the statusLog texteditor that we are stopping. Finally we wait.
The purpose of the [checkInitialFiles] subroutine is to create a description of the files we are interested in and the time and date they were last modified. Then each time the timer ticks after this we create a new description of these files. If the date and time changes on any of these files then it's time to make a new backup.
Just for now let's just create an empty [checkInitialFiles] subroutine:
[checkInitialFiles] 'snapshot of filenames and timestamps
return
The routine doesn't do anything yet, so we only have a RETURN statement.
Now we'll create a [checkFiles] routine which will be called each time the timer ticks. For now the routine will not do much. We will write the full routine in a later section.
[checkFiles] 'are there new files
#main.statusLog "tick"
'temporarily disable the timer
timer 0
'perform the check here
'reenable the timer
timer interval * 1000, [checkFiles]
wait
The first thing we do is log the word "tick" to the statusLog. This is for instructive purposes only and will be removed later. We do this so that we can see that the timer is working. After this we disable the timer. This might seem like a strange idea, but the reason we do it is because the next thing we do is check the files to see if they changed (we'll write this part later). If they change we don't want the timer to be running because if it takes a while to backup the files and the timer is still running then the timer events can build up. Once the file check and possible backup are finished we reenable the timer.
The entire listing so far is posted below. Try running it. When you click Start it will begin logging its activity. Notice that the word tick gets logged every five seconds. Click the Stop button and change the interval to 1. Start it again and the logging will happen once per second.
dim info$(10,10)
setupPath$ = DefaultDir$+"\backupsetup.ini"
WindowWidth = 560
WindowHeight = 460
statictext #main, "Files to backup:", 5, 5, 94, 20
texteditor #main.listOfFiles, 5, 26, 530, 95
statictext #main, "Destination folder:", 5, 132, 107, 20
textbox #main.destination, 115, 127, 420, 25
statictext #main, "Backup interval in seconds:", 5, 157, 163, 20
textbox #main.interval, 170, 152, 100, 25
button #main.save,"Save",[save], UL, 495, 152, 42, 25
button #main.start,"Start",[start], UL, 5, 187, 75, 25
button #main.stop,"Stop",[stop], UL, 90, 187, 70, 25
statictext #main, "Backup status log", 5, 217, 106, 20
texteditor #main.statusLog, 5, 237, 530, 160
menu #main, "Edit"
open "Backup Utility" for window_nf as #main
#main.stop "!disable"
gosub [loadSetup]
wait
[loadSetup]
#main.listOfFiles "!cls";
if fileExists(setupPath$) then
open setupPath$ for input as #setup
while filename$ <> "end!"
line input #setup, filename$
if filename$ <> "end!" then
#main.listOfFiles filename$
end if
wend
line input #setup, destination$
#main.destination destination$
line input #setup, interval
#main.interval interval
close #setup
end if
return
[start] 'startup the backup timer
#main.start "!disable"
#main.stop "!enable"
#main.interval "!contents? interval"
gosub [checkInitialFiles]
#main.statusLog "Starting backup"
timer interval * 1000, [checkFiles]
wait
[stop] 'stop the backup timer
timer 0
#main.start "!enable"
#main.stop "!disable"
#main.statusLog "Stopping backup"
wait
[checkInitialFiles] 'snapshot of filenames and timestamps
return
[checkFiles] 'are there new files
#main.statusLog "tick"
'temporarily disable the timer
timer 0
'perform the check here
'reenable the timer
timer interval * 1000, [checkFiles]
wait
'return a true if the file in fullPath$ exists, else return false
function fileExists(fullPath$)
files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
fileExists = val(info$(0, 0)) > 0
end function
'return just the directory path from a full file path
function pathOnly$(fullPath$)
pathOnly$ = fullPath$
while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
wend
end function
'return just the filename from a full file path
function filenameOnly$(fullPath$)
pathLength = len(pathOnly$(fullPath$))
filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
Labels:
file exists,
gosub,
gui,
logging,
setup file,
subroutine,
timer
Thursday, March 03, 2011
Automatic file backup - loading setup
Now that we've got a simple GUI designed, let's write some code which will load the files we want to backup, the destination path, and the interval of our automatic backup.
We need a subroutine to load the setup which we will call using GOSUB. We can call this right after we open the window.
We want to know if the setup file exists. There is an example program called fileExists.bas that comes with the functions we need to check for file existence. We'll just grab those. Here they are:
We will call the fileExists( ) function from our [loadSetup] subroutine. A really simple example of the data in our setup file would have a list of file paths, and end! marker for the end of that list of files, a single line with the desired destination path, and another line with the interval in seconds between backup attempts.
Example backupSetup.ini
Once we know the file exists we can open it up and read it, placing the information into the different fields in our GUI.
Here is the complete listing so far:
We need a subroutine to load the setup which we will call using GOSUB. We can call this right after we open the window.
open "Backup Utility" for window_nf as #main
gosub [loadSetup]
wait
We want to know if the setup file exists. There is an example program called fileExists.bas that comes with the functions we need to check for file existence. We'll just grab those. Here they are:
'return a true if the file in fullPath$ exists, else return false
function fileExists(fullPath$)
files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
fileExists = val(info$(0, 0)) > 0
end function
'return just the directory path from a full file path
function pathOnly$(fullPath$)
pathOnly$ = fullPath$
while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
wend
end function
'return just the filename from a full file path
function filenameOnly$(fullPath$)
pathLength = len(pathOnly$(fullPath$))
filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
We will call the fileExists( ) function from our [loadSetup] subroutine. A really simple example of the data in our setup file would have a list of file paths, and end! marker for the end of that list of files, a single line with the desired destination path, and another line with the interval in seconds between backup attempts.
Example backupSetup.ini
c:\myfolder\test.txt
c:\myfolder\backMeUp.dat
c:\myfolder\SillyPutty.exe
end!
c:\backupFolder\files
5
Once we know the file exists we can open it up and read it, placing the information into the different fields in our GUI.
[loadSetup]
#main.listOfFiles "!cls";
if fileExists(setupPath$) then
open setupPath$ for input as #setup
while filename$ <> "end!"
line input #setup, filename$
if filename$ <> "" then
#main.listOfFiles filename$
end if
wend
line input #setup, destination$
#main.destination destination$
line input #setup, interval
#main.interval interval
close #setup
end if
return
Here is the complete listing so far:
dim info$(10,10)
setupPath$ = DefaultDir$+"\backupsetup.ini"
WindowWidth = 560
WindowHeight = 460
statictext #main, "Files to backup:", 5, 5, 94, 20
texteditor #main.listOfFiles, 5, 26, 530, 95
statictext #main, "Destination folder:", 5, 132, 107, 20
textbox #main.destination, 115, 127, 420, 25
statictext #main, "Backup interval in seconds:", 5, 157, 163, 20
textbox #main.interval, 170, 152, 100, 25
button #main.save,"Save",[save], UL, 495, 152, 42, 25
button #main.start,"Start",[start], UL, 5, 187, 75, 25
button #main.stop,"Stop",[stop], UL, 90, 187, 70, 25
statictext #main, "Backup status log", 5, 217, 106, 20
texteditor #main.statusLog, 5, 237, 530, 160
menu #main, "Edit"
open "Backup Utility" for window_nf as #main
gosub [loadSetup]
wait
[loadSetup]
#main.listOfFiles "!cls";
if fileExists(setupPath$) then
open setupPath$ for input as #setup
while filename$ <> ""
line input #setup, filename$
if filename$ <> "end!" then
#main.listOfFiles filename$
end if
wend
line input #setup, destination$
#main.destination destination$
line input #setup, interval
#main.interval interval
close #setup
end if
return
'return a true if the file in fullPath$ exists, else return false
function fileExists(fullPath$)
files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
fileExists = val(info$(0, 0)) > 0
end function
'return just the directory path from a full file path
function pathOnly$(fullPath$)
pathOnly$ = fullPath$
while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
wend
end function
'return just the filename from a full file path
function filenameOnly$(fullPath$)
pathLength = len(pathOnly$(fullPath$))
filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
Labels:
file exists,
gosub,
gui,
setup file,
subroutine
Tuesday, March 01, 2011
Automatic file backup UI design
Here's what I'm thinking. The back utility GUI will be a simple window with a text area that contains a list of file paths. There will be start and stop buttons, an interval for a timer in seconds, and a field with a destination path.
When the timer is started the backup utility will examine each file that is specified in the text area and collect modification date and time. Later when the timer ticks we will check them again to see if any of them has changed. If even one of the files is different we will back them up as a set.
To perform the backup the program will take the destination path and use it to create a unique folder by adding a number to it. Then it will copy all the files into newly created folder.
There will also be a status area in the window where the user will be kept informed about backup activities.
The configuration for the backup utility will be stored in a file. When the program is started it will be loaded and displayed in the GUI, and there will be a save button to save the configuration back to the configuration file.
More than likely this design will evolve as we actually build the program code.
Here is the beginning of our program, just the GUI code to start.
When the timer is started the backup utility will examine each file that is specified in the text area and collect modification date and time. Later when the timer ticks we will check them again to see if any of them has changed. If even one of the files is different we will back them up as a set.
To perform the backup the program will take the destination path and use it to create a unique folder by adding a number to it. Then it will copy all the files into newly created folder.
There will also be a status area in the window where the user will be kept informed about backup activities.
The configuration for the backup utility will be stored in a file. When the program is started it will be loaded and displayed in the GUI, and there will be a save button to save the configuration back to the configuration file.
More than likely this design will evolve as we actually build the program code.
Here is the beginning of our program, just the GUI code to start.
WindowWidth = 560
WindowHeight = 460
statictext #main, "Files to backup:", 5, 5, 94, 20
texteditor #main.listOfFiles, 5, 26, 530, 95
statictext #main, "Destination folder:", 5, 132, 107, 20
textbox #main.destination, 115, 127, 420, 25
statictext #main, "Backup interval in seconds:", 5, 157, 163, 20
textbox #main.interval, 170, 152, 100, 25
button #main.save,"Save",[save], UL, 495, 152, 42, 25
button #main.start,"Start",[start], UL, 5, 187, 75, 25
button #main.stop,"Stop",[stop], UL, 90, 187, 70, 25
statictext #main, "Backup status log", 5, 217, 106, 20
texteditor #main.statusLog, 5, 237, 530, 160
menu #main, "Edit"
open "Backup Utility" for window as #main
wait
Saturday, February 26, 2011
Automatic file backup
I'm inspired by a real world need I have to create utility in Liberty BASIC which will do the following:
1) Periodically examine a list of files in a folder to see if they have changed
2) Make a new folder with a unique name somewhere else to contain the updated files
3) Copy the changed files to the new folder
We can keep a list of paths and files in a file, create a simple gui for maintaining this list and starting and stopping the timer, and for displaying a log of activity.
In our next installment we will write the GUI code.
1) Periodically examine a list of files in a folder to see if they have changed
2) Make a new folder with a unique name somewhere else to contain the updated files
3) Copy the changed files to the new folder
We can keep a list of paths and files in a file, create a simple gui for maintaining this list and starting and stopping the timer, and for displaying a log of activity.
In our next installment we will write the GUI code.
Thursday, February 24, 2011
Projects
I've decided to start some small projects which show how to do various things in Liberty BASIC. This will be a good way to demonstrate how easy programming in BASIC can be, and it will help people to learn specific programming techniques.
Labels:
basic,
learn,
learn programming,
liberty basic,
programming,
projects
Tuesday, December 01, 2009
Words of wisdom
I've always been a big fan of the Forth programming language. It is nothing like BASIC, but here is a page from forth.com with some words of wisdom from Chuck Moore that I figure are just good food for thought no matter what language you prefer.
http://www.forth.com/resources/evolution/evolve_1.html
http://www.forth.com/resources/evolution/evolve_1.html
Sunday, October 11, 2009
BASIC and Space Flight!
The same fellow who created an OpenGL flight simulator in Liberty BASIC has taken it a step further by creating a spaceflight simulator with a map editor. Very neat!
Check it out
Check it out
Labels:
basic,
basic programming,
flight simulator,
graphics,
liberty basic,
opengl,
orbit,
planets,
qbasic,
solar system,
vb
Monday, September 28, 2009
BASIC, Lasers, and you
Here's an interesting example of the perfect use for BASIC. If you're into laser tag and programming this may be your ticket. It's cool that the makers of this device decided to write the config tool in Liberty BASIC, and that they make the code available so the average Joe can customize it. That's in the spirit of BASIC. Programming for the non-programmer.
http://www.lasertagparts.com/mtmicro.htm
http://www.lasertagparts.com/mtmicro.htm
Friday, September 18, 2009
Fractals in a page of code
What's great about BASIC and languages like it is that you don't have a write a lot of code that has nothing to do with what you're trying to create (like Java for example). It should be really easy to throw together a little code and play with graphics. Programming should be fun, not a burden.
Here is a thread that shows how to draw fractals in less than a page of BASIC.
Click to read the thread
Here is a thread that shows how to draw fractals in less than a page of BASIC.
Click to read the thread
Labels:
basic,
basic programming,
easy programming,
fractal,
graphics,
java
Friday, September 11, 2009
Levity and Programming
BASIC is the perfect programming language to a lighthearted programming challenge, and I'm about to prove it to you. What better matchup between BASIC than Paper, Rock, Scissors?
Check it out. It's great to see people programming just for fun.
Check it out. It's great to see people programming just for fun.
Programming tools in BASIC
Alyce Watson has updated her CodeAChrome widget, which is a syntax coloring editor specially made for editing BASIC source code. It's small, simple to use, and free! Check out her announcement here.
Labels:
basic,
basic programming,
code editor,
free,
syntax coloring,
widget
Thursday, September 03, 2009
Earth shaking!
Here's a neat example of BASIC programming which plots earthquake data graphically. What's cool about this is that it demonstrates graphics, interfacing with VBScript, and getting information off the Internet. Add to this that it's not a large program.
Labels:
basic,
graphics,
internet,
programming,
vbscript
Tuesday, September 01, 2009
Who says you can't do that in BASIC?
Over at the Liberty BASIC forum on Conforums they've announced a programmer of the month for September. Chung, a prolific Liberty BASIC programmer has created an OpenGL flight simulator in Liberty BASIC. Very, very nice!
Click to read the announcement and make sure to follow the link to Chung's site to see the flight simulator!
Labels:
basic,
basic programming,
flight simulator,
gaming,
graphics,
opengl,
simulation,
video game
Saturday, July 25, 2009
Searching for BASIC
When people search for BASIC online using Google or Bing, or whatever, what keywords do they search with? Some of the obvious choices to me are:
- basic
- basic for windows
- qbasic
- visual basic
- vb
How would you search for BASIC?
Monday, June 01, 2009
Joy in Programming
I responded to a post on another blog (http://blogten.blogspot.com/2009/05/wards-comment.html) about how someone complained that the Smalltalk programming language permits the programmer too much freedom and that it's "too easy." The argument against being easy is that if it's too easy the programmer will be able to rush into creating software that is designed poorly. I have a hard time believing it is ever a benefit that something is hard to do. I think this applies to languages like BASIC so I'm copying what I posted there below.
Freedom is essential if you want to live life to the full, and not just in software development. We need to teach what is the best way to live in freedom, not impose a tyranny of suffocating "safety". If we don't build a culture of discipline and excellence then we deserve what we get. If we impose tons of rules to in an effort to prevent people from making mistakes we risk making software development such a burden that few people will want to do it anymore. It should be possible for software development to be an enjoyable activity, and for innovation and discovery to be experienced by newbies and experts. Joy is important in life.
Perhaps I oversimplify, but I hope this communicates an important idea effectively.
Saturday, January 03, 2009
Easter Eggs?
Here's a link to a fun article about how Microsoft added Easter Eggs to their original BASIC implementations.
It never even occurred to me to do this. ;-)
Monday, December 15, 2008
Imposter?
I found an article named Web programming is hard to do right by a fellow named Bert Hubert. He does a nice job of explaining what is so hard about web programming and then goes on to describe how it could be done right. He even includes some BASIC code as an example. I like the questions he asks:
He provides some C-like code implementing what the BASIC code does. I guess that this new scripting language is code for a language called Imposter by Gabor Vitez which he mentions in a note at the top of his article.
I did a quick search for information about Imposter and its author but it seems to have withdrawn from the Internet. Does anyone know where to get a copy of Imposter to have a look?
- How did we arrive at this mess?
- That's just the way it works, isn't it?
- How should it be then?
- Why not go back to the old days?
He provides some C-like code implementing what the BASIC code does. I guess that this new scripting language is code for a language called Imposter by Gabor Vitez which he mentions in a note at the top of his article.
I did a quick search for information about Imposter and its author but it seems to have withdrawn from the Internet. Does anyone know where to get a copy of Imposter to have a look?
Labels:
basic,
bert hubert,
C,
gabor vitez,
imposter,
run basic
Subscribe to:
Posts (Atom)