- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在构建一个使用蓝牙热敏打印机打印收据的应用程序。我可以使用打印机连接和打印,但我无法弄清楚所有这些 ESC/POS 命令的含义。
打印机将我的文本打印为黑色背景上的白色,而我实际上希望文本为黑色,背景为白色。我不确定如何使用 ESC/POS 命令实现这种类型的格式化。
这是我的打印代码:
if (btsocket == null) {
Intent BTIntent = new Intent(getApplicationContext(), DeviceList.class);
this.startActivityForResult(BTIntent, DeviceList.REQUEST_CONNECT_BT);
} else {
OutputStream opstream = null;
try {
opstream = btsocket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
outputStream = opstream;
//print command
try {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
outputStream = btsocket.getOutputStream();
byte[] format = { 27, 33, 0 };
byte[] printformat = {0x1B, 0 * 21, FONT_TYPE};
outputStream.write(format);
//print title
printUnicode();
//print normal text
outputStream.write(format);
printCustom(message, 0, 0);
//printPhoto(R.drawable.img);
printNewLine();
outputStream.write(format);
printText(" >>>> Thank you <<<< "); // total 32 char in a single line
//resetPrint(); //reset printer
//printUnicode();
printNewLine();
printNewLine();
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
第一行printUnicode();
实际上在白色背景上打印了很好的黑色字符,但纸张的其余部分则在黑色背景上打印了白色字符。有没有解释所有 ESC/POS 命令的文档?
最佳答案
您可以检查这些页面中的 ESC/POS 命令,这对我来说非常有用:
https://github.com/escpos/escpos/blob/master/lib/escpos.rb
<小时/>还有我的一段代码,希望有帮助:
public class MainActivity extends AppCompatActivity {
Button printButton;
final byte[] ALIGN_CENTER = {0x1b, 0x61, 0x01};
final byte[] ALIGN_LEFT = {0x1b, 0x61, 0x00};
final byte[] ALIGN_RIGHT = {0x1b, 0x61, 0x02};
final byte[] TEXT_SIZE_NORMAL = {0x1b, 0x21, 0x00};
final byte[] TEXT_SIZE_LARGE = {0x1b, 0x21, 0x30};
final byte[] INVERTED_COLOR_ON = {0x1d, 0x42, 0x01};
final byte[] BEEPER = {0x1b,0x42,0x05,0x05};
final byte[] INIT = {0x1b, 0x40};
//final byte[] CUT_PAPER = {0x1d, 0x56, 0x00};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
printButton = findViewById(R.id.main_print_button);
printButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new PrintTask().execute();
}
});
}
private class PrintTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
try {
String text1 = "No setting size text" + "\n\n";
String text2 = "Inverted color text" + "\n\n";
String text3 = "Large size text" + "\n\n\n";
Socket socket = new Socket("192.168.1.241", 9100); //one socket responsible for one device
OutputStream outputStream = socket.getOutputStream();
outputStream.write(text1.getBytes("GBK")); //when printing text, "write()" will print before "println()"
outputStream.write(INVERTED_COLOR_ON);
outputStream.write(text2.getBytes("GBK"));
outputStream.write(new byte[]{0x1D, 0x56, 0x41, 0x10}); //"0x1d, 0x56, 0x41" is for paper cut and "0x10" is for line feed
//outputStream.write(BEEPER); //hardware turn on
outputStream.write(INIT);
outputStream.close();
socket.close();
} catch (UnknownHostException e) {
Log.e("Print()", "UnknownHostException");
} catch (IOException e) {
Log.e("Print()", "IOException");
}
return null;
}
}
关于java - ESC/POS 命令解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56578406/
我计划使用 pos for .net 创建我自己的 POS 系统。 到目前为止,我从未创建过任何 POS 系统或为 .net 使用过 pos。我试图找到一些教程但没有成功,有人知道一些好的网站或书籍吗
阅读 pygame 教程 here ,你会发现这个例子:(箭头是我的) for o in objects: screen.blit(background, o.pos, o.pos) # Re
所以我一直在为蓝牙打印机编写 Android 应用程序一段时间,我意识到这实际上是 ESC/POS 标准:http://nicholas.piasecki.name/blog/wp-content/u
我设法在 上更改了 POS 收据模板/addons/point_of_sale/static/src/xml/pos.xml 其中位于: 但是如何更改 PosTicket 上的详细信息?
我有一个长度为 32 的字符数组,想从中取出某些字符。例如 111111000000000000000000111111 #include #include /* Creates a sub-s
Parsey McParseface输出的POS标签和Depedency标签在 tag-set 中给出和 label-set文件 here分别。 Syntaxnet自述文件概述了该模型是在 Penn
我正在尝试使用 Stanford POS-tagger,我想问一下是否可以解析(实际上只有 pos 标签就足够了)英文文本并以 conll 格式输出结果。有这样的选择吗? 我正在使用 Stanford
我有使用 NLTK 的平均感知器标记器进行词性标记的代码: from nltk.corpus import wordnet from nltk.stem import WordNetLemmatize
我正在尝试为 58mm POS 热敏打印机编写正确的 ESC/POS 命令。我尝试将此命令作为 ASCII 文本输入,并将其转换为 HEX,但在这两种情况下,打印机都只打印此代码,而不是收据输出。代码
我正在使用 spaCy 库进行 POS 标记,但是当我运行这段代码时,它会返回数字来代替 pos 标签: import spacy from spacy.lang.fr.examples import
我博客的标题显示标题后面有一张图片。我希望这张图片有自己的高度直到它变得大于50vh(用户视口(viewport)的 50%)。 但正常行为是图像从底部裁剪,我希望图像从顶部和底部裁剪(换句话说:我希
我正在阅读句子列表并使用 NLTK 的 Stanford 词性标注器标记每个单词。我得到这样的输出: wordnet_sense = [] for o in output: a = st.ta
我们正在尝试实现一个支持 COM 接口(interface)的 .NET 服务对象来模拟 POSPrinter,但仍然与旧技术兼容。 我们在下面的类中有我们的接口(interface)和类对象。 us
我有一个列表 list = ['about','above','account','address','after'] 我将其传递给 nltk pos 标签 函数,输出看起来像这样以列表的形式: [(
有谁知道为什么“深度”(vertShader) 不同于“gl_FragCoord.z”(从 opengl 渲染)?特别是随着 z 的减小,差异变得更大。 “深度”是否有可能在更高的 z 值下更精确?
假设我有一个 block 元素,例如 h2: Title 然后我给它一个背景色。背景将跨越 wrapper 的整个宽度(应该如此)。 如果我 float 它,或者 position: absolute
我提供了一个 fiddle : http://jsfiddle.net/dCYdw/ 这个例子很惨,但是问题也能看出来。 .levelFive 是问题所在。这应该在所有其他元素之前,因为它的 z-in
C++(STL): Request for member ‘push_back’ in ‘pos.std::vector::operator[](((std::vector::size_type)i)
以下 JavaScript 中包含云图像的元素的动画的逻辑错误到底是什么?我认为“pos”变量似乎在每次迭代中都偏离了方向,而且我无法弄清楚每次迭代时云图像的运动如何变得越来越疯狂。 //CSS: #
我正在尝试在RMarkdown文档中插入图形,但无法将其显示在正确的位置。下图显示了该问题:使用图标题时,该图显示在页面顶部而不是文档中相关段落的下面。 这是此最小工作示例的代码: --- title
我是一名优秀的程序员,十分优秀!