Brother printer Esc/P

若如初见. 提交于 2021-01-28 05:19:31

问题


I am wanting to print pricing labels for a list of products. I cannot use the csv as the prices change and am doing this through an in house application. How do I send like an array of data to the printer. I can print one label at a time, however this is slow. Through the P Template software it prints really quick. Any help would be much appreciated.

I am sending the commands to the printer in Hex and they work ok. Can print with Esc/P mode and with P Template mode. P Template mode is better as the layout can be set and stored on the printer, then all I need to do is send the object data.

Any help on how to send an array of sorts would be much appreciated.


回答1:


We are using a Mac computer (any Unix machine will do the same) and send the data to the printer from a simple bash script. If using a Windows computer, it will work the same way, just find a way to send binary data to the serial/USB port.

(The reason a Unix machine is preferred by us, because we also communicate to an external server database via Internet, an easy task in Unix scripting).

All Unix machines have 'lp' command, which can send binary data to printer. I wrote a script in bash terminal, which parces its arguments, copies them to 'data' variable, then sends this 'data' variable to the printer.

In short, a small label can be printed like this:

data="\x1Bia\x00"       # set esc_p mode
data="${data}\x1B@"     # initialize printer (resets many variables)
data="${data}\x1BX\x32" # set font height
data="${data}Hello"     # the actual data to be printed
data="${data}\x0C"      # advances the page (basically prints the label)

# Check your binary on the screen (for debugging):
echo -ne $data | hexdump -C

# Send the data to the printer
echo -ne $data | lp -d Brother_PT_P900W

Of course, you must replace the 'Brother_PT_P900W' with your own printer name.



来源:https://stackoverflow.com/questions/45503738/brother-printer-esc-p

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