Home Page The Mule™ The Bray DLL shopping cart
site currency

currency info
spacer Home spacer Barcode Mill spacer Barcode Fonts spacer How to order spacer Email us spacer

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

Web This site

Mule Resources

bulletMule Home
bulletMule Dispatcher
bulletBray Overview
bulletBray Basics
bulletBray Script Index
bulletBray DLL
bulletKeyboard Emulator
bulletKeyboard Scan Codes
bulletMule Quickstart
bulletTechnical Manual
bulletEngineering details
bulletLegacy Tech Manual
bulletLegacy downloads

The Mule is a trademark of Altek Instruments Ltd

Support Services

bulletTechnical Support
bulletHow to Order
bulletEmail us
bulletWho we are
bulletPolicy Statements
bulletSpam email from here?

Thin Basic

[Thin Basic Web Site]

In 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. These examples have been tested with Thin Basic v1.3.0.0

Thin Basic is a fully featured automation script engine. Thin Basic meshes well with Bray. It is intuitive, simple and provides Bray with a comprehensive programmable environment. It is as advanced as any other modern computer language yet as easy to use as the old style pre-Windows Batch files. You run Thin Basic text scripts just by clicking on a filename. Best of all - like Bray, Thin Basic is free.

The first example shows how to call the braymain function in the Bray DLL using Thin Basic.

This is a complete working script. Copy it all into a text file and save it as braytest.tbasic. If you have Thin Basic installed on your machine just double click on the file to run it.

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.

'Interacting with the Bray DLL using Thin Basic. A basic calling framework

'declare the braymain function in the mulebray.dll
Declare Function braymaindll Lib "mulebray" Alias "braymain" _
  (ByVal braycmd As Long, braystring AS ASCIIZ)AS DWORD

'declare a helper Windows API function
Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" _
  (ByVal ptr As Long) As Long

'Wrapper to communicate with Bray
Function braymain(braycmd As Long,braystring As String) As ASCIIZ 
   Dim retval As Dword
   Dim length As Dword
   Dim braystringz as ASCIIZ * 512
   braystringz=braystring    'limited length of input string
   retval = braymaindll(braycmd, braystringz)
   Function = PEEK$(retval,length)  
End Function

'define Double-quote string constant to simplify Bray string handling
$DQ = chr$(34)    

Dim braycmd       As Long
Dim braystring    As String
Dim brayretstring As String

braycmd=0                   'Zero command returns the DLL version number
braystring=""               'no string parameter is needed for zero command
MsgBox 0,brayretstring,%MB_OK,"Mule/Bray test"    

You can use this code framework to experiment with sending Bray commands to The Mule and through it take control of a secondary slave computer. In the section between the dotted lines just change value of braycmd and give a string value to braystring when needed.

A simple 'Hello World!' example is shown below.

First you tell Bray which COM port The Mule is connected to. Then you 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 concatenation operator to attach string constant $DQ to either end.

This is a very basic example. 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.

Further Bray DLL Examples

Table of all the DLL commands and parameter values

' Hello World! example.
' In the script above replace the section between dotted lines with this

braycmd = 20                        'Command to tell Bray which COM port to use
braystring = "COM1"                 'Assumes The Mule is connected to COM1
brayretstring = braymain(braycmd,braystring)

braycmd = 1
braystring = $DQ + "Hello World!{ret}" + $DQ
brayretstring = braymain(braycmd,braystring)

Top Home            © Lee Allen,2018