Xamarin API
As explained on the "Setup" page, the Xamarin 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 Xamarin 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> AvailablePrinterUpdates { get; }
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.
List<string> Printers { get; }
Returns a list of strings representing the names of all Brady Printers that were discovered from the discovery scans.
async Task<bool> ConnectToPrinter(string printerSelected)
Used to connect to whichever printer whose name is passed in. This name is able to be retrieved from the "Printers" property. 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 "Printers" property 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> Cut()
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> Feed()
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 PrinterDetailsString { get; }
Returns a custom string of the vital PrinterDetails that a user may need to know about the currently connected printer. This essentially combines the properties documented below into a single string.
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.
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 CheckForPartMismatch { 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 Template { set; }
Sets a BWT file or bitmap as the current item to print. This must be a base64 string because the bridge from C# to the native iOS language cannot pass custom objects back and forth. To successfully set a valid BWT template, it must be embedded inside the Xamarin.iOS project and the Build Action must be set to "BundleResource". See example below to convert this file to a base64 string.
string path = @"flutter_barcode_test.BWT";
byte[] byteData = File.ReadAllBytes(path);
string base64 = Convert.ToBase64String(byteData);
theSdk.Template = base64;
NOTE: If the template is unable to be deserealized from the base64 string, the SDK will assume you are attempting to print a bitmap. Therefore, if you want to print a bitmap, you can convert a UIImage type into a base64 string and set it to this property and then call the "Print" method.
List<string> TemplateDataNames { get; }
Returns a list of strings that represent each entity's name in the template. If a user does not have a Windows machine, this property makes it easy to see which fields to set a placeholder value on. Alternatively, for users with access to a Windows machine, you may download Brady Workstation and open the BWT template. Simply click any object in the template to see what that object's name is set to.
string TemplatePartInfo { get; }
Returns a string that represents information about the part that was selected when designing the current template.
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 GetPreviewBase64String(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.