2

I am developing a C# application of POS system in Visual Studio 2012 RC. I have to print the sales on label printer using

Brothers P-Touch QL-500 Label printer.

WHAT I HAVE DONE ALREADY.

  • I have installed latest b-pac SDK 3.0
  • Successfully add reference to my C# application.
  • For creating label templates i have installed latest version of p-touch Editor 5.0.
  • Made one template (Mylabel.lbl).

    But before that.

I run some of the built in Examples but those examples Throws an Exception. After doing alot of search on Google I found that this is the printer's driver Problem.

i can't install the driver because Driver's installation requires a printer to be connected. I DON'T HAVE THE PRINTER.

WHAT I NEED TO DO

  • Do you have any idea that how can i do this task.
  • what is the right way of printing a label using Brothers P-Touch QL-500 Label printer.

    Please Help me I have done alot of time on searching. stackoverflow is my last hope. I am new to such label printing. Please help i will be greatly thankful.

The ruff example Code i am using.

bpac.DocumentClass doc = new DocumentClass();
if (doc.Open("templateFile.lbx"))
{
    doc.GetObject("field1").Text = "...";
    doc.GetObject("field2").Text = "...";

    doc.StartPrint("", PrintOptionConstants.bpoDefault);
    doc.PrintOut(1, PrintOptionConstants.bpoDefault);
    doc.EndPrint();
    doc.Close();
}

This is the example code which i am trying. the very first line throws an exception

bpac.DocumentClass doc = new DocumentClass();

I am Also attaching a Exception Screen Preview.

Thrown Exception Screen Preview

Khizar Ali
  • 486
  • 2
  • 12
  • 26

6 Answers6

8

I had the exact same error message when the exception occurred. The solution for me was to set the "Platform target" to "X86" CPU. This can be done via: (menu) Project -> Properties -> (tab) Build -> Platform target "x86" Instead of "Any CPU"

I have developed the software on Windows 7 64 bit.

You can find more info about this in the b-PAC SDK documentation. C:\Program Files (x86)\Brother bPAC3 SDK\Doc\bPAC30_eng.chm In the section "Troubleshooting" you will find: "The program does not operate on a 64-bit operating system. Change the platform to "x86", and then recompile it."

This solution is tested with the QL560 hardware connected to my PC and it worked.

3

Here is some code I have used to print using this object.

            string strPrinterAddress = "domain\machinename";
            objDoc = new BrssCom.Document();
            string strPath = "192.168.1.45" + " /D" + strPrinterAddress;
            if (objDoc.Open(strPath))
            {
                objDoc.SetText(0, "Recycle: " + recycleReason);

                objDoc.SetText(1, "Other Text");
                objDoc.SetBarcodeData(0, "1234");
                objDoc.DoPrint(BrssCom.PrintOptionConstants.bpoAutoCut, "0");
            }

However, @JamieMeyer is right. You cannot, absolutely can NOT be sure this will work without having a printer to test with. In my example, I'm using a very simple label with 3 fields, one of them being a barcode. It's not a simple matter of using named variables, it really depends on the order the fields were added, etc.

I didn't have a printer myself, and it took about 2 weeks of me sending code updates at night, and then the customer testing the next day, round and round, to get the look and feel just right. If I had it to do all over again, I would have purchased a printer myself.

Good luck, but you are shooting in the dark without a printer.

Matt Dawdy
  • 19,247
  • 18
  • 66
  • 91
  • 1
    Agreed. I built a similar system a few years ago that used bar code scanners and Dymo labelmaker printers. You NEED the hardware. You have to have it. If you don't have it, get it. I had to buy the bar code scanners myself, yes. Sometimes you have to grab the bull by the horns to get the job done. – GrayFox374 Jun 23 '12 at 02:55
  • **Thanks Matt** I'm agreed too. you people are suggesting me the right thing. and yes i am going to shoot in the dark. No hardware that is my problem. i can't buy it in my country right now. But still i am motivated to work on this task without hardware. Any additional help you can provide me. Please consider my problem and situation i am facing i can't have a hardware. but i have to implement. ANY HELPING MATERIAL. I just want to write the code and set assemblies right. then what ever the consequences i will manage. BIG THANKS AGAIN. – Khizar Ali Jun 23 '12 at 20:02
  • I need to know that the exception thrown in my code is this really related to the hardware component or driver not installed problem. – Khizar Ali Jun 23 '12 at 20:04
  • I don't know the answer to that. Can you send a test project to someone who has a printer installed and see if it prints out? – Matt Dawdy Jun 24 '12 at 02:41
1

How do you intend to verify the results of your coding without the physical unit?? Brother does not offer any sort of visual emulator, so your best bet is to get the unit. These can be had for $75 street price, and likely on the shelf at your local office supply store. http://www.officedepot.com/a/products/506232/Brother-P-Touch-QL-500-PC/

JamieMeyer
  • 386
  • 3
  • 14
  • **Thanks Jamie** yes i understands this factor. I can't purchase a printer. But i have a solution and i need Help. I need to set assemblies and write code correct. and when this installs on the customer's computer. As customer has the printer and driver. NOW, If i wrote the code correct and set every things to its location. then i hope no bad thing happen. Important thing is what are the key steps in development that i should check for this very task. This is a risky step but its my need and i can't deviate. – Khizar Ali Jun 23 '12 at 02:03
0

This is my Working Code. I think the c# example is not correct and you must change DocumentClass for Document.

Actives code is for interop.bpac.dll Comented code is for bpac.dll

Blockquote

public void ETQ_Print(string Lote, string NumSerie) {

        try
        {
            // bpac.Document PrnLabel = new bpac.Document ();
            ///  bpac.Document PrnLabel = new bpac.Document();

            bpac.Document doc = new Document();

            // Actualizo los Campos de la Etiqueta.

            // if (PrnLabel.Open(this.txtETQ_Plantilla.Text))
            if (doc.Open (this.txtETQ_Plantilla.Text) != false)
            { // hemos cargado la plantilla corectamente.

                // Editamos los campos necesarios..
                // PrnLabel.GetObject("BarCode").Text = Lote + NumSerie;
                doc.GetObject("BarCode").Text = Lote + NumSerie;
                // PrnLabel.GetObject ("objName").Text = ETQ_txtNumSerie.Text;
                // PrnLabel.StartPrint("", PrintOptionConstants.bpoDefault);
                doc.StartPrint("", PrintOptionConstants.bpoDefault);
                // PrnLabel.PrintOut(1, PrintOptionConstants.bpoDefault);
                doc.PrintOut(1, PrintOptionConstants.bpoDefault);
                // PrnLabel.EndPrint();
                doc.EndPrint();
                // PrnLabel.Close();
                doc.Close();
            }
            else
            {
                MessageBox.Show(this, "Open() Error: " + doc.ErrorCode); //  PrnLabel.ErrorCode);
            }
        }
        catch
        {
            MessageBox.Show(this, "Error de Etiqueta", "Error Etiqueta", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }
    }

Blockquote

Benitoar
  • 1
  • 1
0

I had the exact same problem. It turns out that I had inadvertently downloaded the 32 bit version of the SDK. Version info from http://www.brother.com/product/dev/label/bpac/download/index.htm#full

enter image description here

Once I removed the 32 bit SDK and added the 64 bit SDK the example worked right out of the box. This is for b-PAK 3.2.001. The next step for me was to load the template used in the sample code into P-touch editor and set the proper color and print size.

Syfer
  • 4,262
  • 3
  • 20
  • 37
0

Sources: Brother youtube instructional video : https://www.youtube.com/watch?v=WRssVf8zxQQ and the other excellent answers above. They didn't quite work for me.

With Visual Studio Community 2017, I added a reference to interop.bpac, and then ran:

        try
        {
            bpac.Document mylabel = new bpac.Document();
            if (mylabel.Open("SensorNodeLabel.lbx"))
            {
                mylabel.GetObject("labelText").Text = "blah blah";


                mylabel.StartPrint("", bpac.PrintOptionConstants.bpoDefault);
                mylabel.PrintOut(1, bpac.PrintOptionConstants.bpoDefault);
                mylabel.EndPrint();
                mylabel.Close();
            }
        }
        catch ...

This worked nicely on the QL-700 label printer.

monkey
  • 1,213
  • 2
  • 13
  • 35