Skip to content

Commit 62a7642

Browse files
committed
refactoring TCP class + update documentation
1 parent aac2dbd commit 62a7642

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ The code below is an example to write in your activity :
151151
new Thread(new Runnable() {
152152
public void run() {
153153
try {
154-
EscPosPrinter printer = new EscPosPrinter(new TcpConnection("192.168.1.3", 9300), 203, 48f, 32);
154+
EscPosPrinter printer = new EscPosPrinter(new TcpConnection("192.168.1.3", 9300, 15), 203, 48f, 32);
155155
printer
156156
.printFormattedText(
157157
"[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, getApplicationContext().getResources().getDrawableForDensity(R.drawable.logo, DisplayMetrics.DENSITY_MEDIUM)) + "</img>\n" +
@@ -397,6 +397,13 @@ Easy way to get the first bluetooth printer paired / connected.
397397
Get a list of bluetooth printers.
398398
- **return** `BluetoothConnection[]`
399399

400+
### Class : `com.dantsu.escposprinter.connection.tcp.TcpConnection`
401+
402+
#### Constructor : `TcpConnection(String address, int port[, int timeout])`
403+
- **param** `String address` : Targeted ip address
404+
- **param** `int port` : Targeted tcp port
405+
- **param** `int timeout` *(optional)* : Connection timeout.
406+
400407
### Class : `com.dantsu.escposprinter.connection.usb.UsbPrintersConnections`
401408

402409
#### **Static** Method : `selectFirstConnected()`

escposprinter/src/main/java/com/dantsu/escposprinter/connection/tcp/TcpConnection.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class TcpConnection extends DeviceConnection {
1313
private Socket socket = null;
1414
private String address;
1515
private int port;
16-
private int timeout = 0;
16+
private int timeout;
1717

1818
/**
1919
* Create un instance of TcpConnection.
@@ -22,9 +22,7 @@ public class TcpConnection extends DeviceConnection {
2222
* @param port Port of the device
2323
*/
2424
public TcpConnection(String address, int port) {
25-
super();
26-
this.address = address;
27-
this.port = port;
25+
this(address, port, 30);
2826
}
2927

3028
/**
@@ -69,10 +67,6 @@ public TcpConnection connect() throws EscPosConnectionException {
6967
e.printStackTrace();
7068
this.disconnect();
7169
throw new EscPosConnectionException("Unable to connect to TCP device.");
72-
} catch (SocketTimeoutException e) {
73-
e.printStackTrace();
74-
this.disconnect();
75-
throw new EscPosConnectionException("Unable to connect to TCP device; exceeded timeout limit.");
7670
}
7771
return this;
7872
}

0 commit comments

Comments
 (0)