mike42 / escpos-php

PHP library for printing to ESC/POS-compatible thermal and impact printers
Other
2.57k stars 862 forks source link

Error connecting usb modem #716

Open Sehp2019 opened 5 years ago

Sehp2019 commented 5 years ago

Currently I have a POS system in laravel 5.7 running on xampp in windows 7 locally. The machine is not connected to any network, everything works perfectly, but when you connect a USB modem or connect the phone and enable network anchoring, everything continues to work but when I disconnect the modem or the phone it generates the exception failed to open stream: no such file or directory. also when running windows + R and writing \ localhost shows me an error that I can not access but if I type \ pc name then it works. everything is spoiled when a modem or telephone connected to a network previously connected is disconnected. It is worth mentioning that if xampp is not started then I can connect USB modem and disconnect them and I can always access \ localhost. I have tried everything to solve this and have tried the different connectors, however nothing works. forgive me for my English, I'm from El Salvador

mike42 commented 5 years ago

Hi, would you mind sharing the commands you are running, and the PHP code that you're using now?

Network changes (due to the modem) are most likely causing the copy command from PHP to stop working.

If you have a command that works all the time to print text, then I should be able to show you how to achieve the same thing from PHP.

Sehp2019 commented 5 years ago

try { $nombre_impresora = "lr2000"; $connector = new WindowsPrintConnector($nombre_impresora); $printer = new Printer($connector); $printer->pulse(); $printer->close(); } catch(Exception $p) { echo "No es posible imprimir"; } return response()->json([ "mensaje" => 'Creado' ]);

This is my code, I have also managed to verify that when the modem is disconnected, the NETBIOS auxiliary application service over TCP / IP stops and this is what causes local resources to not be able to access local resources, since when the service starts again everything works perfect. if there was any way to restart this service in case of any failure, it would be perfect

mike42 commented 5 years ago

If you can find a way to keep that service running, then your problem may be solved. I was thinking about this though:

writing \ localhost shows me an error that I can not access but if I type \ pc name then it works.

The WindowsPrintConnector accepts a URL. You can try $nombre_impresora = "smb://computer-name/lr2000", for example, which is similar to copying a text file to \\computer-name\lr-2000 on the command-line.