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.

BradySdk (constructor)


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.

.showDiscoveredBleDevices

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

isConnected(): boolean

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

.getConnectionErrorMessage

getConnectionErrorMessage(): string

getConnectionErrorMessage retrieves the error message of the previously attempted connection in the session. In the future, we plan to change showDiscoveredBleDevices to a throwable function so that exceptions can be caught from the web app. However, this would introduce a breaking change to the API. Therefore, we have introduced this method to allow the retrieval of the connection failure message so that users can key off specific errors to change their UIs behavior if showDiscoveredBleDevices returns "false".

  • Returns a string representing the reason for the previous failed connection. Will return an empty string if the only connections in the session have been successful.

.isSupportedBrowser

async isSupportedBrowser(): Promise<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.

.feed

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.

.cut

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.

.setAutomaticShutdownTime

async setAutomaticShutdownTime(minutes: number): Promise<boolean>

setAutomaticShutdownTime is only functional when connected to an M211, M511, or inkjet printer. This will set the setting on the printer that control when it automatically shuts off. This timer will only begin when no devices are connected to the printer. The printers should never turn off automatically when in use.

  • Returns a boolean representing the success of the opration.

.cleanPrinthead

async cleanPrinthead(): Promise<boolean>

cleanPrinthead is only functional on inkjet printers. Send a command to the printer to make it clean the printhead. The printer will notify the SDK via the isCleanPrintheadMaintenanceRecommended property if this printer operation is suggested to be called. If this property is "true", colors may appear faded with streaks or simply inaccurate. If you see this behavior, it most-likely means the ink has started to dry out. It is recommended to call printTestLabel afterwards to confirm this fixed the color issue.

  • Returns a boolean representing if the command successfully sent to the printer.

.printTestLabel

async printTestLabel(): Promise<boolean>

printTestLabel is only functional on inkjet printers. Sending this command simply prints out the test label that is preinstalled on the print. This label is meant to show a range of colors so the user can verify that all colors are accurate and the ink is sufficient.

  • Returns a boolean representing if the command successfully sends and the operation is completed.

.setMaintenanceStationProperty

async setMaintenanceStationProperty(stationReset: MaintenanceStation): Promise<boolean>

setMaintenanceStationProperty is only functional on inkjet printers. The printer will notify the SDK via the "message", "messageTitle", and "messageRemedy" that the maintenance station needs to be replaced. If this is the case, users may call this method and pass in "MaintenanceStation.Reset" to tell the printer you've successfully replaced the maintenance station physically. This will resolve the printer error. Users may also pass in "MaintenanceStation.RemindMeLater" to dismiss the printer error and to be notified at a later date. From a UI point of view, this two options could be handled via a pop-up window with a "Ask Me Later" and a "Done" button for example.

  • Returns a boolean representing the success of the setting being changed on the printer

.printAlignmentLabel

async printAlignmentLabel(): Promise<boolean>

printAlignmentLabel is only functional on inkjet printers. This command can be sent to the printer to print out the premade alignment label. Once printed out, this label provides a visual to help the user callibrate the alignment of the printer. This should be used if the user notices inaccuracies when printing fine lines such as photographs. The actual callibration process can be completed using the setAlignmentOffset method documented below.

  • Returns a boolean representing the success of the printer operation.

.setAlignmentOffset

async setAlignmentOffset(offset: number): Promise<boolean>

setAlignmentOffset is only functional on inkjet printers. It controls the callibration of the printer alignment. The number that should be passed in as a parameter must be between -7 and 7 and should match wherever the pink line is most solid after observing the print-out that printAlignmentLabel produced.

Example: If the user called printAlignentLabel and the physical label shows a pink line that is the most solid at -4 on the chart, then the number -4 should be passed into this setAlignmentOffset method

  • Returns a boolean representing the success of the setting being changed on the printer

.setPrinterQualityMode

setPrintQualityMode(qualityMode: PrintMode | null | undefined): void

setPrintQualityMode sets the quality mode of all future print jobs. These different modes show clear differences in the sharpness and saturation of colored printing. Users may use the availablePrintQualityModes property to retrieve all available options to use for this parameter. Passing in "null" or "undefined" will use the PrintMode.Default setting.

.printBitmap & .printBitmaps

async printBitmap(bitmap: HTMLImageElement, xOffset: number = 0, yOffset: number = 0, rfidOperations: RfidOperation[][] = []): Promise<boolean>

async printBitmaps(bitmaps: HTMLImageElement[], xOffset: number = 0, yOffset: number = 0, rfidOperations: RfidOperation[][] = []): Promise<boolean>

printBitmap(s) prints the HTML Image Element(s) that it's handed. The image(s) always maintain the original aspect ratio and will be resized to fill the dimension of the first printable zone of the installed supply in the connected printer.

The parameters xOffset and yOffset are optional values to manually shift the image on the printed out label (in inches). These parameters will default to 0. It is encouraged to only used these optional parameters if the printed out label does not meet your standards.

The RfidOperation parameter is optional and will only be functional while connected to an i7500 that supports RFID encoding. An example of how to initialize this parameter is included below.

  • Example: The code below will encode 1AAAAAAAAAA to the first label, 2BBBBBBBBBB to the second label, and 3CCCCCCCCCC to the third label along with their respective images:
    const rfidOperations = [
        [
            new RfidOperation(RfidCommandType.Write, RfidInputType.Ascii, RfidLocation.ElectronicProductCode, "1AAAAAAAAAA", null, 0, null, null),
            new RfidOperation(RfidCommandType.Write, RfidInputType.Hex, RfidLocation.User, "AAAAAAAAAA", null, 0, null, null)
        ],
        [
            new RfidOperation(RfidCommandType.Write, RfidInputType.Ascii, RfidLocation.ElectronicProductCode, "2BBBBBBBBBB", null, 0, null, null),
            new RfidOperation(RfidCommandType.Write, RfidInputType.Hex, RfidLocation.User, "BBBBBBBBBB", null, 0, null, null)
        ],
        [
            new RfidOperation(RfidCommandType.Write, RfidInputType.Ascii, RfidLocation.ElectronicProductCode, "3CCCCCCCCCC", null, 0, null, null),
            new RfidOperation(RfidCommandType.Write, RfidInputType.Hex, RfidLocation.User, "CCCCCCCCCC", null, 0, null, null)
        ]
    ];
    
    const printingStatus = await bradySdk.printBitmaps(imagesToPrint, 0, 0, rfidOperations)
    

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.

.disconnect

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.

.setCopies

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.

.setCollate

setCollate(collateValue: boolean): void

setCollate will control the order in which the labels are printed in the next print job. If the next print job is set to include 2 copies of image "A" and image "B" and collation is "true", the labels will be printed in the order of A, B, A, B. If collation is "false", the labels will be printed in the order of A, A, B, B.

.setCutOption

setCutOption(number): void

setCutOption allows you to specify the cut option for your print job.


EndOfJob = 0 - the printer will only cut at the end of the print job (default cut option)

EndOfLabel = 1 - if your print job consists of multiple copies, this will cut in between each copy

Never = 2 - the printer will never cut your printed label and must be done manually

CutAfterRow = 3 - the printer will cut your printed label only after the amount of rows specified

UsePrinterSettings = 4 - the printer will resort to using the cut option set on the printer


.setCutAfterRowValue

setCutAfterRowValue(cutAfterRowValue: number): void

setCutAfterRowValue allows you to specify how many labels to print before a cut action is performed. For example, "setCutAfterRowValue(2)" will tell the printer to cut after every 2 labels. This option is only supported on the M611, S3700, and i7500. Print will not be successful when used with an unsupported printer.

.setSupplyDatabase

setSupplyDatabase(supplyDatabaseFile: File) : void

supplyDatabaseFile allows you to specify a new Supply Database file to override the embedded one. This may be used in cases where the printed out image is not fully on the printable area of the label or if the image is sized incorrectly.

.parsePdfToImages

parsePdfToImages(file: File) : HTMLImageElement[]

file a file object of a PDF file.

  • Returns an array of HTMLImageElements whose items represent each page of the PDF file as an image that will print on its own label.

Printer Properties of BradySdk


All instance variables will be null of undefined until a successful connection to a printer has been made. Not all properties of BradySdk apply to every printer model and may still be undefined after connection. We have tried to specify all these cases below.

  • status: the current status of the connected printer.
  • printerName: the name of the connected printer.
  • printerModel: the model of the connected printer
  • supplyName: the name of the connected printer's supply part.
  • supplyYNumber: the Y Number of the current part installed in the connected printer.
  • supplyWidth: the width of the current supply installed in the connected printer.
  • supplyHeight: the height of the current supply installed in the connected printer.
  • supplyDimensions: the width and height of the installed part in inches.
  • supplyIsPreprinted: if there is a preprinted graphic on the label.
  • supplyIsDirectThermal: Is the supply installed in the connected printer direct thermal or not.
  • supplyIsRfid: true if the installed supply includes RFID encodable chips within each label.
  • supplyRemainingPercentage: the percentage remaining of the connected printer's supply.
  • ribbonRemainingPercent: the percentage remaining of the connected printer's ribbon if there is one.
  • inkRemainingPercentage: the percentage remaining of the connected printer's ink supply if it's an inkjet printer.
  • outOfInkCmy: indicates if an inkjet printer is out of ink.
  • isCleanPrintheadMaintenanceRecommended: true if an inkjet printer is recommending its printhead to be cleaned. Otherwise, false.
  • cleanPrintheadSuccessful: true if the cleanPrinthead printer operation was successful. Otherwise, false.
  • alignmentOffset: represents the current alignment offset of the connected inkjet printer. This can help with calibration when using setAlignmentOffset.
  • availablePrintQualityModes: a list of all possible print quality modes that are available to be set on the connected inkjet printer.
  • printerQualityMode: the print quality mode currently selected for print jobs (inkjet printers only). Defaults to PrintMode.Default and can be changed with setPrinterQualityMode.
  • validInkSupply: true if the installed ink cartridge is valid. Otherwise, false. Will also be false if the connected printer is not an inkjet printer.
  • printheadInstalled: true if there is a printhead installed. Otherwise, false. Will also be false if the connected printer is not an inkjet printer.
  • maintenanceStationWarningAway: represents if the warning to replace the maintenance station is active or inactive (inkjet printers only).
  • maintenanceStationErrorAway: represents if the error to replace the maintenance station is active or inactive (inkjet printers only).
  • postPrintAccessoryType: The hardware accessory installed on the printer for post-printing actions (i7500 only).
  • dotsPerInch: The dots per inch capabilities of the connected printer.
  • mediaIsDieCut: indicates whether the installed supply is die-cut or continuous.
  • rotation: where on the label your image will be printed.
  • orientation: the orientation of the part (Landscape or Portrait).
  • leftOffset: the horizontal offset of the installed supply to help center the image being printed.
  • verticalOffset: the vertical offset of the installed supply to help center the image being printed.
  • zoneDimensions: 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: the percentage of battery left in the connected printer.
  • isAcConnected: if the connected printer is plugged into an AC power source.
  • firmwareVersionNumber: the firmware version number of the connected printer.
  • autoShutoffTimeInMinutes: the time in minutes that it takes the connected printer to shut off automatically (M211 & M511 only).
  • message: the message body of a printer error.
  • messageTitle: the message title of a printer error.
  • messageRemedy: the remedy explanation of a printer error.
  • printOptions: object containing the values for cutOption, copies, and collate
  • mostRecentUpdates: a list of variables that 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
  • isSupplyValid: the validity of the installed supply in the connected printer
  • isRibbonValid: the validity of the installed ribbon in the connected printer
  • bluetoothVersionNumber: the bluetooth version number of the printer. This will always be an empty string on the M211, M511, M610, and M710.
  • wifiVersionNumber: the Wi-Fi version number of the printer. This will always be an empty string on the M211, M511, M610, and M710.
  • labelLibraryVersionNumber: the version number of the YB file installed on the connected printer's firmware. This will always be an empty string on the M211, M511, M610, and M710.
  • errorSeverity: if there is a current error on the connected printer, this will represent the severity level of the error (example: Error, Warning, Info, etc.)
  • isRfidSupportedPrinter: true if the connected printer is an i7500 with RFID encoding support. Otherwise, false.