|
| | 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();
}
}
}