使用 JAVA 或批处理文件打开现金抽屉

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11309054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:37:33  来源:igfitidea点击:

Opening a Cash Drawer using JAVA or Batch File

javabatch-filethermal-printer

提问by Theron084

I have a Partner RP-300 receipt printer with a cash drawer connected to it for experimental purposes.It connects to the PC via LPT1.

我有一个 Partner RP-300 收据打印机,为了实验目的,它连接了一个现金抽屉。它通过 LPT1 连接到 PC。

I would like to open the cash drawer by means of a java application or a batch file.

我想通过 java 应用程序或批处理文件打开钱箱。

Any ideas?

有任何想法吗?

EDIT I have found out that the command to open the drawer is ESC p, hex value \x1b\x70\x00,

编辑我发现打开抽屉的命令是ESC p,十六进制值\x1b\x70\x00,

but how do I send that command to the printer using cmd?, I tried putting latter in a text file, then using copy \b file name lpt1, but it just prints the contents of the text file on the printer.

但是如何使用 cmd 将该命令发送到打印机?我尝试将后者放入文本文件中,然后使用 copy \b 文件名 lpt1,但它只是在打印机上打印文本文件的内容。

回答by wmz

I have looked into the manual and the command includes two more parameters, pulse on and pulse off. It's also well explained here: How to program cash drawer to open. So the command is ESC p m t1 t2, where m is relating to connector pin, and t1, t2 are high/low times. You send only ESC p 0 (\x1b\x70\x00), while you should do eg. ESC p 0 25 250 (\x1b\x70\x00\x19\xfa)

我查看了手册,命令还包括两个参数,脉冲开启和脉冲关闭。这里也有很好的解释:How to program cash drawer to open. 所以命令是ESC p m t1 t2,其中 m 与连接器引脚有关,t1、t2 是高/低时间。你只发送ESC p 0 (\x1b\x70\x00),而你应该做例如。ESC p 0 25 250 (\x1b\x70\x00\x19\xfa)

copy /b is perfectly valid way of sending your control commands to the printer and it should work.

copy /b 是将控制命令发送到打印机的完全有效的方式,它应该可以工作。

Just make sure that your file does include proper hex sequence using any hex editor.

只需使用任何十六进制编辑器确保您的文件确实包含正确的十六进制序列。

Hope this helps

希望这可以帮助

Edit: link to technical manual

编辑:链接到技术手册

Edit: To get command sequence encoded in file (long but easy):
1. Get Notepad++
2. Check you have Converter installed under plugins. If not, find and install it
3. Create new file in Notepad++
4. Select ANSI under encoding
5. Enter 1b700019fa

6. Select(highlight) string you entered (or select all with Ctl-A)
7. Go to plugins->Converter-> HEX --> ASCII
8. You should see garbled output (with letter p inside). Save
9. Send your file to printer.

编辑:获取文件中编码的命令序列(长但简单):
1. 获取 Notepad++
2. 检查您是否在插件下安装了 Converter。如果没有,找到并安装它
3. 在 Notepad++ 中创建新文件
4. 在编码下选择 ANSI
5. 输入 1b700019fa

6. 选择(突出显示)您输入的字符串(或使用 Ctl-A 全选)
7. 转到 plugins->Converter -> HEX --> ASCII
8. 您应该会看到乱码输出(里面有字母 p)。保存
9. 将您的文件发送到打印机。

回答by LINEMAN78

You should be able to use RXTX or javax.comm(depricated) to send binary commands to an LPT port.

您应该能够使用 RXTX 或 javax.comm(已弃用)将二进制命令发送到 LPT 端口。

http://rxtx.qbang.org/wiki/index.php/Using_RXTX

http://rxtx.qbang.org/wiki/index.php/Using_RXTX

http://rxtx.qbang.org/wiki/index.php/Parallel_Communications

http://rxtx.qbang.org/wiki/index.php/Parallel_Communications