Question

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();
    }
Was it helpful?

Solution

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

OTHER TIPS

There have been multiple bugs in the Bluetooth stacks (StoneStreetOne and Microsoft) included with Motorola WinMobile handhelds that will cause failures similar to this. Since you are using the 32Feet library for BT, you should be able to switch stacks (from SSO to MS or vice-versa) without any code changes to your app. This requires a simple registry modification -- see http://christian-helle.blogspot.com/2010/10/motorola-dual-bluetooth-stack-support.html for more info.

Also, I would make sure that you running the latest WinMobile release from Motorola. I'd also make sure that you have the latest firmware for the iMZ (V73.19.6Z as of April 2014). Besides being good practice in general, both Motorola and Zebra have fixed Bluetooth-related issues in recent firmware versions.

Additional testing from a PC/Android device should yield some insight into whether the source of the issue is the printer or handheld -- if you can't reproduce this problem when connecting to the printer from other devices, then the handheld is likely at fault.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top