使用ESC POS生成QRCode并以打印机热敏方式打印-ZIJIANG 58mm-Delphi 10.2

如何解决使用ESC POS生成QRCode并以打印机热敏方式打印-ZIJIANG 58mm-Delphi 10.2

我正尝试在android平台delphi中的热pos蓝牙打印机上打印qr代码(firemonkey)。 打印机已连接,我可以打印文本,但是我无法生成和打印二维码,如果有人可以提供帮助,我将不胜感激。

pos打印机的标记为P08-580LD(ZIJIANG)。

这是我在delphi-android 10.2中使用的代码。

        sock.connect;
         // Reset Printer
         ostream.write(StringToJA(escResetPrinter,'iso8859-2'));

        ostream.write(StringToJA(pO8escBoldOn,'iso8859-2'));
        ostream.write(StringToJA('Naziv 1'+escNewLine,'iso8859-2'));
        ostream.write(StringToJA(pO8escBoldOff,'iso8859-2'));

        ostream.write(StringToJA(pO8escFontA,'iso8859-2'));
        ostream.write(StringToJA('Adresa'+escNewLine,'iso8859-2'));
        ostream.write(StringToJA(escResetPrinter,'iso8859-2'));

        ostream.write(StringToJA(pO8escFontB,'iso8859-2'));
        ostream.write(StringToJA('MB xxxxx,ID HR-AB-99-0125--54'+escNewLine,'iso8859-2'));

        ostream.write(StringToJA(pO8escUnerlineOn,'iso8859-2'));
        ostream.write(StringToJA('IBAN: xxxxxxxxx'+escNewLine,'iso8859-2'));
        ostream.write(StringToJA(pO8escUnerlineOff,'iso8859-2'));

        ostream.write(StringToJA('OIB 99999999'+escNewLine,'iso8859-2'));

       // start - qr-code //
        ostream.write(StringToJA(chr(27)+chr(90)+chr(0)+chr(7)+chr(15)+chr(25)+chr(30)+'dada','iso8859-2'));

        ostream.write(StringToJA(escResetPrinter,'iso8859-2'));

   Sleep(250);
   ostream.flush();
   ostream.close;

这是打印机的文档,其中说明了如何构建代码(十进制)。

https://mega.nz/file/fu4zTCSR#UZ53LSty7dUpRyqzvz8li27amG1KvVlLk0slQFhd5Os

我设法生成了如下图所示的qr代码,但不是很好。

enter image description here

这是应根据打印机文档生成qr代码的方式

enter image description here

我在android studio中找到了一个函数,该如何构建qr代码,如果有人知道如何将一个函数转换为delphi,我将不胜感激。

.....

 byte[] qrcode = PrinterCommand.getBarCommand("Zijiang Electronic Thermal Receipt Printer!",3,6);//
 Command.ESC_Align[2] = 0x01;
 SendDataByte(Command.ESC_Align);
 SendDataByte(qrcode);

public static byte[] getBarCommand(String str,int nVersion,int nErrorCorrectionLevel,int nMagnification)

{   
  if(nVersion<0 | nVersion >19 | nErrorCorrectionLevel<0 | nErrorCorrectionLevel > 3
            | nMagnification < 1 | nMagnification > 8){
          return null;
      }
      
     byte[] bCodeData = null;
     try
     {
      bCodeData = str.getBytes("GBK");
       
     }
     catch (UnsupportedEncodingException e)
     {
       e.printStackTrace();
       return null;
     }

     byte[] command = new byte[bCodeData.length + 7];     
     command[0] = 27;
     command[1] = 90;
     command[2] = ((byte)nVersion);
     command[3] = ((byte)nErrorCorrectionLevel);
     command[4] = ((byte)nMagnification);
     command[5] = (byte)(bCodeData.length & 0xff);
     command[6] = (byte)((bCodeData.length & 0xff00) >> 8);
     System.arraycopy(bCodeData,command,7,bCodeData.length);
     return command;
   }

解决方法

在那种迷你 POS 打印机上有非常相似的问题。当直接从 Kotlin(Android Studio,原生)打印时,我设法以某种方式部分解释了他们的官方手册,并得出结论认为 ESC Z 的工作方式几乎没有什么不同(实际上它与您找到的 Java 代码一致)...

  1. ESC Z (27 90)
  2. 第一个字节与表格行(“版本”)相关,如果为 0,则它将“自动选择”
  3. 起初,我认为第二个字节必须是 'M' (77) - 'L','Q','H' - 没有让它起作用?! (实际上它必须是基于纠错的 0,1,2,3 - 正如您在此处找到并发布的 Java 代码中所建议的那样)
  4. 这个字节与二维码大小有关,1-8
  5. 字符串大小的低字节(例如,对于您的“爸爸”,它将是 4)
  6. 字符串大小的较高字节(对于您的“爸爸”,它将为 0...如果长度超过 256 个字符,则长度为 div 256)
  7. 字符串字符

在你的 Delphi 代码中,我会改变(一步一步,你可以对长度进行二进制掩码......):

// start - qr-code //
ps := 'dada'; // your content string... detalji o računu ili štogod...
l1 := length(ps);
y  := l1 div 256;
x  := l1 - y * 256; 
ostream.write(StringToJA(chr(27)+chr(90)+chr(7)+chr(1)+chr(6)+chr(x)+chr(y)+ps,'iso8859-2'));

// please not that 7-1-6 is fixed combination - 7 relates to the table from documentation,1 relates to error correction (use 0 for "smaller" QR with less redundany,or 2 and 3 for larger more complex QR),6 relates to size of printed code (can be set lower)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-