ng-thermal-print icon indicating copy to clipboard operation
ng-thermal-print copied to clipboard

Not connected to printer

Open yaxx opened this issue 5 years ago • 24 comments

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

yaxx avatar Jan 02 '20 17:01 yaxx

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

bebo925 avatar Jan 16 '20 15:01 bebo925

@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 ?

DCode11 avatar Jan 31 '20 11:01 DCode11

@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

C2418M31 avatar Feb 20 '20 22:02 C2418M31

@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);
    }

bebo925 avatar Mar 02 '20 12:03 bebo925

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 avatar Mar 03 '20 07:03 PhanithNoch

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

PhanithNoch avatar Mar 03 '20 07:03 PhanithNoch

I really need this help, please

PhanithNoch avatar Mar 03 '20 07:03 PhanithNoch

I really need this help, please

try to install -> npm i webusb

C2418M31 avatar Mar 03 '20 10:03 C2418M31

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

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

amaneer94 avatar Jun 06 '20 09:06 amaneer94

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

NithMario avatar Jun 08 '20 04:06 NithMario

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.

mcvendrell avatar Oct 22 '20 18:10 mcvendrell

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.');
            }
        });
    }
  • NOTE : In the above sinippet result is always false

AlluNandaKishore avatar Nov 04 '20 08:11 AlluNandaKishore

@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

mcvendrell avatar Nov 04 '20 09:11 mcvendrell

@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.

AlluNandaKishore avatar Nov 04 '20 09:11 AlluNandaKishore

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.

mcvendrell avatar Nov 04 '20 09:11 mcvendrell

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 ?

AlluNandaKishore avatar Nov 05 '20 05:11 AlluNandaKishore

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

mcvendrell avatar Nov 05 '20 07:11 mcvendrell

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.

AlluNandaKishore avatar Nov 05 '20 08:11 AlluNandaKishore

@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

adnannrajaa avatar Oct 03 '22 13:10 adnannrajaa

@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

mcvendrell avatar Oct 04 '22 09:10 mcvendrell

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

mohamed-mostafa10 avatar Nov 14 '22 11:11 mohamed-mostafa10

@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

adnannrajaa avatar Nov 14 '22 14:11 adnannrajaa

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

mcvendrell avatar Nov 15 '22 08:11 mcvendrell

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

Ankit199 avatar Oct 06 '23 06:10 Ankit199