跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 新手求助
  4. PosBox模块通过树莓派的硬件盒子打印出来的中文出现乱码

PosBox模块通过树莓派的硬件盒子打印出来的中文出现乱码

已定时 已固定 已锁定 已移动 Odoo 新手求助
12 帖子 4 发布者 10.6k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • V 离线
    V 离线
    vFire
    写于 最后由 编辑
    #1

    最近一直在捣鼓树莓派的posbox,非常不错,唯一的问题就是。。。打印出来的中文乱码啊 ,同志们有研究过这个的没有,求指点~~~
    不是本地打印的那个哦,本地没问题,但是通过树莓派打印就不行,中文出现一堆的“北北北”这样的乱码字符,查看官方文档说ESCOP打印指令暂时还不支持中文,崩溃啊~~~

    1 条回复 最后回复
    0
    • KevinKongK 离线
      KevinKongK 离线
      KevinKong
      写于 最后由 编辑
      #2

      在escpos模块下的constants.py文件中第93行(附近)添加下面一行

      TXT_ENC_PC936 ='\x1C\x21\x00'
      


      然后在escpos.py文件的第813行附近添加下面一行:

       'cp936': TXT_ENC_PC936
      


      最后,在escpos.py文件中的第838行注释掉原来一行附近添加一行:

      #encoding = &#039;cp437&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp;  encoding = &#039;cp936&#039;
      



      即,在constants.py文件中添加对中文的编码支持,蓝后在escpos.py文件中引用新添加的encoding,最后的encode_char看起来大概是这个样子的:

      def encode_char(char):&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Encodes a single utf-8 character into a sequence of <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; esc-pos code page change instructions and character declarations <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char_utf8 = char.encode(&#039;utf-8&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encoded&nbsp; = &#039;&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encoding = self.encoding # we reuse the last encoding to prevent code page switches at every character<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encodings = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # TODO use ordering to prevent useless switches<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # TODO Support other encodings not natively supported by python ( Thai, Khazakh, Kanjis )<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp936&#039;: TXT_ENC_PC936,&lt;-----新加的<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp437&#039;: TXT_ENC_PC437,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp850&#039;: TXT_ENC_PC850,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp852&#039;: TXT_ENC_PC852,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp857&#039;: TXT_ENC_PC857,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp858&#039;: TXT_ENC_PC858,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp860&#039;: TXT_ENC_PC860,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp863&#039;: TXT_ENC_PC863,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp865&#039;: TXT_ENC_PC865,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp866&#039;: TXT_ENC_PC866,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp862&#039;: TXT_ENC_PC862,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp720&#039;: TXT_ENC_PC720,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;iso8859_2&#039;: TXT_ENC_8859_2,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;iso8859_7&#039;: TXT_ENC_8859_7,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;iso8859_9&#039;: TXT_ENC_8859_9,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp1254&#039;&nbsp;  : TXT_ENC_WPC1254,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp1255&#039;&nbsp;  : TXT_ENC_WPC1255,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp1256&#039;&nbsp;  : TXT_ENC_WPC1256,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp1257&#039;&nbsp;  : TXT_ENC_WPC1257,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;cp1258&#039;&nbsp;  : TXT_ENC_WPC1258,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;katakana&#039; : TXT_ENC_KATAKANA,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; remaining = copy.copy(encodings)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not encoding :<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #encoding = &#039;cp437&#039; &lt;----注释掉<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encoding = &#039;cp936&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ……<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  
      



      然后再重启服务,你就会发现中文好使了。
      Good luck!

      1 条回复 最后回复
      0
      • mrshellyM 离线
        mrshellyM 离线
        mrshelly
        写于 最后由 编辑
        #3

        赞, 就是给 escpos 添加 cp936 编码 的支持吧?

        看整理一下 提到官网github 好了...
        谢谢 贡献...

        1 条回复 最后回复
        0
        • mrshellyM 离线
          mrshellyM 离线
          mrshelly
          写于 最后由 编辑
          #4

          https://github.com/fvdsn/py-xml-escpos/pull/5/files

          已提交给 py-xml-escpos 不知道官网什么时候能合并

          1 条回复 最后回复
          0
          • KevinKongK 离线
            KevinKongK 离线
            KevinKong
            写于 最后由 编辑
            #5

            直接提给Odoo官方不行么,我看他们都改了escpos的文件

            1 条回复 最后回复
            0
            • V 离线
              V 离线
              vFire
              写于 最后由 编辑
              #6

              太谢谢了~ 一下子就搞定了,之前联络了odoo的官方支持,他们也还没搞定或者说顾得上搞定,搜遍全网都没找到这个解决方法,兄弟,在上海不,我要请你吃饭。。。!!!版主,你可以来蹭一下~:)

              1 条回复 最后回复
              0
              • KevinKongK 离线
                KevinKongK 离线
                KevinKong
                写于 最后由 编辑
                #7

                [quote author=vFire link=topic=17116.msg30410#msg30410 date=1432651083]
                太谢谢了~ 一下子就搞定了,之前联络了odoo的官方支持,他们也还没搞定或者说顾得上搞定,搜遍全网都没找到这个解决方法,兄弟,在上海不,我要请你吃饭。。。!!!版主,你可以来蹭一下~:)
                [/quote]
                哈哈,客气啦,我在北京不在上海,可以让校长和Joshua代我去吃啊,O(∩_∩)O哈哈~

                1 条回复 最后回复
                0
                • V 离线
                  V 离线
                  vFire
                  写于 最后由 编辑
                  #8

                  [quote author=KevinKong link=topic=17116.msg30412#msg30412 date=1432691680]
                  [quote author=vFire link=topic=17116.msg30410#msg30410 date=1432651083]
                  太谢谢了~ 一下子就搞定了,之前联络了odoo的官方支持,他们也还没搞定或者说顾得上搞定,搜遍全网都没找到这个解决方法,兄弟,在上海不,我要请你吃饭。。。!!!版主,你可以来蹭一下~:)
                  [/quote]
                  哈哈,客气啦,我在北京不在上海,可以让校长和Joshua代我去吃啊,O(∩_∩)O哈哈~
                  [/quote]

                  那我去北京的时候怎么也得找你吃饭~ 把QQ密我~~~ 再次表示感谢~

                  1 条回复 最后回复
                  0
                  • mrshellyM 离线
                    mrshellyM 离线
                    mrshelly
                    写于 最后由 编辑
                    #9

                    OK , 官网  v8.0 分支已经合并进去了...
                    到时看看 master v9.0 分支是否合并...
                    <br / https://github.com/odoo/odoo/commit/8fe042ea917dad6a09fe69ef47ad6d6c4f3a72af br />

                    1 条回复 最后回复
                    0
                    • KevinKongK 离线
                      KevinKongK 离线
                      KevinKong
                      写于 最后由 编辑
                      #10

                      ;)Cool

                      不过看着你们沟通的过程,感觉朝官网提交个代码好费劲啊~~

                      1 条回复 最后回复
                      0
                      • P 离线
                        P 离线
                        podo
                        写于 最后由 编辑
                        #11

                        請問我們打印機(EPSON TM-T88IV)只有支援BIG5編碼

                        我們印出來的中文字都會顯示 控控控控

                        請問該如何修改呢?

                        1 条回复 最后回复
                        0

                        • 登录

                        • 没有帐号? 注册

                        • 登录或注册以进行搜索。
                        • 第一个帖子
                          最后一个帖子
                        0
                        • 版块
                        • 标签
                        • 热门
                        • 用户
                        • 群组