 |
 |
|
 |
|
|
|
|
|
|
|
|
|
|
Programming W.A.S.P. in Visual Basic |
|
|
|
|
|
|
|
|
|
|
|
| |
Although WASP comes with it's own
software (WaspWare) to allow the beginner to start using it in home
automation projects very quickly, it also comes with a DLL interface to
allow the intermediate and advanced user to write their own programs for
it. The DLL provides a general purpose interface that greatly simplifies
the task of writing programs for a USB device. It can be tricky
manipulating the USB comms into sending and receiving messages to and from
a device which can easily be plugged and unplugged at any time. The
DLL eliminates all of these headaches by simplifying the task into three
library functions. |
|
| |
|
InitWasp( )
,
SetOutputs (outputs) and
ReadInputs(analogue) |
|
|
| |
InitWasp()
is called somewhere near the start of your program and takes care of all
of the USB comms initialisation and prepares the WASP for sending and
receiving messages.
SetOutputs(outputs) can then be called
at any time during your program to set the output pattern of on's and
off's. The parameter Outputs is simply a 32
bit integer value. In Outputs, bit0
corresponds to output 1, bit 1 to output2, etc... In each case a
logic value of 1 turns the output on and a value of 0 turns it off. For
example the statement below would turn on the first three outputs... |
|
| |
|
SetOutputs (7) |
|
|
| |
and the following would turn on outputs 1, 2,
and 4 |
|
| |
|
SetOutputs (11) |
|
|
| |
ReadInputs(analogue) can also be called at any time during your
program to read the current values of the analogue inputs. When you call
this function the WASP performs an analogue to digital conversion on the 4
inputs and stores the results in 4 (32 bit) integers. The integers are
actually the elements of the array called analogue.
This array has been passed By Reference to the wasp dll by your program,
allowing the dll to modify its contents directly. You array should be
declared as follows... |
|
| |
Dim
analogue(4) As
Integer
|
|
| |
The values
stored in these array elements will correspond to the analogue inputs
representing 0 to 5volts as 0 to 255. For example if the analogue inputs
are 1v, 2.5v, 4v and 5v respectively the contents of the array
analogue after the
ReadInputs( analogue(0) ) function call will be.... |
|
| |
analogue(0)
= 51, analogue(1)=128, analogue(2)=204 and analogue(3)=255 |
|
| |
The only other thing that a VB program
must do is to declare the functions that it is going to use within the DLL
and the name of the DLL itself. This must be done at the start of your
program or at least before any references to the two functions are made.
The following is a program excerpt showing how this is done... |
|
| |
Declare
Function
InitWasp Lib "wsp.dll"
() As
Boolean
Declare Function
SetOutputs Lib "wsp.dll" (ByVal
outputs As
Integer)
As
Integer
Declare Function
ReadInputs Lib "wsp.dll" (ByRef
analogue As
Integer)
As
Integer |
|
| |
The first declaration states that the function
InitWasp
has no parameters, is found in
wsp.dll and returns a
boolean value. The second states that
SetOutputs
has one integer parameter passed by value
rather than reference, is found in wsp.dll
and also returns an integer value. The third declaration states that
ReadInputs has one parameter which is a reference to an integer and
returns an integer value. The reference to the integer is actually the
reference to the first integer in an integer array, with the subsequent 3
array values also being used to store analogue results. It should be noted
that the |
|
| |
|
Lib
"wsp.dll" |
|
|
| |
lets the program know where to find the wsp.dll
file. When written like this it assumes, since there is no path
information, that the wsp.dll
file can be found in the windows system directory
c:\windows\system32
If you like you can copy the file wsp.dll
on the installation disk to the system32 directory and the above statement
will work perfectly. Alternatively you can copy the file to some other
location and give that location in the declaration as in the example
below... |
|
| |
|
Declare
Function
InitWasp
Lib "c:\mylibrary\wsp.dll"
() As
Boolean |
|
|
| |
|
|
|
|
|
|
|
|
|
| |
To speed up your development of software for the WASP a complete working
example is available for download below. It is called VBwasp and creates a
very simple form based program that has individual buttons for various
functions such as initialising the WASP and setting various patterns on
the outputs. The main (and only) screen is shown on the right. This
has been written using Microsoft Visual Studio .net and the download files
contain the full workspace (solution) details to allow you to
immediately open and start editing or running this application.
Even if you don't have Visual Studio, the source code is virtually self
explanatory with the most relevant sections being in "Form1.vb" which can
even be opened in a simple text editor such as notepad. The files are
zipped for convenience and may be downloaded by right clicking on the link
below and choosing "save target as" to begin the download. |
|
| |
|
|
|
|
|
|
|
|
|
| |
|
|
Download Files |
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
| |
.
. |
|
| |
©
Copyright pc-control.co.uk 2008 |
|
| |
|