Skip to content

Commit

Permalink
feat(added): docs for Printer constructor and connect method, allow t…
Browse files Browse the repository at this point in the history
…o disconnect in case connection has lost
  • Loading branch information
tr3v3r committed May 7, 2024
1 parent 482c192 commit 9da6f38
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ synchronized public void disconnect() throws Epos2Exception {
} catch (Exception ignored) {
}
} else {
throw e;
if(((Epos2Exception) e).getErrorStatus() != Epos2Exception.ERR_ILLEGAL) {
throw e;
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions docs/printer/Printer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Printer

Class that controls the printer connection and printing functions.

## [constructor](./constructor.md)

Initializes the printer object.

#### Example

```typescript
const printer = new Printer({
target: "BT:00:22:15:7D:70:9C",
deviceName: "TM-T88V",
})
```

## Methods

### [connect(`timeout: string`): `Promise<void>`](./connect.md)

Starts communication with the printer.

#### Example

```typescript
await printerInstance.connect();
```
---
61 changes: 61 additions & 0 deletions docs/printer/connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## connect

Starts communication with the printer.

### Parameters

#### timeout *(optional)*

- `number`

Specifies the maximum time (in milliseconds) to wait for communication with the printer to be established.

| **Value** | **Description** | **Default** |
| --- | --- | --- |
| 1000 to 300000 | Maximum wait time before an error is returned (in milliseconds). | 15000 |

### Returns

`Promise<void>`

### Errors

| **Error status** | **Description** |
| --- | --- |
| ERR_PARAM | An invalid parameter was passed. |
| ERR_CONNECT | Failed to open the device. |
| ERR_TIMEOUT | Failed to communicate with the devices within the specified time. |
| ERR_ILLEGAL | Tried to start communication with a printer with which communication had been already established. Tried to start communication with a printer during reconnection process. |
| ERR_MEMORY | Necessary memory could not be allocated. |
| ERR_FAILURE | An unknown error occurred. |
| ERR_PROCESSING | Could not run the process. |
| ERR_NOT_FOUND | The printer could not be found. |
| ERR_IN_USE | The device was in use. |
| ERR_TYPE_INVALID | The device type is different. |
| ERR_RECOVERY_FAILURE | Failed to recover the printer. |

### Supplementary explanation

Android:

- When communication with the printer is no longer necessary, be sure to call disconnect to terminate it.
- If you are using DHCP to assign the IP address of the printer, specify the MAC address or host name of the
printer as the identifier.
- When connecting through the USB, the identifiers that can be specified differ depending on the shape of
the USB connector.
When the identifier is omitted, Android OS connects with the USB device found first.
When the Android terminal is set to the developer mode, you may not be able to connect through USB-
A - Device Charging.
- Devices other than printers are exclusively locked.
- If error with status ERR_RECOVERY_FAILURE occurs, restart the printer.

iOS:

- When communication with the printer is no longer necessary, be sure to call disconnect to terminate it.
- For TM-DT series, MAC address cannot be specified.
- When connecting with the printer using Bluetooth, complete pairing before calling the connect command.
- Depending on the project settings, Bluetooth communication may be disconnected if the application runs in the background.
- If Bluetooth and USB are used simultaneously, priority is given to the USB.
- Devices other than printers are exclusively locked.
- If error with status ERR_RECOVERY_FAILURE occurs, restart the printer.
- Since it takes time to send and receive a large amount of data with BLE connection, the following APIs not recommended be used. (addImage)
59 changes: 59 additions & 0 deletions docs/printer/constructor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Printer constructor

Initializes the printer object.

> [!NOTE]
> Implements singletone pattern. Return the same instance if the same target is passed.
### Parameters

#### target

- `string`

Specifies the method of connecting to the printer by a character string.
The connection method varies according to the system configuration. Can be retrieved from the [discovery](../discovery/discovery.md).

| **I/F** | **Connec-tion type** | **Identifier** | **Example** |
| --- | --- | --- | --- |
| Wi-Fi/Ethernet | "TCP" | - IP address in IPv4 format<br/> - MAC address<br/> - Host name | "TCP:192.168.192.168" |
| Bluetooth | "BT" | BD address | "BT:00:22:15:7D:70:9C" |
| USB | "USB" | - Device node<br/> - USB Serial number<br/> - Omitted | "USB:/dev/udev/*", "USB:00000000000000000", "USB:" |

---
#### deviceName

- `string`

The name set to the device is stored.

Example: `TM-T88V`

---
#### lang

- `enum PrinterModelLang`

Specifies the language of the printer.

| **Value** | **Description** |
| --- | --- |
| `PrinterConstants.MODEL_ANK` | ANK model |
| `PrinterConstants.MODEL_CHINESE` | Simplified Chinese model |
| `PrinterConstants.MODEL_TAIWAN` | Taiwan model |
| `PrinterConstants.MODEL_KOREAN` | Korean model |
| `PrinterConstants.MODEL_THAI` | Thai model |
| `PrinterConstants.MODEL_SOUTHASIA` | South Asian model |


Note: The default value is `PrinterConstants.MODEL_ANK`.

### Example
```typescript
const printer = new Printer({
target: "BT:00:22:15:7D:70:9C",
deviceName: "TM-T88V",
})
```


2 changes: 1 addition & 1 deletion ios/EscPosPrinter.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ + (BOOL)requiresMainQueueSetup
result = [thePrinter disconnect];
}

if(result == EPOS2_SUCCESS) {
if(result == EPOS2_SUCCESS || result == EPOS2_ERR_ILLEGAL) {
resolve(nil);
} else {
reject(@"event_failure", [@(result) stringValue], nil);
Expand Down

0 comments on commit 9da6f38

Please sign in to comment.