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
.
.
 
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

Google
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?
lll

Visual Basic.NET

This code is not backwards compatible with Visual Basic v.6 or earlier. Code for those versions can be found here

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. If not you may have to prepend the path to the dll filename.

This example shows an easy way to call the braymain function in the Bray DLL using Visual Basic running under the Microsoft.NET Framework.

With VB.NET we use a 'wrapper' function to isolate the unmanaged DLL data operations. This allows us to bring the data returned from the DLL back into the managed area controlled by the .NET framework as a regular VB string type. It also allows us to use regular VB string and integer types as parameters to the braymain function. In this way the braymain wrapper function can be called just like any other Visual Basic function. All the unmanaged code operations are hidden away.

Here are the steps necessary to create a simple program demonstrating the calling of the mulebray DLL using the Microsoft Visual Basic IDE.

  1. Select File: New project: Windows Application: Give it the name 'mulebraytest': Click OK
  2. From the toolbox drag a button onto the form.
  3. Click the button to open up the code window.
  4. From the box below copy the section of code between the dotted lines and paste it into the VB form you just created.
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    '----------------------------------------------------------
        Dim braycmd As Integer
        Dim braystring As String
        Dim brayretstring As String

        braycmd = 0 'Zero command returns the DLL version number
        braystring = "" 'The zero command does not need a string parameter

        'The braymain function we call here is a wrapper around
        'the "real" braymain function within the DLL.
        brayretstring = braymain(braycmd, braystring)
        MsgBox(brayretstring)
    '------------------------------------------------------------
    End Sub
End Class

Next we add a module containing the braymain wrapper which in turn communicates directly with the mulebray.dll.

  1. Add a module to the project- call it Bray_Module (Project -> Add Module -> Module -> Bray_Module.vb)
  2. From the box below copy the section of code between the dotted lines and paste it into the module you just created.

Run the code and click the button. A zero value command is sent to mulebray.dll and it returns the current version number which is displayed in a message box.


Module Bray_Module
    '----------------------------------------
    Public Declare Ansi Function braymaindll Lib "mulebray.dll" _
    Alias "braymain" (ByVal braycmd As Integer, _
    ByVal braystring As String) As String

    Public Function braymain(ByRef braycmd As Integer, _
    ByRef braystring As String) As String
        braymain = braymaindll(braycmd, braystring)
    End Function
    '----------------------------------------
End Module

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). Just change value of braycmd and give a string value to braystring when necessary.

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 create a string constant containing a double quote character then use 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.

Further Bray DLL Examples

Table of all the DLL commands and parameter values


Const DQ = Chr(34)      'define a double quote charater as a string constant

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				   'parse and execute Bray
braystring = DQ & "Hello World!{ret}" & DQ  'line of bray surrounded by dquotes 
brayretstring = braymain(braycmd,braystring)
   
.
.
Top Home            © Lee Allen,2018