.NET MAUI API

As explained on the "Setup" page, the .NET MAUI binding must be implemented in both Xamarin.Android and Xamarin.iOS separately. This is because there are minor differences in the API's which are entirely documented below.

Android

The .NET MAUI API is nearly identical to the native Android SDK. Therefore, please reference the "API (Android)" documentation in the navigation menu to the left. The largest differences include:

  • Proper C# practices such as capitalizing the first letter of every API method.
  • Every "getter" method is instead treated as a property. Example: "printerDetails.PrinterName" instead of "printerDetails.getPrinterName()"
  • Should call async methods such as ConnectToDiscoveredPrinter and Print in another thread.

iOS

public BradySdk()

This is the constructor of the Xamarin and .NET MAUI iOS Bindgings. ALL of the API methods below will be called with this type. Example:

BradySdk theSdk = new BradySdk(); 
theSdk.StartBlePrinterDiscovery();

List<string> GetAvailablePrinterUpdates()

Returns a list of strings that represent every PrinterProperty that has changed since the last time this method was called. This allows the user to make something happen on the UI depending on what changed. This is most commonly used with the CurrentStatus property to check if there is a Warning or an Error on the printer. If there is, change the UI accordingly.

Example: Iterate through the returned list. If the item in the list is equal to "CurrentStatus", call theSdk.PrinterStatusMessage and display the value on the UI to show the printer's status.

void StartBlePrinterDiscovery()

Starts the Bluetooth Low Energy scan in the background to find all supported Brady Printers in your area. All device names get stored internally and are retrieved using the "Printers" property. You will passed one of these names into the ConnectToPrinter method to connect to the device.

void StartWifiPrinterDiscovery()

Finds all supported Brady Printers connected to the same Wifi as your mobile device. These devices get stored internally and are retrieved using the "Printers" property. You will passed one of these names into the ConnectToPrinter method to connect to the device. Most devices discovered over Wifi will include the string ".local." concatenated to the end of the printer's name.

void StopPrinterDiscovery()

Stops all discovery scans that are currently running in the background.

Dictionary<string, string> GetPrinters()

Returns a Dictionary where the keys are discovered printer names in the area and their values are the discovery protocol is was discovered by (Bluetooth or Wi-Fi).

async Task<bool> Connect(string printerSelected, bool connectWithBluetooth)

Used to connect to whichever printer whose name is passed in using a specified protocol (Bluetooth or Wi-Fi). This name and protocol are able to be retrieved from the "GetPrinters" method. It is encouraged to call this from another thread.

string LastConnectedPrinterName { get; }

Returns the printer name of the last printer that was successfully connected to. The printer's other information is stored internally and will only be cleared after a successful disconnect. Even when closing the application, this information will always be retrievable. This is used for automatic connection capabilities.

Automatic Connection Example:

- On app launch, start discovery
- Call the "GetPrinters" method to get a list of discovered printers
- You may need to wait or put this in a loop until the desired printer is discovered.
- Iterate through the list and compare each one to the LastConnectedPrinterName 
- If one matches, pass in the LastConnectedPrinterName to the **ConnectToPrinter** method to connect.

bool HaveOwnership { get; }

This method is only applicable when using an M211. Returns true if your mobile device has claimed ownership of the M211. This DOES NOT necessarily mean you are connected. The blue light on the printer should turn solid blue when you gain ownership regardless if you are connected or not. This light will stay solid blue only until the Disconnect method is called. Even when the app is closed and the printer disconnects, the light should stay solid blue.

async Task<bool> Disconnect()

Attempts to disconnect from a connected printer and releases ownership if the printer is an M211. Return a boolean representing the success or failure of the disconnect.

async Task<bool> DisconnectWithoutForget()

Disconnects from the current printer without forgetting it internally allowing future auto-connects. Calling this immediately before ForgetLastConnectedPrinter() will result in the same functionality as calling the normal "disconnect" method. Therefore, disconnectWithoutForget + forgetLastConnectedPrinter = disconnect.

void ForgetLastConnectedPrinter()

Forgets the printer that has been stored internally. This will always be the printer the user most previously connected to successfully. Therefore, calling this method will always result in the LastConnectedPrinter property returning null afterwards until another printer is successfully connected to.

async Task<bool> CutSupply()

Attempts to send a "cut" printer operation to the printer. This makes the printer cut any label that has recently been fed. A noise will be heard from the printer. Calling this will do nothing on an M611 because this operation is available directly on the M611's LED screen.

Only applicable on an M211 or M511

async Task<bool> FeedSupply()

Attempts to send a "feed" printer operation to the printer. This makes the printer feed exactly one label's worth in length. Calling this will do nothing on an M611 because this operation is available directly on the M611's LED screen.

Only applicable on an M211 or M511

string PrinterStatus { get; }

Returns the PrinterStatus enumeration that describes the state of the printer's connection.

string PrinterStatusMessage { get; }

Returns a String that represents the body of a printer error message.

string PrinterStatusMessageTitle { get; }

Returns a String that represents the title of the printer error.

string PrinterStatusRemedyExplanationMessage { get; }

Returns a String that represents the remedy to a printer error.

string PrinterName { get; }

Returns a String that represents the name of the connected printer.

string PrinterModel { get; }

Returns a String that represents the model of the connected printer.

string ConnectionType { get; }

Returns the ConnectionType enumeration that describes how we are connected to the printer.

int BatteryLevelPercentage { get; }

Returns an Integer that represents roughly the battery life percentage of the printer.

bool isAcConnected { get; }

Returns a Boolean that represents whether this printer is plugged into an outlet and on AC power.

string SupplyName { get; }

Returns a String that represents the full name of the part loaded in the connected printer.

string SupplyRemainingPercentage { get; }

Returns an Integer that represents the percentage of remaining supply in the connected printer.

string SupplyDimensions { get; }

Returns a String that represents the supply dimensions in inches (width and height).

double SupplyWidth { get; }

Returns a Double that represents the Width in inches of the supply installed in the printer

double SupplyHeight { get; }

Returns a Double that represents the Height in inches of the supply installed in the printer.

int SupplyColor { get; }

Returns an int that represents the color of the supply installed in the connected printer.

bool IsSupplyPreSized { get; }

Returns a Boolean that represents if the installed part in the connected printer is a pre-sized part. If false, the part could be continuous or another part not categorized as die-cut

bool suppliesMatch { get; }

Compares the part in the connected printer to the part used to create the template. Returns true if the parts match, false if they are different. If a Template has not been set, this property will return false as well.

string YNumber { get; }

Returns a string representing the installed supply's unique Y Number.

string RibbonName { get; }

Returns a string representing the name of the installed ribbon. Will always return an empty string for printers that are not applicable (M211 and M511).

int RibbonRemainingPercentage { get; }

Returns an int representing the percentage of ribbon remaining inside the connected printer.

int RibbonColor { get; }

Returns an int representing the color of the ribbon installed in the connected printer.

string TemplateSupplyName { get; }

Returns a string that represents information about the part that was selected when designing the current template.

void SetTemplateWithFilePath(string filePath)

Sets a BWT file or bitmap as the current item to print. This string must be a valid path to a MAUI Asset in order to be successful. To successfully set a valid BWT template, it must be embedded inside the MAUI Resource>>Raw folder and the Build Action must be set to "MauiAsset".

void SetTemplateWithBase64(string value, bool isTemplate)

Sets a BWT file or bitmap as the current item to print. The "value" parameter must be a Base64 string of an image or BWT file (see example below). The "isTemplate" parameter specifies if the passed-in Base64 string is derived from a template or an image file (.png, .jpg. etc.).

string path = @"my_template.BWT";
byte[] byteData = File.ReadAllBytes(path);
string base64 = Convert.ToBase64String(byteData);
theSdk.Template = base64;

Dictionary<string, string> GetTemplateDataNames()

Returns a Dictionary where the keys represent the object names on the currently set template and where the values represent the type of object they are.

void SetPlaceholderValue(string placeholderName, string placeholderValue)

Sets a value to the desired placeholder of the current template. You may find the names of all valid placeholders by using the "TemplateDataNames" property.

string GetPreview(int elementSize)

Retrieves a print preview image in the form of a base64 string. Must pass-in the desired image size.

async Task<bool> Print(int copies, bool cutAfterEachLabel, bool isCollated, bool printTrailer)

Attempts to print the previous template or bitmap that was set using the "Template" property. Returns a boolean representing the success or failure of the print. Please reference the "PrintingOptions.swift" page for further documentation about copies, cutAfterEachLabel, isCollated, and printTrailer.

async Task<bool> Print(double bitmapWidth, double labelLength, int copies, bool cutAfterEachLabel, bool isCollated, bool printTrailer)

Attempts to print the previous bitmap that was set using the "Template" property. Returns a boolean representing the success or failure of the print. Please reference the "PrintingOptions.swift" page for further documentation about copies, cutAfterEachLabel, isCollated, and printTrailer.

bitmapWidth - The width in inches of the bitmap once it prints out.

labelLength - The length in inches of the label once it prints out. Currently, M611 continuous parts have a length of 0.5 inches before being overrided according to the information we receive from the printer. The width in inches will always be stated of the physical part.