Windows IoT - Zebra Bluetooth Printer

╄→гoц情女王★ 提交于 2019-12-02 02:20:27

问题


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!


回答1:


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();
}


来源:https://stackoverflow.com/questions/34510095/windows-iot-zebra-bluetooth-printer

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