ananthasivanvk / BrotherPrinterSDK_Xamarin_iOSBinding

Xamarin.iOS Binding for BrotherPrinterSDK
5 stars 0 forks source link

How to print text to printer or replace text in an template on the printer xamarin.ios #1

Closed ghost closed 5 years ago

ghost commented 5 years ago

Good day Thank you for this wonderful sample. However how do you print to a p-touch label form this binding? Or how do I send a text to the printer there are no examples.

robr2112 commented 5 years ago

To send "raw data" to a printer via the SDK (which this binding wraps), you will use the "SendData" API.

You can "send data" using any printer command language your specific printer model supports, which may include ESC/P, ZPL, CPCL, Template Mode Commands, and/or others. Different printers support different command languages, so check online at Brother Solutions Center for the Command Reference Guides that are available for your specific model.

NOTE: When using "SendData" API, the BRPtouchPrintInfo class (i.e. "print settings") are NOT APPLICABLE. But, most of the remainder of this Xamarin sample that prints a PDF will be applicable. Just replace "printPDFAtPath" with "sendData" method with appropriate inputs.

I strongly recommend that you sign up for our FREE developer program here: https://developerprogram.brother-usa.com/

You can download the actual SDK and refer to the SDK documentation and samples. Writing code in C# for Xamarin will be similar to writing code in Obj-C or Swift (as the SDK samples demonstrate) with Xcode. And, we can provide you with one-on-one support if needed.

ghost commented 5 years ago

Thank you.

I can connect to the printer via and print an image no problem.

However, I am having trouble with the following.

I have saved a template to the QL820nwb printer which is saved as template 1.

it uses a 38X90MM tape.

All I want to do is send text "Name Surname" to the template to print.

I cannot sign up to the developer program because I am based in New zealand

robr2112 commented 5 years ago

OK. You can find the "P-touch Template Manual/ Command Reference" here: https://support.brother.com/g/b/manualtop.aspx?c=us&lang=en&prod=lpql820nwbeus

This should give you an idea for the data to send (with SendData API) to do what you want.

I don't support the QL printers, but if you contact SDKSupport from the Dev Program using the "Contact Us" option, someone should be able to help you if you need more assistance.

ghost commented 5 years ago

Thank you much appreciated.

ghost commented 5 years ago

Hello I am sending it the following string to replace a text on template but it is not working

"^II^TS001^ONText3^DIHello^FF"

Is there a way for me to test these commands outside of the app

Kind regards Divan

robr2112 commented 5 years ago

Hi Divan, Refer to the details in the command reference guide. It seems your command string may be missing null terminators and count bytes. Try this: "^II^TS001^ONText3\x00^DI\x05\x00Hello^FF"

If you are still having troubles, please reach out to our support team using the "Contact Us" button on the Developer Program website.

About a tool to use outside the app, if you are using Windows, I may (TBD) be able to provide a tool you can use. Contact me via support, not here. You must have Windows driver installed and file to send that contains your test data. Or, on iOS device, you can build and install the SDK Sample App with Xcode and use that to send a FILE that has your test data (using "Send Data" -> "Select" -> Send Data' option).

Regards, Rob

ghost commented 5 years ago

For anyone else wondering how to do this. Here is a sample that replaces data in a Ptouch template on the printer ql820nwb

You have to create a template with the p-touch editor and then upload it to the printer.

TS001 is template number1 on the printer and Text3 is the variable on the template.

x05 is the number of bytes of the new text in this case 5.

After connecting via Bluetooth.

        bool stCommunication = printer.StartCommunication();

        bool isReady = printer.IsPrinterReady();

        int printCode = 999;

       var firstName  = "Divan"

       byte[] byt2 = System.Text.Encoding.ASCII.GetBytes("^II^TS001^ONText3\x00^DI\x05\x00" 
       +firstName + "^FF");

        // convert the byte array to a Base64 string

        var strModified2 = Convert.ToBase64String(byt2);

        NSData s2 = new NSData(strModified2, 
        NSDataBase64DecodingOptions.IgnoreUnknownCharacters);

        printCode = printer.SendData(s2);
       printer.EndCommunication();
robr2112 commented 5 years ago

Hi Divan,

Great that you were able to get this working and thanks for sharing!

As a tip, it may be easier (and more efficient with memory) to generate the NSData object by using an "NSMutableData" object along with the "appendBytes:length" method. This way, you don't have to bother with encoding and decoding strings.

For example, using Obj-C syntax (untested, only for reference): NSMutableData *s2 = [[NSMutableData alloc] init]; [s2 appendBytes: "^II^TS001^ONText3\x00^DI\x05\x00" length: 23]; [s2 appendBytes: firstName length:firstName.length]; [s2 appendBytes: "^FF" length:3];

Just a thought! Otherwise, you got it!!

Best regards, Rob

ghost commented 5 years ago

Hi, Rob,

I'm running into another issue.

and wondering if you can assist me as you have been the only knowledge base on this issue.

how do I specify a count byte off more than 10 ex where x05 is the count bytes in the below string. I am trying to set it for the length of text of the users first name that they enter

But I cannot find it anywhere in the documentation

[s2 appendBytes: "^II^TS001^ONText3\x00^DI\x05\x00" length: 23];

Kind regards Divan

robr2112 commented 5 years ago

Hi Divan,

For reference, the command is "^DI n1 n2 data" The 2 BYTES n1 n2 express the byte count (of data) in reverse byte order. These are "hexadecimal" values, which is why you use "\x" to prefix them in your appendBytes string.

For example,

Hope this helps!

Rob

ghost commented 5 years ago

Thanks, Rob that clears it up thank you for all your help it has really helped me a lot with getting it working with a p-touch template on the ql820nwb printer.

Kind regards Divan