This project has moved. For the latest updates, please go here.

Can't pair to Bluetooth Printer Zebra MZ 320

Topics: Bluetooth - Microsoft
May 11, 2012 at 12:53 PM
Edited May 11, 2012 at 1:00 PM


i want to pair between a Zebra MZ 320 Bluetooth Printer and a WM 6.5 Device.

The WM 6.5 Device uses the Windows Bluetooth Stack.

At first i tried to use the InTheHand.Net.Personal.dll  Version 3.4.0429.0 but it fails with false at this Call

BluetoothSecurity.PairRequest(btDevice.DeviceAddress, "")

For a better debugging i added the InTheHand.Net.Personal.CF2 and InTheHand.Net.Personal (Version 3.4.0429.0) Projects to my Solution.

I found ouf that in Class InTheHand.Net.Bluetooth.Msft.WindowsBluetoothSecurity the Method-Call 

int result = NativeMethods.BthPairRequest(device.ToByteArray(), len, pinbytes);

returns the result 87.


What does this means ?

Thx for your support

May 14, 2012 at 2:34 PM

Is this the Reason why it does not work ?,26,43#


I have tried to connect without pairing. This works for me... 


...but when i try to send/write my CPCL-Command Bytes to the Printer it does "print" some empty rows.

Does anybody knows why ?

Thx for any support

May 15, 2012 at 3:30 PM

Error code 87 is ERROR_INVALID_PARAMETER The BthPairRequest page ( suggests that that occur when "The PIN length is incorrect."

As to you 'blank' printing.  Does CPCL need some special commands to set some mode or something.  Does it need the job to end with FF maybe?

If you're want to set-up a virtual COM port as asked at stackoverflow, try using class BluetoothSerialPort or BluetoothDeviceInfo.SetServiceState. See

May 16, 2012 at 1:08 PM

Tronix, I am having the same issues. I have to wait for a charger before I can continue work, but I've sent a few emails with Zebra. If the device has authentication turned off, try turning it on and setting a pin on it. Or if you can set a pin without turning on authentication, try that as well. Hope it works. (I'm actually the one that posted the stack overflow question.)

May 17, 2012 at 11:43 AM
Edited May 17, 2012 at 11:44 AM

thank you both for your reply,

actually i found a other way without pairing, that works for me.


I just connect to the zebra printer by using BluetoothClient.Connect  (

The BluetoothEndpoint does not assigned to a specific com-port (

To send/write some data (incl CPCL Commands) i use the BluetoothClient.GetStream  (

and write to the datastream.  

I do not use the Zebra SDK to create the CPCL Commands (e.g.,

i just build them by using StringBuilder and convert with

My App simple stores the selected Printer-Address in the registry to remember it for the next time.


HTH someone

Thx and best regards

May 24, 2012 at 9:29 AM


I'm trying to develop a similar project (using Motorola ES400 running WM6.5 to print to Zebra MZ320).

I've tried several approaches but still with no success.

Can someone provide some code sample for this ?

Thanks in advance for any help!

All the best!

May 24, 2012 at 1:13 PM
Edited May 24, 2012 at 1:14 PM

Hello Pico,

this works for me.


    BluetoothClient _btClient = null;

    void ActivateBT()
      BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
      _btClient = new BluetoothClient();

void SearchBTDevices()
      Cursor.Current = Cursors.WaitCursor;

        BluetoothDeviceInfo[] btDevices = _btClient.DiscoverDevices(1, true, true, true);

        foreach (BluetoothDeviceInfo btDevice in btDevices)
      catch (Exception)
        Cursor.Current = Cursors.Default;

void ConnectDevice(InTheHand.Net.BluetoothAddress address)
      _btClient.Connect(new InTheHand.Net.BluetoothEndPoint(address, BluetoothService.SerialPort));

      if (_btClient.Connected)
        string cpclCommand = "! 0 200 200 40 1\r\n" +
                             "IN-MILLIMETERS\r\n" +
                             "LABEL\r\n" +
                             "CONTRAST 0\r\n" +
                             "TONE -20\r\n" +
                             "SPEED 0\r\n" +
                             ";// PAGE 0000000003800240\r\n" +
                             "IN-DOTS\r\n" +
                             "L 0 95 530 95 1\r\n" +
                             "IN-MILLIMETERS\r\n" +
                             "T 15 0 0 13 * * *   ZEBRA Printer Test   * * *\r\n" +
                             "IN-DOTS\r\n" +
                             "L 0 255 530 255 1\r\n" +
                             "FORM\r\n" +

        byte[] printCommandBytes = System.Text.Encoding.Default.GetBytes(cpclCommand.ToString());

        using (System.Net.Sockets.NetworkStream stream = _btClient.GetStream())
          stream.Write(printCommandBytes, 0, printCommandBytes.Length);




You just have to modify this solution by storing the DeviceAddress to the Registry and use them like that for the next time:





May 25, 2012 at 1:35 AM

Hi Tronix,

Many many thanks! It worked great!

In any case I also share my code, based on yours, with some minor changes.

private void btPrint_Click(object sender, EventArgs e)
            // Activate BT
            BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
            // Connect  
            BluetoothAddress btAddress;
            btAddress = BluetoothAddress.Parse("0022583165F7");            
            BluetoothClient btClient = new BluetoothClient();
                btClient.Connect(new BluetoothEndPoint(btAddress, BluetoothService.SerialPort));
            catch (Exception ex)
            // Send data
            string CPCLStr1 =
                "! 0 200 200 210 1" + Environment.NewLine +
                "ML 25" + Environment.NewLine +
                "TEXT 7 0 10 20" + Environment.NewLine +
                "Just" + Environment.NewLine +
                "Testing" + Environment.NewLine +
                "ENDML" + Environment.NewLine +
                "FORM" + Environment.NewLine +
                "PRINT" + Environment.NewLine;

            // Convert CPCL String to byte array
            byte[] CPCLbytes1 = ASCIIEncoding.ASCII.GetBytes(CPCLStr1);

            NetworkStream ns = btClient.GetStream();
            ns.Write(CPCLbytes1, 0, CPCLbytes1.Length);



Dec 12, 2012 at 9:14 AM

hey guys about the above code where do i put it?

i mean how do i execute it/ and where?

Jun 3, 2014 at 4:40 AM
Hello Pico,

Above print code is working fine for me at once but when I print the document again then I need to restart the printer then after it will print.

So is there any solution for this to avoid restart printer??