我正在尝试使用热敏打印机打印收据。
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;
}
答案 0 :(得分:1)
好的,我找到了解决方案。我只需要在调用mprinter.Write(byteData);
之后调用Thread.sleep()