Send string to USB virtual port USB001 (Windows)
-
wrote on 8 Dec 2017, 12:37 last edited by
My Windows application needs to send a QString to the USB001 port in order to print a document to a specific printer (ZPL format to a Zebra printer). Ideally I would copy a file to that port or send it somehow.
Anybody has an advice?
Related problem with QPrinter is posted here.
-
wrote on 8 Dec 2017, 12:50 last edited by VRonin 12 Aug 2017, 12:54
QSerialPort + QDataStream/QTextStream
Please note you probably want to send a QLatin1String or a QByteArray rather than a QString
-
Lifetime Qt Championwrote on 8 Dec 2017, 14:15 last edited by mrjj 12 Aug 2017, 15:42
Hi
Reminds me of the good old times where we didshare virtual USB001 port as "printersharename" net use lpt1: \\computername\printersharename /persistent:yes COPY /B test.txt LPT1
:)
-
QSerialPort + QDataStream/QTextStream
Please note you probably want to send a QLatin1String or a QByteArray rather than a QString
-
Hi
Reminds me of the good old times where we didshare virtual USB001 port as "printersharename" net use lpt1: \\computername\printersharename /persistent:yes COPY /B test.txt LPT1
:)
-
@mrjj Right, this works but it is not acceptable for the user to do net use when configuring the printer. Thanks.
@AleksM
Well you could run it via QProcess and hook up from application but I agree
its a bit hackish. -
Hi
Just as a note.
As far as i know, its not possible with QPainter to send raw commands
to a printer and native API may be the only solution
https://support.microsoft.com/en-us/help/138594/howto-send-raw-data-to-a-printer-by-using-the-win32-apiCould be wrong though as i only dig around for some hours.
-
Hi
Just as a note.
As far as i know, its not possible with QPainter to send raw commands
to a printer and native API may be the only solution
https://support.microsoft.com/en-us/help/138594/howto-send-raw-data-to-a-printer-by-using-the-win32-apiCould be wrong though as i only dig around for some hours.
wrote on 12 Dec 2017, 11:03 last edited by@mrjj Thanks, mrjj! This is an alternative, but probably a QProcess with print batch file is more acceptable. Copy to network printer works within a batch file, but not with QFile::copy() !?
I am just curious if I can use USB001 port directly, from QT, but I am out of ideas at the moment.
-
@mrjj Thanks, mrjj! This is an alternative, but probably a QProcess with print batch file is more acceptable. Copy to network printer works within a batch file, but not with QFile::copy() !?
I am just curious if I can use USB001 port directly, from QT, but I am out of ideas at the moment.
@AleksM Have you read this SO thread? https://stackoverflow.com/questions/4442122/send-raw-zpl-to-zebra-printer-via-usb
-
@mrjj Thanks, mrjj! This is an alternative, but probably a QProcess with print batch file is more acceptable. Copy to network printer works within a batch file, but not with QFile::copy() !?
I am just curious if I can use USB001 port directly, from QT, but I am out of ideas at the moment.
Lifetime Qt Championwrote on 12 Dec 2017, 13:59 last edited by mrjj 12 Dec 2017, 14:15@AleksM
I think cmd copy /b knows the something about LPT1 that
QFile::copy do not. (since LPT1 is a special target)Note:
While doing research i did see, and comments suggested it worked but
i have not tested it.std::ifstream input("c:\\test", std::ios::binary); if (input) { std::ofstream("lpt1", std::ios::binary) << input.rdbuf(); } else { std::cerr << "ERROR: failed to open 'c:\\test' for reading\n"; }
-
@AleksM Have you read this SO thread? https://stackoverflow.com/questions/4442122/send-raw-zpl-to-zebra-printer-via-usb
wrote on 13 Dec 2017, 08:59 last edited byThanks aha_1980! I did not read it before. It is promising, but it does not work for me yet.
There are some fragments of the ZPL in a saved file (instead of printing), but some parts are transformed and some tags are added before and after. I need to experiment and troubleshoot a bit more.
1/11