Printing using libusb - c++

Hello I am working on project that need to print directly to USB printer (POS printer). The application is running on Linux, right now i am using the usblp to print by write ESCP command directly to /dev/usb/lp0. Everything goes well, but the problem comes when user plug a printer that not detected as usblp on Linux.
So instead of depends on linux kernel usblp, I would like to directly write the data to USB device using libusb. So my question will be:
Is it OK to send directly the ESCP command to printer using libusb.
From the libusb docs, to open and configure usb device there are some step to do. Should I open and configure the usb when printing OR I open and configure once and keep it open so I don't need to open and close when I want to print?
If I want to open and close printer when I want print, is it fast for opening, configure, and claiming an USB device using libusb?

Related

Claim device is not working while using the EPSON TM-T88VI printer once we upgrade it to Advanced driver printer from ADK 270

My POS Terminal has installed the Epson driver ADK 2.70E for model EPSON TM-T88VI.
That time the printer was working fine from my POS Terminal application which is in C++.
The registry contains the key in \HKEY_CLASSES_ROOT\OPOS.POSPrinter
enter image description here
In Device MAnager,
the device is displaying in the USB prot.
enter image description here
In Devices, it is displaying in the Unspecified category,
enter image description here
And from my application it is working fine without any problem.
Then I Installed the advanced driver version APD 512E on top of it.
And then try to print the receipt from my application which uses C++
code the print is not happening.
The OPOS error returning as 106 during the claimDevice funciton.
Device MAnager,
enter image description here
Devices,
enter image description here
If I uninstall the Advanced driver it is working fine from my application, like to know y it not working once we upgrade it to Advanced driver ?
Is there any Language compatibility is there, that c++ is not compatible for this Advanced driver ?
You should be concerned with hardware and software mode settings and related APIs, whether C++ or not.
Advanced Printer Driver and OPOS ADK are exclusive and can be used with only one of the settings.
If you want to use OPOS, delete the TM-T88VI related information from the Windows printer list and printer queue, and uninstall Advanced Printer Driver.
If you want to update OPOS, please get it from the above link and update it.
In response to comments:
As per the question in your comment. However, it depends on the hardware settings. It cannot be handled simply by changing the API used.
If you want to use Advanced Printer Driver, you need to use this utility to change the interface hardware settings from vendor class to printer class.
TM-T88VI Utility
Then print using the standard Windows desktop printer API.
Printing (Documents and Printing)
In that case, you will create image data for each page of the print content and print it as bit image data.
If you want to print using printer fonts, cut paper or open a cash drawer, you will need to create and embed RawPrinterHelper.
Send raw data to a printer by using the Win32 API
Print Direct To Windows Printer (EPOS Receipt)
How to send page cut command to Epson printer
Furthermore:
You probably can't use it like a question in a comment.
is that the behaviour of the driver or any other way to add the device to qindows printer without installing Advance printer drivers ?
To be able to use it as a Windows desktop printer, you need to install some printer driver, even if it is not an Advanced printer driver.
For example, it seems that it is no longer provided in windows 10, but before that there was a generic text only printer driver.
You will need to have some such driver installed.
And perhaps if you install the windows printer driver and create a print queue, it's likely that the connection port will be occupied at system startup and will not be available to others.
This corresponds to the phenomenon of "3. The OPOS error returning as 106 during the claimDevice funciton." In the question.
About: what u mentioning as hardware settings ?
This is the interface mode setting by the TM-T88VI Utility described above.
Printer class or Vendor class of USB.
However, if it is currently available in OPOS, you do not need to consider it.
Rather, it should not be changed.

How can I print to HDMI display on a Raspberry Pi

I can print debug messages to GDB console with printf or cout, but none of the data actually shows up on the HDMI display running on /dev/fb0
Is there a way to print data directly out on the display without having to write to /dev/fb0
This is Raspberry Pi 3, running Raspbian Lite OS
The program is supposed to run in the background from /etc/rc.local
From your comment it seems that you are running the HDMI in a text mode a framebuffer console on the HDMI (rather than something like X) and want to print messages to it.
For that purpose in most configurations, you can write to /dev/console
Code doing this would need to run as root (as something launched from rc.local would) or the permission of the device node would need to be changed.
You can also typically (as the owner or as root) write to the pty devices for GUI-mode terminals, ssh sessions, etc.
Finally note that there is the unix-style write command which would write to a user's terminal session(s).

Is there any way to respond in code to a Mac terminal window changing its contents?

I'm doing some embedded C++ development and I have a call stack being printed from my device to a Mac terminal via a UART.
I'd like to create a C++ app that somehow listens to the terminal output, detects a callstack, and automatically converts the addresses into symbols.
I can do the conversion, but I'm not sure if there's a way for my app to be notified when the terminal output has changed, or even to periodically poll the open terminals and extract their contents?

How to get information on the drive where the executable is located in c++

My app will be running from a USB key which have specific information like vendor-id, device-id, ... which I need.
I tried using libusb, but despite the fact that I still can't make it work properly, how could I find the right usb drive to get information from?
Note that I would like the code to be cross-platform, that's why I firstly choose libusb.
Edit :
I have found a program (usbviewer) that enumerates all usb ports and the specific informations on the drive when it's connected.
I have read the sources for linux, infos are directly extracted from /proc/bus/usb/devices, it's quite straightforward.
But on windows, to get usb node connection information, it takes about 1000 lines before you get the actual information in a data structure (enumerate hub controllers, root hubs, ports...).
libusb on the otherside force me to generate an INF file and install a driver via inf-wizard.exe for each device before I can reach the information (didn't try on linux though).
Edit 2 :
I have found a way to get the device serial number with Windows, Linux and Mac OS X (didn't try MAC OS X but it should work just as Linux). For Windows, I use the function GetVolumeInformation(), on Linux, to read the serial number of drives with a FAT filesystem, I read 4 bytes in the corresponding /dev/* file starting from 0x27 or 0x43 depending on the FAT version.
But this reading requieres a root access which the program won't have, and it seems to me a little bit unreliable.
Any ideas ?
I have found the solution that fits me, for thoses who are insterested.
For Windows :
I extract the serial number of the device from the registry knowing the drive letter : HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices\DosDevices\X:
For Unix :
I get the /dev file with the df command, then I read the link in /sys/block corresponding to the /dev file (e.g : The drive is /dev/sdb, I read link of /sys/block/sdb. Then I read the file serial which is located in the directory pointed by the link, 6x directory backwards.
Hope it helps.

Path to a USB Device in Windows

I would be using a USB hub to connect multiple devices. I want to fix a specific USB device to a particular slot. Then check if it is done properly.
The way I am planning to achieve this is to get the complete USB path like
PCIROOT(0)#PCI(1D00)#USBROOT(0)#USB(1)#USB(2)#USB(3)#USB(3)
I can get this particular string in w7 via device property but the same is not available in wXP.
You can build this path by using the SetupAPI.
The device manager is built with this.
You start with CM_Locate_DevNode and enumerate children with CM_Get_Child.
I strongly advise you against what you're planning to do. AFAIK a USB device MUST function regardless on the USB port it's plugged in. If you'll creating such a device, forget e.g. about the "Certified for Windows" logo.
Just handle WM_DEVICECHANGE message, then use e.g. WMI to search for the USB device you're interested in. Here's my article about it: that time I coded C# language, however WMI has C++ API as well.