Can I print with windows phone 8 using Bluetooth to a portable printer?

醉酒当歌 提交于 2019-12-03 15:07:47

This code works for me on a Zebra 420 paired with a Nokia 820.

 private async void PrintStuff()
        {
            string command = "^XA^LH30,30^F020,10^AD^FDHello World^FS^XZ";
            Byte[] buffer = new byte[command.Length];
            buffer = StringToAscii(command);

            PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
            var pairedDevices = await PeerFinder.FindAllPeersAsync();

            if (pairedDevices.Count == 0)
            {
                Debug.WriteLine("No paired devices were found.");
            }
            else
            {
                PeerInformation selectedDevice = pairedDevices[0];
                StreamSocket socket = new StreamSocket();
                await socket.ConnectAsync(selectedDevice.HostName, "1");                
                await socket.OutputStream.WriteAsync(WindowsRuntimeBufferExtensions.AsBuffer(buffer));
            }
        }

There are already examples of other BT-SPP printers on WP8. It should be possible to connect to your "Zebra" bluetooth printer and send it jobs. Based on this documentation is supports the BT-SPP (bluetooth serial port portocol) that WP8 supports:

One thing you're going to have to figure out first is the specifics of the input/output byte packets expected by your device. SPP just sends and receives bytes over BT, you need to know the specific format your device needs. For example in my Mindwave Headset WP8 BT SDK I had to find this document that has the BT-SPP protocol for that particular device. There seem to be quite a few OSS projects for Zebra printers, so you might want to see if those have those formats.

I'm working on an Android app (Windows Phone later) that uses a Bluetooth printer and it is simple and I found it can be done with any OS that has Bluetooth capabilities. Each printer is a little different to connect to, but once you can get connected, you just pass data through serial. In my case, I'm using an image and sending the bytes as a string.

Zebra provides an API for Windows Mobile .NET framework for printing in WinMo .NET

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!