
MSW Logo Primitives
The syntax for 'calling' the mswbrick DLLs is quite involved. Typically, users must deal with long and complex commands along the lines of:
dllcall [v TurnPortOn v 0]. The likelihood of errors is quite high. The calls are further complicated by the importance of 'case'. "TurnPortOn", for example, is not the same as "TurnportOn".
MSW Logo will report a "Function not found." error unless the case matches exactly. These precise requirements can cause frustration when errors are made.
The alternative is to define the calls as MSW Logo "primitives" which provide much simpler calls for the user. These new primitives load automatically when MSW Logo loads and are available in exactly the same way that 'native' commands such as "forward" and "clearscreen" are used. As far as the user is concerned, your new primitives are an integral part of MSW Logo.
Defining New Primitives
To define a new primitive you must write a procedure containing the commands and then save the procedure into the MSW Logo "logolib" directory. The name of the procedure must be the same as the name of the file. The filename has no 'extension'. If you add the usual ".lgo" extension your primitive will not work.
For example …
Before you start using MSW Logo to control the Brick you must load the mswbrick DLL and then 'turn on' the tower. This requires two separate commands:
dllload "mswbrick.dll
dllcall[v TurnPortOn v 0]
The idea is to incorporate these commands into a new procedure called "toweron" and save the procedure as a file called "toweron" into the logolib directory.
ie
to TowerOn
dllload "mswbrick.dll
dllcall[v TurnPortOn v 0]
end
When MSW Logo starts up it will automatically load your file and make the procedure available as a new primitive. The user simply types "toweron" (without the quotes) in the MSW Logo command line and the instructions within the file toweron are carried out.
The same process is used to create single files containing each of the sets of commands you want to define as new "primitives".
The full set of sample mswbrick primitives is listed on the following pages …
NOTE: MSW Logo is not fussy about capitals, but the DLLCALL commands must contain correct capitalisation or you will get a "Function not found." Error message.
MSWBRICK Primitives
Tower Setup
|
to TowerOn to TowerOff |
Motor Control
|
to MotorAOn to MotorAReverse to MotorBOn to MotorBOff to MotorBForward to MotorBReverse to MotorCOn to MotorCOff to MotorCForward to MotorCReverse |
Sensor Control
|
to Sensor1On to Sensor1 to Sensor1Off to Sensor2On to Sensor2 to Sensor2Off to Sensor3On to Sensor3 to Sensor3Off |
NOTE: Each new primitive is saved as a separate file. The set listed above was saved as 23 individual files, each with the same filename as the name for the procedure (in the "to" line). You can't collect all of your procedures together and save them as one file.
Logo Primitives versus DLL Calls
Compare the following …
| Using MSW Logo Primitive Commands | Using DLLCALL |
| TowerOn wait 30 ; (See NOTE below.) MotorAForward MotorAOn wait 120 MotorAOff TowerOff |
dllload "mswbrick.dll dllcall[v TurnPortOn v 0] wait 30 dllcall[v MotorAForward v 0] dllcall[v MotorAOn v 0] wait 120 dllcall[v MotorAOff v 0] dllcall[v TurnPortOff v 0] dllfree |
NOTE: The "wait 30" command in the second line allows a delay while the tower is initialising. If you don't allow a small delay before calling another command your system may hang.
Both sets of code will turn on MotorA for two seconds and then turn it off again. It should be obvious which set of commands is easiest to understand and use.
Your new primitive commands can be used in procedures in the same way as all other MSW Logo commands. A typical procedure to make the RCX brick move forward, spin and then stop would be …
|
to travel TowerOn wait 30 ; Waits for the Tower to turn on MotorAForward MotorBForward MotorAOn MotorBOn wait 120 ; Buggy moves forward MotorAReverse wait 120 ; Buggy spins. (MotorB is still Forward.) MotorAOff MotorBOff TowerOff end |