@drake24 I’m not sure I understand your question. Why are you printing numbers to a thermal printer? What numbers are these? You have read using PHP’s fwrite function for what? Writing to a printer? And planning on making a design for what?
Printing on a Thermal Paper
Hi,
I am planning on making a queuing system. I do have a problem with regards with printing the numbers on a thermal printer. I have read using php fwrite. But is there an easier way to do it on Laravel? and I am planning on making a design for it.
Thanks,
Laravel and PHP are server side components. How will you attach your thermal printer to the server?
If you are talking to the printer directly then you will need to understand its command language and find a means to stream these commands to the printer. You will need an engineer familiar with your server technology to do it server side and your printer and server would need to be on the same network.
If the printer will actually be connected to a PC then you have a front-end issue, not Laravel specifically. You could use javascript in a separate browser tab to receive messages sent from the server through something like www.pusher.com and forward them on to the printer.
@martinbean It is actually a queuing system. For example if it is a general transaction it will print G01, G02 etc, Cashier, C01,C02. and so on. For the design I was thinking of designing the output of the printed or generated file. Somewhat as a simple layout below.
| CASHIER TRANS |
| NO: CO1 |
If you happen to see on most POS system that issues a receipt, I think you will get the picture.
@Snapey We are talking about 9 PC's. There will a single PC that it's sole job is printing numbers. I will be using a Bixolon Thermal Printer and it will be connected via USB to the PC that will be printing the numbers. Think of it as a POS type of system. I think Javascript would be okay, what I meant about Laravel, is that is there a class that can easily communicate with the printer via USB. I have searched, and they are telling me using the fwrite method in PHP that can pass commands via USB and I'm not pretty sure what they really mean about it. :)
@drake24 I actually looked into this last year as a prospect came to me wanting to set up a takeaway delivery site, where restaurants could house a printer and the website would send them orders (a Just Eat clone, basically). Unfortunately, the project never went ahead.
Each printer would have a different method of communicating to it. The units we were looking at actually had SIM cards, and communication was via SMS. So you would send a payload via SMS to the printer, and the printer would then print the information.
If you have multiple PCs with printers attached, then you’re not going to be able to write directly to the printer’s input stream using the fwrite() function from your single PHP instance. You’re going to need some sort of software running on each PC, which your PHP app sends a message to, and the PC software then delivers the message to the printer.
Unfortunately there’s not a nice PHP class for doing this as each printer is different, and we’re talking about hardware components here and not web-based components. Web servers and web applications aren’t meant to talk to hardware.
The first thing that comes to my mind is using a long polling service, such as Pusher or PubNub, and handle this in the front end with either a computer program or web browser running on each computer.
In this case, the logic would be handled in the back-end with requests to print something pushed to the client side.
Think of this in terms of a software based fax machine, always connected and waiting for a message to print. The polling service is the phone line, the server makes the call and the browser / program answers.
My thoughts here is that writing directly to the usb sounds like a lot of work. Printers generally have their own drivers and every OS has a print queue handler so why not use that. Then all your app has to do is send the document to the print queue and the OS will handle the rest.
If you are on Linux then use something like this:
exec("lpr -P 'printer' -r 'filename.txt');
or, for Windows
exec("print /d:LPT2: C:\filename.txt");
Have a look at how some of the big SaaS epos providers do it.
The likes of Vend support a very limited set of thermal printers, usually printers that have an ethernet connection and an IP address. If I remember correctly Vend will only support a couple of models from Star and Epson. There's a very good reason why that's the case as you're discovering.
The other alternative is using a thermal printer that comes bundles with a cloud print service. You connect the printer to the cloud and you send prints via the cloud.
The downside to both of those approaches is the initial cost of the printers is 3 - 5 times more than an el cheapo no-name thermal printer. I think I paid about €500 for a Star TSP100 thermal printer with an ethernet port.
@drake24 You won't find a PHP class to drive a USB printer because the PHP is running on the server and the printer is most likely attached to a client.
Have a look at this project; https://code.google.com/p/jzebra/
So, your server decides it needs to print something (your Laravel / PHP code) You send a message to a queue such as Pusher (pusher.com) for a specific printer A browser at the client end is running the QZ Print Java plugin and listening to a specific queue It receives the message via pusher and then passes this data to QZ print QZ Print sends the data to the attached printer.
You then have an additional choice. Do you format the string of printer commands at your server (and the client just passes it through), or do you send a command to the client ie 'cashier:05' and the code in the client decides how to render that for the specific printer language being used.
Good luck!
You could try using https://www.printnode.com which is essentially exactly the service that you are looking for. You download and install a desktop client onto the users computer - https://www.printnode.com/download. You can then discover and print to any printers on that user's computer using their JSON API https://www.printnode.com/docs/api/curl/. They have lots of libs here: https://github.com/PrintNode/
Please or to participate in this conversation.