Skip to content

Commit

Permalink
expose the printer version ,sn and modal to the constants
Browse files Browse the repository at this point in the history
expose the printer version ,sn and modal to the constants`
  • Loading branch information
januslo committed Aug 11, 2017
1 parent 44d1f1e commit 369cab7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ See examples folder of the source code that you can find a simple example of pri

## API

### Constants
| Name | Description|
|:-----:|:-----------:|
| Constants | 打印状态常量 |
| hasPrinter | boolean,是否有打印机 |
| printerVersion | 打印机固件版本 |
| printerSerialNo | 打印机序列号 |
| printerModal | 打印机型号 |


### Printer Status

| Name | Description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ public Map<String, Object> getConstants() {

constants.put("hasPrinter", hasPrinter());

try {
constants.put("printerVersion", getPrinterVersion());
}catch(Exception e){
// Log and ignore for it is not the madatory constants.
Log.i(TAG, "ERROR: " + e.getMessage());
}
try{
constants.put("printerSerialNo", getPrinterSerialNo());
}catch(Exception e){
// Log and ignore for it is not the madatory constants.
Log.i(TAG, "ERROR: " + e.getMessage());
}
try{
constants.put("printerModal",getPrinterModal());
}catch(Exception e){
// Log and ignore for it is not the madatory constants.
Log.i(TAG, "ERROR: " + e.getMessage());
}

return constants;
}

Expand Down Expand Up @@ -213,48 +232,65 @@ public void onRaiseException(int code, String msg){
@ReactMethod
public void getPrinterSerialNo(final Promise p) {
try {
final IWoyouService printerService = woyouService;
String sn = printerService.getPrinterSerialNo();
p.resolve(sn);
p.resolve(getPrinterSerialNo());
}
catch (Exception e) {
Log.i(TAG, "ERROR: " + e.getMessage());
p.reject("" + 0, e.getMessage());
}
}
private String getPrinterSerialNo()throws Exception{
final IWoyouService printerService = woyouService;
return printerService.getPrinterSerialNo();
}

/**
* 获取打印机固件版本号
*/
@ReactMethod
public void getPrinterVersion(final Promise p) {
try {
final IWoyouService printerService = woyouService;
String version = printerService.getPrinterVersion();
p.resolve(version);
p.resolve(getPrinterVersion());
}
catch (Exception e) {
Log.i(TAG, "ERROR: " + e.getMessage());
p.reject("" + 0, e.getMessage());
}
}
private String getPrinterVersion()throws Exception{
final IWoyouService printerService = woyouService;
return printerService.getPrinterVersion();
}

/**
* 获取打印机型号
*/
@ReactMethod
public void getPrinterModal(final Promise p){
//Caution: This method is not fully test -- Januslo 2018-08-11
try{
final IWoyouService printerService = woyouService;
String modal = printerService.getPrinterModal();
p.resolve(modal);
p.resolve(getPrinterModal());
}catch(Exception e){
Log.i(TAG, "ERROR: " + e.getMessage());
p.reject("" + 0, e.getMessage());
}
}

private String getPrinterModal()throws Exception{
//Caution: This method is not fully test -- Januslo 2018-08-11
final IWoyouService printerService = woyouService;
return printerService.getPrinterModal();
}

@ReactMethod
public void hasPrinter(final Promise p){
try{
p.resolve(hasPrinter());
}catch(Exception e){
Log.i(TAG, "ERROR: " + e.getMessage());
p.reject("" + 0, e.getMessage());
}
}

/**
* 是否存在打印机服务
* return {boolean}
Expand Down

1 comment on commit 369cab7

@januslo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#6

Please sign in to comment.