热敏打印机仅在设置断点时打印

时间:2015-11-26 09:22:35

标签: java android printing java-native-interface

我正在尝试使用热敏打印机打印收据。

    printer mprinter = new printer();
    mprinter.Open();
    mprinter.SetPrintMode(1);
    /*Some code */
    mprinter.Write(byteData);
    mprinter.Close();

当我在mprinter.Close();(或其他地方)附近设置断点时,一切正常。如果我重置断点热敏打印机什么都不打印。为什么会这样?

我的原生功能:

   JNIEXPORT jint JNICALL Java_aclasdriver_printer_Open(JNIEnv *env, jobject thiz)
       {
           if(openflag < 0)
           {
               openflag = open(DEV_PRINTER_NAME, O_RDWR);
           }

           return openflag;
       }

   JNIEXPORT jint JNICALL Java_aclasdriver_printer_Write(JNIEnv *env, jobject thiz, jbyteArray wrbuf)
   {
       jbyte *pwrbuf;
       int ret;
       int wrlen;
       int i;

       if(openflag < 0)
       {
           return -1;
       }
       LOGD("Printer write");

       pwrbuf = (*env)->GetByteArrayElements(env, wrbuf, NULL);
       wrlen = (*env)->GetArrayLength(env, wrbuf);
       for(i =0 ;i< wrlen;i++)
       {
          LOGD("%x ",pwrbuf[i]);
       }

       ret = write(openflag, pwrbuf, wrlen);
       (*env)->ReleaseByteArrayElements(env, wrbuf, pwrbuf, 0);

       return ret;
   }

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案。我只需要在调用mprinter.Write(byteData);

之后调用Thread.sleep()