Home Page The Mule™ Bray Examples 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

"To talk to a Mule you have to Bray..."

Further Bray DLL examples

The examples on this page build on the 'Hello World' example covered in the Popular Language Examples pages.

Before progressing to these examples you should understand the basics for the specific programming language you will be using.

Each programming language has different ways of calling the DLL and other issues to overcome. These are covered in the specific language example pages. Here are the links:


Pseudo Code

The examples on this page are algorithms written in a pseudo code which you will have to translate to the particular programming language you are using.

The code does not take account of any particular language syntax issues - these have already been covered in the earlier examples. Our Pseudo Code has these characteristics.

  • String literals are enclosed in double-quotes.
  • Double-quote or Single-quote characters can be included in a string literal by escaping with a backslash.
  • We use # for a comment character
  • Our pseudo code does not need to terminate line endings.
  • Our pseudo code has no formal syntax. Things get made up and changed around as needed to make thing clearer.

A better 'Hello World!'

The 'Hello World!' example given earlier was very rudimentary. In particular it did not deal with the issue of reopening an already open COM port. If it was run more than once a COM port error may have been reported.

All Bray applications should have 3 stages...

  1. Initialisation
  2. Execute the Bray Script
  3. Close down

Here is an improved 'Hello World!" program with the three stages implimented. It also illustrates a technique of defining the braycmd parameters as constants in order to enhance program self documentation and readability by avoiding the use of 'magic numbers'.


constant getId       =  0
constant doBrayLine  =  1   
constant getAstream  =  2   
constant getEstream  =  3   
constant getCstream  =  4   
constant getSstream  =  5   
constant putAstream  =  6   
constant putEstream  =  7   
constant putCstream  =  8   
constant putSstream  =  9   
constant initBray    = 10  
constant endBray     = 11  
constant getErrCount = 12  
constant useCom      = 20  

retstring  = braymain(useCom,"COM1")  	 	 # tell Bray to use COM 1
retstring  = braymain(initBray,"")	 	 # initialise Bray
braystring = "\"Hello World!{ret}\""	 	 # line of bray to send 
retstring  = braymain(doBrayLine,braystring) 	 # dispatch line of Bray	
retstring  = braymain(endBray,"")	 	 # close down Bray

You may notice in this program we ignored the strings returned from the braymain function. Many commands always return "OK" but the useCom command may have returned an error report so why was it not checked? The answer is that this command only returns an error if the function cannot understand the COM number (a syntax error). It never returns any information about the port opening process. Because the COM name was hard coded we know it will always be correct. If the COM port name came direct from user input then it would be prudent to check. Alternatively your program could verify the syntax before passing to braymain.

Unlike many other programming languages the COM command does not open the port- it just tells Bray which port to open should it need to send data later in the run. The command can be called anywhere in the program provided it is called before output to channel 0 is needed. A flow chart showing the way Bray handles the com port is provided in the DLL documentation.


Handling a Users Bray Script File

Your application will often be little more than providing a means where users can just run their own Bray Scripts. This example outlines how this can be done.

Notice how virtually all the issues are handled internally by Bray. You only need to intervene when handling events beyond the scope of Bray. For example opening the Bray Script File.

# Outline example of an application to run a Users Bray Script from file.

constant getId       =  0
constant doBrayLine  =  1   
constant getAstream  =  2   
constant getEstream  =  3   
constant getCstream  =  4   
constant getSstream  =  5   
constant putAstream  =  6   
constant putEstream  =  7   
constant putCstream  =  8   
constant putSstream  =  9   
constant initBray    = 10  
constant endBray     = 11  
constant getErrCount = 12  
constant useCom      = 20  


# The User can be provided a means of selecting the COM port through the
# GUI for example Radio Buttons or Combo Box. Alternatively the choice
# of COM port can written into the Bray Script using the PORT command

If user has selected a COM port to use
	Verify the User input is correctly formed and send to Bray...
	brayretstring = braymain(useCom,"user-selected-comport")
	if brayretstring != "OK"		#check for error 
		MessageBox brayretstring	# Show the error	
		Program End.

User selects file and clicks ok

Open file
if open fails...
	prompt user with a message box
 	Program End.

retstring = braymain(initBray,"")	 	 # initialise Bray

#Loop through all lines in the file
Do Loop
    read line from file into braystring
    trim surrounding white space
    check braystring does not exceed 511 characters
    retstring = braymain(doBrayLine,braystring)  # dispatch line of Bray	
    
    gosub displaystreams
	
    #test if a Bray Script syntax error occurred
    errorcount=braymain(getErrCount,"")
    convert errorcount from string to a number
    if errorcount > 0 
    		# You can optionally send a commentary message to the user
    		# here saying the script is being terminated. However this
    		# is often unnecessary because the stream messages will
    		# already have made this apparent
    		message="Script is terminated because of error"
		brayretstring=braymain(putCstream,message)    		
    		Exit Loop
    		
Loop until end of Bray Script File

Close Bray Script file
retstring = braymain(endBray,"")	 	 # close down Bray
Program End


subroutine displaystreams	
    #The Monitor Window refers to a means of displaying information
    # to the User. You could for example use a list box
    # the code displays ALL four streams even though content may be
    # null if disabled by the Bray Script SWITCH command.
	
    Astream=braymain(getAstream,"")
    display Action Stream in Monitor Window
	
    Estream=braymain(getEstream,"")
    display Error Stream in Monitor Window
	
    Cstream=braymain(getCstream,"")
    display Commentary Stream in Monitor Window
	
    Sstream=braymain(getSstream,"")
    display Source Stream in Monitor Window	
subroutine end


Advanced Techniques

Using the Bray DLL with suitably written code it is possible to...

  • Lock out selected Bray Script commands
  • Modify the behaviour of Bray Script commands
  • Add new User commands to Bray Script

In outline the method to achieve these is to intercept the Bray line when it has just been read from the Bray Script file and inspect it for the feature you want to change.

If the feature is not found pass the line on to Bray for normal processing. Otherwise handle the line outside Bray. Parse the line, create the appropriate data streams and inject them into Bray using the putStreams commands.

.
.
Top Home            © Lee Allen,2018