UniPRT SDK  v2.0.0.1
com.UniPRT.Sdk.Comm.BTClassicConnection 類別 參考文件

實作藍牙經典(Bluetooth Classic)通訊的類別,並繼承自 AComm 類別。 更多...

類別com.UniPRT.Sdk.Comm.BTClassicConnection的繼承圖:
com.UniPRT.Sdk.Comm.AComm com.UniPRT.Sdk.Comm.IComm

公開方法(Public Methods)

 BTClassicConnection (String descriptor)
 根據 descriptor 字串初始化新實例。 更多...
 
 BTClassicConnection (long bt_address)
 根據 macAddress 初始化新實例。 需先與印表機進行藍牙配對後才能連線。 更多...
 
int BytesAvailable ()
 
String Descriptor ()
 
boolean Connected ()
 
void Close ()
 
void Open ()
 
byte[] Read ()
 
void Write (byte[] dataOut)
 
- 公開方法(Public Methods) 繼承自 com.UniPRT.Sdk.Comm.AComm
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
 將位元組資料寫入輸出流並返回接收到的資料。返回的資料是接收到的任何資料或收到的完成標記。等待回應超時後返回。 更多...
 

靜態公開方法(Static Public Methods)

static long DescriptorValidate (String descriptorHint)
 從 descriptorHint 驗證描述字串是否有效,可能包含或不包含 v_id 與 p_id。返回 long 值。 更多...
 

私有屬性

BluetoothAdapter mBluetoothAdapter = null
 
BluetoothSocket btSocket = null
 
OutputStream OutStream = null
 
InputStream InStream = null
 
long _bt_address
 

靜態私有屬性

static final UUID MY_UUID_SECURE = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
 
static final int BLOCK_SIZE = 1024
 

詳細描述

實作藍牙經典(Bluetooth Classic)通訊的類別,並繼承自 AComm 類別。

範例

package com.test.UniPRTSdk;
import java.io.*;
public class commBTClassicSnippet {
public static void test() {
sendPrintFile(); // send file over default printer data port
sendPrintString(); // send print data over default printer data port
}
public static void sendPrintFile() {
String fileName = "C:\\testFiles\\Hello.pgl";
BTClassicConnection ptrBTClassicComm = new BTClassicConnection(0x0080A3123456L); // sending through default data port
try {
ptrBTClassicComm.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) {
ptrBTClassicComm.Write(buffer);
}
}
} else {
System.out.println("File \"" + fileName + "\" not found");
}
} catch (Exception e) {
System.out.println("Exception Msg: " + e.getMessage());
} finally {
ptrBTClassicComm.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";
BTClassicConnection ptrBTClassicComm = new BTClassicConnection(0x0080A3123456L); // sending through default data port
try {
ptrBTClassicComm.Open();
if (ptrBTClassicComm.Connected()) {
byte[] outBytes = dataToPrint.getBytes("US-ASCII");
ptrBTClassicComm.Write(outBytes);
} else {
System.out.println("Not connected to printer");
}
} catch (Exception e) {
System.out.println("Exception Msg: " + e.getMessage());
} finally {
ptrBTClassicComm.Close();
}
}
}

建構子與解構子說明文件

◆ BTClassicConnection() [1/2]

com.UniPRT.Sdk.Comm.BTClassicConnection.BTClassicConnection ( String  descriptor)

根據 descriptor 字串初始化新實例。

參數
descriptor可接受格式:
  • "BT:MAC Address:<_bt_mac>"
    • _bt_mac 為 16 進位字串,例如:MAC Address:0080A3123456

參考 com.UniPRT.Sdk.Comm.BTClassicConnection._bt_address, 及 com.UniPRT.Sdk.Comm.BTClassicConnection.DescriptorValidate().

◆ BTClassicConnection() [2/2]

com.UniPRT.Sdk.Comm.BTClassicConnection.BTClassicConnection ( long  bt_address)

根據 macAddress 初始化新實例。 需先與印表機進行藍牙配對後才能連線。

參數
[in]macAddress透過藍牙 MAC 位址指定要連線的印表機,例如:0x0080A3123456L

函式成員說明文件

◆ BytesAvailable()

int com.UniPRT.Sdk.Comm.BTClassicConnection.BytesAvailable ( )

Get the number of bytes available to read.

傳回值
Number of bytes available to read.

實作 com.UniPRT.Sdk.Comm.IComm.

參考 com.UniPRT.Sdk.Comm.BTClassicConnection.InStream.

被參考於 com.UniPRT.Sdk.Comm.BTClassicConnection.Read().

◆ Close()

◆ Connected()

boolean com.UniPRT.Sdk.Comm.BTClassicConnection.Connected ( )

Check if connection is established.

傳回值
true if connection is established, otherwise false.

實作 com.UniPRT.Sdk.Comm.IComm.

參考 com.UniPRT.Sdk.Comm.BTClassicConnection.btSocket.

◆ Descriptor()

String com.UniPRT.Sdk.Comm.BTClassicConnection.Descriptor ( )

Get the string descriptor of the connection.

傳回值
String descriptor of the connection.

實作 com.UniPRT.Sdk.Comm.IComm.

參考 com.UniPRT.Sdk.Comm.BTClassicConnection._bt_address.

◆ DescriptorValidate()

static long com.UniPRT.Sdk.Comm.BTClassicConnection.DescriptorValidate ( String  descriptorHint)
static

從 descriptorHint 驗證描述字串是否有效,可能包含或不包含 v_id 與 p_id。返回 long 值。

可接受的 descriptorHint 格式:

  • "BT:MAC Address:<_bt_mac>"
    • _bt_mac 是 16 進位字串,例如:MAC Address:0080A3123456

被參考於 com.UniPRT.Sdk.Comm.BTClassicConnection.BTClassicConnection().

◆ Open()

◆ Read()

byte [] com.UniPRT.Sdk.Comm.BTClassicConnection.Read ( )

◆ Write()

void com.UniPRT.Sdk.Comm.BTClassicConnection.Write ( byte[]  dataOut)

Write all bytes from the array passed in.

參數
dataOutByte array to write.

實作 com.UniPRT.Sdk.Comm.IComm.

參考 com.UniPRT.Sdk.Comm.BTClassicConnection.BLOCK_SIZE, 及 com.UniPRT.Sdk.Comm.BTClassicConnection.OutStream.

資料成員說明文件

◆ _bt_address

◆ BLOCK_SIZE

final int com.UniPRT.Sdk.Comm.BTClassicConnection.BLOCK_SIZE = 1024
staticprivate

◆ btSocket

BluetoothSocket com.UniPRT.Sdk.Comm.BTClassicConnection.btSocket = null
private

◆ InStream

◆ mBluetoothAdapter

BluetoothAdapter com.UniPRT.Sdk.Comm.BTClassicConnection.mBluetoothAdapter = null
private

◆ MY_UUID_SECURE

final UUID com.UniPRT.Sdk.Comm.BTClassicConnection.MY_UUID_SECURE = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
staticprivate

◆ OutStream

OutputStream com.UniPRT.Sdk.Comm.BTClassicConnection.OutStream = null
private

此類別(class) 文件是由下列檔案中產生:
com.UniPRT.Sdk.Comm
Definition: AComm.java:1
com.UniPRT
com.UniPRT.Sdk.Comm.BTClassicConnection
實作藍牙經典(Bluetooth Classic)通訊的類別,並繼承自 AComm 類別。
Definition: BTClassicConnection.java:36
com.UniPRT.Sdk
com
com.UniPRT.Sdk.Comm.BTClassicConnection.BTClassicConnection
BTClassicConnection(String descriptor)
根據 descriptor 字串初始化新實例。
Definition: BTClassicConnection.java:129