Search code examples
printingbluetoothraspberry-pi2zebra-printerswindows-10-iot-core

Windows IoT - Zebra Bluetooth Printer


I have two Zebra Bluetooth Printers, a MZ220 and iMZ220. The "only" thing I would do, is to print text with a Windows IoT System on a Raspberry Pi 2. Nothing more ;)

Example: Line1 " Hello World" Line2 "---------------" Line3 "Date:01.01.2016" Line4 "Time: 18:00"

The USB Bluetooth Adapter BTA-403 from ORICO, I guess works well. With the Explorer I can connect to the Printer. But, what next? How do I connect to the Printer? How do I say to the Printer print "Hello World!"

Thanks!


Solution

  • These printers are using Bluetooth like a serial port aka SSP profile.

    First, you'll have to edit your app manifest and add a new device capability

    <Capabilities>
        <Capability Name="internetClient" />
        <DeviceCapability Name="bluetooth.rfcomm">
            <Device Id="any">
                <Function Type="name:serialPort"/>
            </Device>
        </DeviceCapability>
    </Capabilities>
    

    You can get the paired printers like this

    var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
    

    Once you identified the right printer, you can open the connection

    var service = await RfcommDeviceService.FromIdAsync(DeviceInfo.Id);
    var socket = new StreamSocket();
    await socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
    

    You should be able to send then information like this

    private async void PrintAsync(string line)
    {
        var writer = new DataWriter(socket.OutputStream);
        var command = "^XA^LH30,30^F020,10^AD^FD + line + "^FS^XZ";
        writer.WriteString(command);
        await writer.StoreAsync();
    }