|
| | BLEConnection (Context context, String address) |
| | 根据 descriptor 字符串初始化新实例。 更多...
|
| |
| int | BytesAvailable () |
| |
| String | Descriptor () |
| | 验证 descriptorHint 中的描述字符串,此字符串可能包含或不包含 v_id 和 p_id。返回 long。 更多...
|
| |
| boolean | Connected () |
| |
| void | Close () |
| |
| void | CloseWithTimeout (int timeoutMs) |
| |
| void | Open () |
| |
| byte[] | Read () |
| |
| void | Write (byte[] dataOut) |
| |
| void | Read (OutputStream binDataIn) throws IOException |
| |
| void | WaitForData (int msTimeOut) |
| | 等待当前线程有可用数据 BytesAvailable。当前线程会休眠直到接收到数据或超时为止。此为阻塞调用。 更多...
|
| |
| void | Write (InputStream binReader) throws IOException |
| | 从输入流写入输出流。 更多...
|
| |
| void | WriteAndWaitForResponse (OutputStream binDataIn, InputStream binDataOut, int responseStartTimeOut, int responseEndTimeOut, String completetionToken) throws IOException |
| | 将 binDataOut 流数据写入输出流,并将接收到的数据返回到 binDataIn 流中。返回的数据是收到的数据或收到的完成标记。等待响应超时后返回。 更多...
|
| |
| byte[] | WriteAndWaitForResponse (byte[] dataOut, int responseStartTimeOut, int responseEndTimeOut, String completetionToken) throws IOException |
| | 将字节数据写入输出流并返回接收到的数据。返回的数据是接收到的任何数据或收到的完成标记。等待响应超时后返回。 更多...
|
| |
实现 BLE 特定通信并扩展 AComm 类的类。
示例
package com.test.UniPRTSdk;
import java.io.*;
public class commBTClassicSnippet {
public static void test() {
sendPrintFile();
sendPrintString();
}
public static void sendPrintFile() {
String fileName = "C:\\testFiles\\Hello.pgl";
try {
comm.Open();
if (new File(fileName).exists()) {
try (InputStream binReader = new BufferedInputStream(new FileInputStream(fileName))) {
System.out.println("Sending \"" + fileName + "\" to printer");
byte[] buffer = new byte[1024];
while ((binReader.read(buffer)) != -1) {
comm.Write(buffer);
}
}
} else {
System.out.println("File \"" + fileName + "\" not found");
}
} catch (Exception e) {
System.out.println("Exception Msg: " + e.getMessage());
} finally {
comm.Close();
}
}
public static void sendPrintString() {
String dataToPrint =
"~CREATE;C39;72\n" +
"SCALE;DOT\n" +
"PAGE;30;40\n" +
"ALPHA\n" +
"C10;1;33;0;0;@HELLO@\n" +
"C16;54;37;0;0;@*World*@\n" +
"STOP\n" +
"BARCODE\n" +
"C128C;XRD3:3:6:6:9:9:12:12;H6;10;32\n" +
"@World@\n" +
"STOP\n" +
"END\n" +
"~EXECUTE;C39\n" +
"~NORMAL\n";
try {
comm.Open();
if (comm.Connected()) {
byte[] outBytes = dataToPrint.getBytes("US-ASCII");
comm.Write(outBytes);
} else {
System.out.println("Not connected to printer");
}
} catch (Exception e) {
System.out.println("Exception Msg: " + e.getMessage());
} finally {
comm.Close();
}
}
}