![]() | The Mule™ The Bray DLL | ![]() |
![]() | ||
![]() | ||
| ANNOUNCEMENT |
For 30 years I have been helping organisations and individuals with their Barcode and Auto ID issues but now I have decided it is time to move on and retire from being the Barcode Man. I will continue to respond to emails from existing customers about their earlier purchases, their special programming configurations and warranty issues but I regret I cannot help with new purchases or issues nor recommend alternative products or sources. Lee Allen, The Barcode Man. February 2010 |
Mule Resources
The Mule is a trademark of Altek Instruments Ltd Support Services
| Power BasicIn this example it is assumed mulebray.dll is located in the same folder as the caller code (recommended) or in some other standard location where Windows can find it. If not you may have to prepend the path to the dll filename. These examples have been tested with PBWin80. They should also work with Power Basic Windows Console Compiler with minor changes (remove Dialog Box Code and substitute PRINT for the MSGBOX). The code shows how to call the braymain function in the Bray DLL using Power Basic. This language has native support for ASCIIZ strings and pointers which make the whole process simple. Before the braymain function can be used Power Basic has to be told its location and the calling parameters to use. This is done by a function declaration like this.
DECLARE FUNCTION braymain LIB "mulebray.dll" ALIAS "braymain" _
(BYVAL braycmd AS LONG, braystring AS ASCIIZ) AS DWORD
After the function is declared the braymain function can be called directly. Here is a complete program listing of a Windows application which can be cut and pasted direct into the Power Basic IDE. It consists of a single button on a Form. When the button is clicked the Bray command 0 is sent to the DLL. The DLL responds by sending back the DLL identification code (version number) which is displayed in a message box. This command does not need a string parameter to be sent so braystring is sent as a null.
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"
DECLARE FUNCTION braymain LIB "mulebray.dll" ALIAS "braymain" _
(BYVAL braycmd AS LONG, braystring AS ASCIIZ) AS DWORD
$AppTitle = "Mulebray test"
%IDC_SEND = 100
CALLBACK FUNCTION Test_Callback () AS LONG
LOCAL braycmd AS LONG 'braymain command parameter
LOCAL braystring AS ASCIIZ * 512 'braymain string parameter
LOCAL brayretstring AS ASCIIZ * 512 'braymain return string
LOCAL retval AS ASCIIZ POINTER 'pointer braymain return string
'-----------------------------------------------------------------
braycmd=0 'Zero command returns the DLL version number
braystring="" 'no string parameter is needed for zero command
retval = braymain(braycmd, braystring) 'get the pointer to the ASCIIZ
brayretstring=@retval 'get the string using the pointer
'brayretstring = PEEK$(ASCIIZ,retval,512) 'another way to get the return string
MSGBOX brayretstring 'show the string in a message box
'-----------------------------------------------------------------
FUNCTION = %TRUE
END FUNCTION
FUNCTION PBMAIN () AS LONG
#REGISTER NONE
LOCAL hDlg AS DWORD
' Create a modal dialog box
DIALOG NEW 0, $AppTitle,,, 80, 50, %WS_POPUP OR %WS_VISIBLE OR _
%WS_CLIPCHILDREN OR %WS_CAPTION OR %WS_SYSMENU OR _
%WS_MINIMIZEBOX, 0 TO hDlg
' Add a single button
CONTROL ADD BUTTON, hDlg, %IDC_SEND, "Test", 13, 10, 50, 14, _
%WS_GROUP OR %WS_TABSTOP OR %BS_DEFPUSHBUTTON _
CALL Test_Callback
DIALOG SHOW MODAL hDlg
END FUNCTION
You can use this code framework to experiment with sending Bray commands to the DLL to control the Mule (and through it a secondary slave computer). In the section between the dotted lines just change value of braycmd and give a string value to braystring when it is needed. A simple 'Hello World!' example is shown below. First you need to tell Bray which port the Mule is connected to. This only needs to be done once. The DLL retains the information until it is unloaded from memory when the program ends. Now you can send Bray commands direct to the DLL by loading braycmd with the value 1 and putting the Line of Bray in braystring. The DLL parses and executes the content of braystring. The example shows how to create keystrokes for Hello World! on the remote computer. Remember that Bray needs ASCII strings to be surrounded by double quotes. To do this use the built-in string constant $DQ and the concatenation operator to attach it to either end of the string. This is a very basic example. It works but if you run it a couple of times you will get an error because the code attempts to reopen an open port (you opened it on the previous run). Real applications would need to check for error conditions and provide feedback to the user. More comprehensive Bray examples can be found on the Further Bray DLL Examples page. Table of all the DLL commands and parameter values
'In this example we retrieve the return string by combining two lines
' of code used earlier into a single expression. This has the advantage
' that the intermediate variable retval is not needed.
' Downside - the code is harder to understand at a glance
braycmd = 20 'Command to tell Bray which COM port to use
braystring = "COM1" 'Assumes the Mule is connected to COM1
brayretstring = PEEK$(ASCIIZ,(braymain(braycmd,braystring)),512)
' A real application would probably check brayretstring for an error here.
braycmd = 1 'parse and execute Bray
'Use built-in string constant to surround the Bray ASCII string with Dquotes
braystring = $DQ+"Hello World!{ret}"+$DQ 'line of Bray.
brayretstring = PEEK$(ASCIIZ,(braymain(braycmd,braystring)),512)
|
![]() | |
![]() | |
| Top Home | © Altek Instruments Ltd, 2010 |