Using the ADB I/O with REALbasic
This implementation uses the ADB I/O's AppleScript OSAX.
Using the XCMDs would be preferred, but (at least in the current implementation)
REALbasic doesn't do all the right stuff with XCMDs. Bummer.
The process:
Write some individual AppleScripts; save them as compiled
scripts. Drag them into REALbasic's Project window. The new command/function,
named by the script's filename, is now embedded and available within your
REALbasic project. This is what I've done, although you are welcome to rewrite
anything at all.
The project:
I set out to implement ADB I/O functions from within REALbasic.
Phase one was to create AppleScripts to get or set any ADB I/O function.
Phase two was to integrate those scripts within REALbasic, and write some
REALbasic code (as a demo) to prove it all works.
The results:
I believe the AppleScripts are complete, and can perform
any and all ADB I/O functions, at least those performable from within AppleScript.
The demo application is just a shell; it provides a pretty
interface to demonstrate how to use the scripts. You can do most ADB I/O
stuff with it, although some things (like setting the B-port to a mix of
digital and analog) are not implemented in the demo. Easily modified to
your own application.
The demo application does nothing to trap errors before
trying the command; if you send a silly command (like setting an A-port
channel to analog in), you will get the error returned by ADB I/O's OSAX.
The implementation:
Four scripts are available:
- CFGADBIO - configure an individual channel (Port A only)
- CFGADBIOP - configure an entire port
- GetADBIO - get the status of a channel
- SetADBIO - set the status of a channel
Calling the scripts:
- CFGADBIO(unit:integer, port:string, channel:integer,
type:string)
- CFGADBIOP(unit:integer,port:string,type:string,type:string,type:string,type:string)
- GetADBIO(unit:integer,port:string,channel:integer)
- SetADBIO(unit:integer,port:string,channel:integer,value:string,howlong:integer)
Each script returns a string as a result. The result from
CFGADBIO, CFGADBIOP and SetADBIO is "1" if no errors reported.
The result contains the error number and error string if an error is reported.
The "howlong" integer in SetADBIO is ignored
for port B (which doesn't allow the parameter), but must be sent to the
script anyway. A setting of zero seems to keep the channel set indefinitely;
please let me know if this isn't the case! Please note that although the
ADB I/O OSAX does allow the "howlong" to be in tenths (of a second),
REALbasic currently limits calls to AppleScripts to strings and integers
only.
- Units allowable: 1, 2, 3, 4
- Ports allowable: A, B
- Channels allowable: 1, 2, 3, 4
- Types allowable: digital in, digital out, analog in,
analog ref
The demo application looks like this:
Using it should be plenty obvious. Remember, this demo
doesn't prevent you from trying things you shouldn't, and doesn't provide
for some ADBIO functions.
Where to get it:
Download adbiorb.sit.hqx
(298K, BinHex), which contains the following:
- ADBIO/RB 0.2 (the source code)
- ADBIO/RB 0.2.app (68K, compiled in REALbasic Release 1.0)
- And the four scripts listed above
If you already have REALbasic 1.0, you can download adbiorb-noapp.sit.hqx (26K, BinHex), which
has all of the above minus the compiled application.
What you need:
You need an ADB I/O, which used to be made by Beehive but isn't
available any more.
You need the ADB I/O OSAX, which comes with the ADB I/O.
REALbasic, from REAL
Software. You don't need REALbasic to run the demo, but you will to
work with the code (and that's the whole point now, isn't it?)
What else should I know?
Not much. It wouldn't hurt to look at the sample AppleScripts
that come with the ADB I/O to see all the options.
Who did this?
Mitch Cohen. Drop me a note (mcohen@proactiveinteractive.com)
if you have any questions, problems, compliments, or complaints.
|