The Brady Web SDK API

All API methods below are members of the BradySdk class. This is the only class in the SDK that should be used.

new BradySdk(callback: function, collectAnalytics?: bool)

The constructor of the BradySdk class should be initialized immediately when the user's web page has loaded. All functionality depends on this single object.

  • A function must be passed into this constructor that will trigger whenever there is an update in the back-end's BradySdk view model. A user can simply update the UI accordingly whenever this method is triggered. An example can be seen in the "printerUpdatesCallback" method used in the example on https://sdk.bradyid.com/web_sdk_setup/.

  • Additionally, the BradySdk class accepts an optional boolean argument. If no value is passed in, analytics related to print jobs will be collected by default to assist Brady developers in continuing to improve the SDK. If 'false' is passed in, no analytics will be collected. Passing in 'true' is redundant since analytics are collected by default.

async showDiscoveredBleDevices(string): string

showDiscoveredBleDevices opens the embedded Bluetooth discovery window that comes with the Web Bluetooth API. If a user selects a device in this window and clicks the "pair" button, it will attempt to connect to the device.

  • Takes a string that represents the ID that should be used to gain ownership of an M211. When using an M611, null can be used.
  • If the connection fails or the user clicks outside of the pop-up window before the connection is finished, this method will return null.
  • If the connection is successful, this method will return a unique ID that can be used in the future to reconnect to the same device.

NOTE: The Web SDK test app saves the returned ID in localStorage in order to connect to an M211/M610 across separate refreshes of web pages. This ID is required by the M211/M610 if the Bluetooth light on the printer is solid blue. If this ID is not saved, the power button can be held for 5 seconds to release ownership before every connection on the M211 or manually forgotten on the M610.

isConnected(): boolean

isConnected will return a boolean representing if any device is connected to the Web SDK at the time of its call.

isSupportedBrowser(): boolean

isSupportedBrowser indicates whether the browser being used to run your app is supported by the Web Bluetooth API. Example browsers that support the API include Google Chrome, Microsoft Edge, and Bluefy (on iOS).

  • Returns a boolean representing whether the browser running your app is supported by the Web Bluetooth API.

async feed(): boolean

feed is only functional when connected to an M211 or M511. This will tell the printer to print exactly one blank label.

  • Returns a boolean representing the success of the operation.

async cut(): boolean

cut is only functional when connected to an M211 or M511. This will tell the printer to perform a cut operation.

  • Returns a boolean representing the success of the operation.

async printBitmap(img): boolean

printBitmap prints the HTML img tag that it's handed. The image always maintains its aspect ratio and will be resized to fill the dimension of the labels that are installed in the printer that is connected.

For users that have difficulties passing in an img object, refer to the code block titled "CODE TO SELECT AND DISPLAY IMAGE TO PRINT" in the example at: https://sdk.bradyid.com/web_sdk_setup/.

  • Returns a boolean representing the success of the print operation. This will return false if there is no printer connected.

async disconnect(): boolean

disconnect severs the current connection to the Bluetooth GATT. This will also clear the "ownershipID" field in localStorage.

  • Returns a boolean representing the success of the disconnection.

async setCopies(number): void

setCopies allows you to specify the number of copies of the image you want to print. The default number of copies for each print job is 1.

async setCutOption(number): void

setCutOption allows you to specify the cut option for your print job. The options are: - EndOfJob - the printer will only cut at the end of the print job (enabled when argument passed in is 0 - this is the default cut option for all print jobs) - EndOfLabel - if your print job consists of multiple copies, this will cut in between each copy (enabled when argument passed in is 1) - Never - the printer will never cut your printed label and must be done manually (enabled when argument passed in is 2)

Instance variables of BradySdk

  • status: property representing the current status of the connected printer.
  • printerName: property representing the name of the connected printer.
  • printerModel: property representing the model of the connected printer (currently M211, M511, or M611)
  • supplyName: property representing the name of the connected printer's supply part.
  • supplyDimensions: property representing the width and height of the installed part in inches
  • supplyRemainingPercentage: property representing the percentage remaining of the connected printer's supply.
  • substrateYNumber: property representing the Y Number of the current part installed in the connected printer.
  • substrateWidth: property representing the width of the current supply installed in the connected printer.
  • substrateHeight: property representing the height of the current supply installed in the connected printer.
  • mediaIsDieCut: property indicating whether the installed supply is die-cut or continuous.
  • rotation: property indicating where on the label your image will be printed
  • orientation: property representing the orientation of the part (Landscape or Portrait)
  • leftOffset: property representing the horizontal offset of the installed supply to help center the image being printed
  • verticalOffset: property representing the vertical offset of the installed supply to help center the image being printed
  • zoneDimensions: property representing the width and height of the first printable zone on the installed part; this is necessary to have as installed parts can have a number of printable zones that may differ from the default width and height
  • batteryLevelPercentage: property representing the percentage of battery left in the connected printer.
  • isAcConnected: property representing if the connected printer is plugged into an AC power source.
  • firmwareVersion: property representing the firmware version number of the connected printer.
  • autoShutoffTimeInMinutes: property representing the time in minutes that it takes the connected printer to shut off automatically.
  • message: property representing the message body of a printer error.
  • messageTitle: property representing the message title of a printer error.
  • messageRemedy: property representing the remedy explanation of a printer error.
  • printOptions: object containing the values for cutOption, copies, and collate (only applicable for M511 print jobs)
  • mostRecentUpdates: property representing which of these variables may have been changed (for example, if you changed the part in your printer or if the battery level percentage of your printer has changed); passed in as an argument to printerUpdatesCallback