bebo925 / ng-thermal-print

Angular module for connecting and printing to thermal printers.
MIT License
42 stars 44 forks source link

Not connected to printer #14

Open yaxx opened 4 years ago

yaxx commented 4 years ago

Hi, Bebo, am using Angular 8 with xprinter (thermal). The printer is connected via USB and was able print test page. I installed the package and set up my angular, but when i click the 'Connect to usb' button i get a pop with the header "http://locacalhost:4200 wants to connect" with options " Unknown device from intel corp() - paired" if i select i and click "Connect" button i get "Not connected in the browser console. Now if try connecting via web 'ip = localhost:4200' i get these error on the console.

"zone-evergreen.js:2952 POST http://localhost:4200/StarWebPRNT/SendMessage 404 (Not Found) scheduleTask @ zone-evergreen.js:2952 scheduleTask @ zone-evergreen.js:378 onScheduleTask @ zone-evergreen.js:272 scheduleTask @ zone-evergreen.js:372 scheduleTask @ zone-evergreen.js:211 scheduleMacroTask @ zone-evergreen.js:234 scheduleMacroTaskWithCurrentZone @ zone-evergreen.js:1107 (anonymous) @ zone-evergreen.js:2985 proto. @ zone-evergreen.js:1428 push../node_modules/ng-thermal-print/fesm2015/ng-thermal-print.js.StarWebPrintTrader.sendMessage @ ng-thermal-print.js:856 connect @ ng-thermal-print.js:955 setDriver @ ng-thermal-print.js:614 connectToWebPrint @ cashier.component.ts:163 eval @ CashierComponent.html:54 handleEvent @ core.js:43993 callWithDebugContext @ core.js:45632 debugHandleEvent @ core.js:45247 dispatchEvent @ core.js:29804 (anonymous) @ core.js:42925 (anonymous) @ platform-browser.js:2668 invokeTask @ zone-evergreen.js:391 onInvokeTask @ core.js:39680 invokeTask @ zone-evergreen.js:390 runTask @ zone-evergreen.js:168 invokeTask @ zone-evergreen.js:465 invokeTask @ zone-evergreen.js:1603 globalZoneAwareCallback @ zone-evergreen.js:1629 cashier.component.ts:81 Not connected to printer

Please what am i missing. Thanks

bebo925 commented 4 years ago

@yaxx Chrome one Windows requires you to allow web usb. Visit chrome://flags and make sure the Web USB flag is checked.

DCode11 commented 4 years ago

@bebo925

Hi, This worked for me for USB thermal printer, but need to connect to the printer from browser popup every time after page refreshes, so is there any solution that browser connects to the previously selected printer ?

C2418M31 commented 4 years ago

@bebo925

Hi, This worked for me for USB thermal printer, but need to connect to the printer from browser popup every time after page refreshes, so is there any solution that browser connects to the previously selected printer ?

This is also the issue I am dealing with. it needs every time to connect and there is no auto detection if already paired to a device. I hope this gets an update

bebo925 commented 4 years ago

@C2418M31 @DCode11 ,

You have to persist the vendorId and productId (in that order) from the USBDevice object returned on requestUSB function. You can then reuse those ids in the USBDriver class to automatically/silently reconnect.

Here is an example of how it would work:

//on request
requestPrinter() {
    this.usbDriver.requestUsb().subscribe((result) => {
      let language = (result.vendorId === 1305)?'StarPRNT': 'ESC/POS';

      localStorage.setItem('printer-device', JSON.stringify({ vendorId: result.vendorId, productId: result.productId }));
      this.printService.setDriver(new UsbDriver(result.vendorId, result.productId), language);
    });
  }
//to silently reconnect
if (localStorage.getItem('printer-device')) {
      device = JSON.parse(localStorage.getItem('eos-printer-device'));
      this.usbDriver = new UsbDriver(device.vendorId, device.productId);
      let language = (device.vendorId === 1305)?'StarPRNT': 'ESC/POS';
      this.printService.setDriver(this.usbDriver, language);
    }
PhanithNoch commented 4 years ago

I got error can't connect to the printer whenever try to click connect to printer chrome dialog show but no device to connect

PhanithNoch commented 4 years ago

@C2418M31 When I connect to the printer browser popup will be alert but unknown device how to solve this?

PhanithNoch commented 4 years ago

I really need this help, please

C2418M31 commented 4 years ago

I really need this help, please

try to install -> npm i webusb

amaneer94 commented 4 years ago

https://github.com/bebo925/ng-thermal-print/issues/14#issuecomment-593808430

I am getting the same problem. Any progress on it?

NithMario commented 4 years ago

I found a solution to fix that error but it works only on mac

mcvendrell commented 3 years ago

Ok guys, if you are getting this error when trying to get USB devices: Cannot read property 'requestDevice' of undefined at Observable._subscribe (ng-thermal-print.js:1037) in your server, but all is running in localhost, the official doc about USB.requestDevice() says This feature is available only in secure contexts (HTTPS) This happened to me too, simply making server secure fixed the problem. I will do a better READ.ME and will send a PR to improve documentation for future users.

AlluNandaKishore commented 3 years ago

Hi, I'd tried the same library to print, but it is not even connected to printer. As the document verifies to check the connection status, it never get connected. https://www.npmjs.com/package/ng-thermal-print.

 constructor(private printService: PrintService) {
        this.usbPrintDriver = new UsbDriver();
        this.printService.isConnected.subscribe(result => {
            this.status = result;
            if (result) {
                console.log('Connected to printer!!!');
            } else {
            console.log('Not connected to printer.');
            }
        });
    }
mcvendrell commented 3 years ago

@AlluNandaKishore I can confirm that this works, I'm using currently in my project. Try to read my improved docs (PR approval pending) to see if that clarifies something: https://github.com/mcvendrell/ng-thermal-print/tree/patch-1

AlluNandaKishore commented 3 years ago

@AlluNandaKishore I can confirm that this works, I'm using currently in my project. Try to read my improved docs (PR approval pending) to see if that clarifies something: https://github.com/mcvendrell/ng-thermal-print/tree/patch-1

Thanks, @mcvendrell . But, I was trying it from last two days. I couldn't see the printer connected log at least once the constructor part. I'm also trying it to run in localhost itself with windows OS and Chrome browser. Would you like to suggest me anything.

mcvendrell commented 3 years ago

Thanks, @mcvendrell . But, I was trying it from last two days. I couldn't see the printer connected log at least once the constructor part. I'm also trying it to run in localhost itself with windows OS and Chrome browser. Would you like to suggest me anything.

Your printer is shown when you click in "Connect to USB" button in the examples?

Did you read this part of my docs? WebUSB specification is still in progress, so you can get problems with later implementations. The main problem I found is that Windows can "reclaim" your printer if you install certified drivers, making your printer invisible to WebUSB call requestUsb() (so, you can't choose it to connect). In that case, a program called Zadig (https://zadig.akeo.ie/) will let you to "free" the printer by changing the current "proprietary" printer driver to the standart WinUSB driver. After that change, printer will be available in the list.

AlluNandaKishore commented 3 years ago

Thanks, @mcvendrell . But, I was trying it from last two days. I couldn't see the printer connected log at least once the constructor part. I'm also trying it to run in localhost itself with windows OS and Chrome browser. Would you like to suggest me anything.

Your printer is shown when you click in "Connect to USB" button in the examples?

Did you read this part of my docs? WebUSB specification is still in progress, so you can get problems with later implementations. The main problem I found is that Windows can "reclaim" your printer if you install certified drivers, making your printer invisible to WebUSB call requestUsb() (so, you can't choose it to connect). In that case, a program called Zadig (https://zadig.akeo.ie/) will let you to "free" the printer by changing the current "proprietary" printer driver to the standart WinUSB driver. After that change, printer will be available in the list.

Yes, thanks @mcvendrell . It's connected on installing the driver. Can this support & print, images/QR codes along with multiple slips at once ?

mcvendrell commented 3 years ago

It's connected on installing the driver.

Great

Can this support & print, images/QR codes along with multiple slips at once ?

This driver only supports text currently, but anyone can try to extend it with some ESP/POS knowledge

AlluNandaKishore commented 3 years ago

It's connected on installing the driver.

Great

Can this support & print, images/QR codes along with multiple slips at once ?

This driver only supports text currently, but anyone can try to extend it with some ESP/POS knowledge

Thank you.

adnannrajaa commented 1 year ago

@mcvendrell Here is the attached Snapshot, i clone your repo mention in above thread also tried Zadig (https://zadig.akeo.ie/) but nothing works for me, can some one guide me? image

mcvendrell commented 1 year ago

@mcvendrell Here is the attached Snapshot, i clone your repo mention in above thread also tried Zadig (https://zadig.akeo.ie/) but nothing works for me, can some one guide me? image

Why did you set the IP? Are you checking WebPRNT or the Connect to USB button? The last one is the only I checked that works. And you need a local usb printer and Chrome

mohamed-mostafa10 commented 1 year ago

1221 hi @mcvendrell I have read the documentation well and followed all the steps, and I changed more than one type of printer and the problem is still that I cannot make a connection to the printer, it always shows me in Chrome the status is false and always not connected .

Please Im really need help

adnannrajaa commented 1 year ago

@mohamed-mostafa10, @mcvendrell i tried everything but its doesn't work for me, soo i design my own solution, that's work's for me.

@mohamed-mostafa10 if you need that solution, then let me know

mcvendrell commented 1 year ago

hi @mcvendrell I have read the documentation well and followed all the steps, and I changed more than one type of printer and the problem is still that I cannot make a connection to the printer, it always shows me in Chrome the status is false and always not connected .

Please Im really need help

Hi @mohamed-mostafa10, all I can say you is I just tested the project again and it is working perfectly, as this image shows:

chrome_CG8318VWkU

An important question is: did you change the driver of your printer to use WinUSB driver? Read my improved docs, final part, to see if that clarifies something: https://github.com/mcvendrell/ng-thermal-print/tree/patch-1

Ankit199 commented 11 months ago

I am facing the same issue with printer CA-410-UB . i am getting always false in result