Search code examples
c#bluetoothwindows-mobilezebra-printers32feet

Zebra iMZ320 communication error bluetooth


I want to print some lines on a Zebra iMZ320 from a Motorola ES400 running WM6.5. I'm communicating over bluetooth using 32feet library and C#.

My code used to work great on the MZ320 but with the new iMZ320 the communication sometimes halts (even in the middle of the printing job) and I have to restart the printer because it keeps refusing to connect again.

I've tried to break the CPCL string in several lines and send it line by line with 100ms intervals but with no improvements.

I've noticed that when I close my app and re-start it the communication will fail for sure.

private void btPrint_Click(object sender, EventArgs e)
    {            
        // Activate BT
        BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
        System.Threading.Thread.Sleep(1000);
        // Connect  
        BluetoothAddress btAddress;
        btAddress = BluetoothAddress.Parse("0022583165F7");            
        BluetoothClient btClient = new BluetoothClient();
        try
        {
            btClient.Connect(new BluetoothEndPoint(btAddress, BluetoothService.SerialPort));
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return;
        }
        // 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);
        btClient.dispose();
        btClient.Close();
    }

Solution

  • Zebra provides a windows mobile sdk to make Bluetooth connections for you.