 |
 |
|
 |
|
|
|
|
|
|
|
|
|
|
Programming PC-Bee in Visual Basic |
|
|
|
|
|
|
|
|
|
|
|
| |
Although PC-Bee
comes with it's own software (BeeStep) 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 two library functions. |
|
| |
|
BeeInit()
and BeeOut(outputs) |
|
|
| |
BeeInit() is called somewhere near the start
of your program and takes care of all of the USB comms initialisation and
prepares the PC-Bee for receiving messages.
BeeOut(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 where bit0
corresponds to output 1, bit 1 to output2, etc... Where 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... |
|
| |
|
BeeOut(7) |
|
|
| |
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 an program excerpt showing how this
is done... |
|
| |
|
Declare
Function BeeInit
Lib "bee.dll"
() As
Boolean
Declare
Function BeeOut
Lib "bee.dll" (ByVal
Outputs As
Integer)
As
Boolean
|
|
|
| |
The first declaration states that the function BeeInit has no parameters,
is found in bee.dll and returns a boolean value. The second states that
BeeOut has one integer parameter passed by value rather than reference, is
found in bee.dll and also returns a boolean value. It should be
noted that the |
|
| |
|
Lib
"bee.dll" |
|
|
| |
lets the program know where to
find the bee.dll file. When written like this it assumes that since there
is no path information that the bee.dll file can be found in the windows
system directory c:\windows\system32 If
you like you can copy the file bee.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 below... |
|
| |
|
Declare
Function
BeeInit Lib
"c:\library\bee.dll" () As
Boolean |
|
|
| |
|
|
|
|
|
|
|
|
|
| |
To speed up
your development of software for the PC-Bee a complete working example is
available for download below. It is called VBbee and creates a very simple
form based program that has individual buttons for various functions such
as initialising the PC-Bee 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.
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 |
|
| |
|