Skip to content

Commit

Permalink
add 2 button for testing printer thermal 80mm and 58 mm
Browse files Browse the repository at this point in the history
  • Loading branch information
denitiawan committed May 23, 2023
1 parent caf7703 commit 3311d3d
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 15 deletions.
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-react-boilerplate",
"version": "4.6.0",
"version": "0.0.1",
"description": "A foundation for scalable desktop apps",
"license": "MIT",
"author": {
Expand Down
76 changes: 73 additions & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AppUpdater {
let mainWindow: BrowserWindow | null = null;


ipcMain.on('ipc-escpos', async () => {
ipcMain.on('ipc-escpos-printer-80', async () => {
console.log('IPC ESCPOS STARTING --------');

try {
Expand All @@ -38,8 +38,7 @@ ipcMain.on('ipc-escpos', async () => {
console.log(escpos.USB.findPrinter()); // for see printer spesification (idVendor & idProduct)

// register idVendor & idProduct Printer
const device = new escpos.USB(4070, 33054); // Printer VSC TM 801
//const device = new escpos.USB(2501,22750); // Printer C58BT
const device = new escpos.USB(4070, 33054); // Printer VSC TM 801
const printer = new escpos.Printer(device); // initialize printer


Expand Down Expand Up @@ -98,6 +97,77 @@ ipcMain.on('ipc-escpos', async () => {
}
});

ipcMain.on('ipc-escpos-printer-58', async () => {
console.log('IPC ESCPOS STARTING --------');

try {


const escpos = require('escpos'); // import lib escpos
escpos.USB = require('escpos-usb'); // create usb adapter
console.log(escpos.USB.findPrinter()); // for see printer spesification (idVendor & idProduct)

// register idVendor & idProduct Printer
const device = new escpos.USB(2501,22750); // Printer C58BT
const printer = new escpos.Printer(device); // initialize printer


let qrUrl = 'https://github.com/denitiawan';


// templating
device.open(() => {

// print text
printer.align('lt').text('');
printer.align('ct').text('Test Printing');
printer.align('ct').text('Electron React Boilerplate');
printer.align('lt').text('');

printer.align('ct').text('By Deni Setiawan');
printer.align('ct').text('NexSOFT');
printer.align('lt').text('');

printer.align('ct').text('Feature Support : ');
printer.align('ct').text('Printout Text');
printer.align('ct').text('Printout Barcode (CODE39)');
printer.align('ct').text('Printout QR Code');
printer.align('ct').text('Cut Papper');
printer.align('ct').text('Open Cash Drawer');
printer.align('lt').text('');


// Print Barcode
printer.align('ct').barcode('CODE39', 'CODE39');
printer.align('ct').text('');


// Print QR Code
printer.align('ct').text('Scan Me').style('B');
printer.align("ct").qrimage(qrUrl, function (err) {
printer.align('ct').text(qrUrl);
printer.align('ct').text('17-mei-2023 13:12');
printer.align('ct').text('');
printer.align('ct').text('');

// print action
printer.cut();
printer.cashdraw(2);
printer.close();
});




});

}
catch (error) {
console.log(error);
alert(error)
}
});

ipcMain.on('ipc-example', async (event, arg) => {
const msgTemplate = (pingPong: string) => `IPC test: ${pingPong}`;
console.log(msgTemplate(arg));
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import PrinterComponent from './printhermal/PrinterComponent';
function Hello() {
return (
<div>
<h1>Electron React Boilerplate</h1>
<h2>v4.6.0 (Latest)</h2>
<br/>
<br/>
<PrinterComponent />
<h1>Electron React Boilerplate</h1>
<h2>Electron Version : v4.6.0</h2>
<br/>
<PrinterComponent />

</div>
);
Expand Down
20 changes: 16 additions & 4 deletions src/renderer/printhermal/PrinterComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { PrinterEscPosService } from './PrinterEscPosService';

export default function PrinterComponent() {
function doTestPrint() {
PrinterEscPosService.doPrint();
function doTestPrinter80() {
PrinterEscPosService.doTestPrinter80();
}
function doTestPrinter58() {
PrinterEscPosService.doTestPrinter58();
}

return (
<div>
<button type="button" onClick={() => doTestPrint()}>
Test Printing

<h2>App Version : 0.0.1</h2>
<br/>

<button type="button" onClick={() => doTestPrinter80()}>
Test Printer 80mm
</button>
<br />
<br />
<button type="button" onClick={() => doTestPrinter58()}>
Test Printer 58mm
</button>
<br />
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/printhermal/PrinterEscPosService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@


export const PrinterEscPosService = {
doPrint() {
window.electron.ipcRenderer.sendMessage('ipc-escpos');
doTestPrinter80() {
window.electron.ipcRenderer.sendMessage('ipc-escpos-printer-80');
},
doTestPrinter58() {
window.electron.ipcRenderer.sendMessage('ipc-escpos-printer-58');
},
};

0 comments on commit 3311d3d

Please sign in to comment.