Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Send string to USB virtual port USB001 (Windows)
QtWS25 Last Chance

Send string to USB virtual port USB001 (Windows)

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AleksM
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      QSerialPort + QDataStream/QTextStream

      Please note you probably want to send a QLatin1String or a QByteArray rather than a QString

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      A 1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        Reminds me of the good old times where we did

        share virtual USB001 port as "printersharename"
        net use lpt1: \\computername\printersharename /persistent:yes
        COPY /B test.txt LPT1
        

        :)

        A 1 Reply Last reply
        3
        • VRoninV VRonin

          QSerialPort + QDataStream/QTextStream

          Please note you probably want to send a QLatin1String or a QByteArray rather than a QString

          A Offline
          A Offline
          AleksM
          wrote on last edited by
          #4

          @VRonin Thanks. I tried, but only COM1 is available in my system. USB001 is a virtual printer port (Win 7 and Win 10), or I need to do something extra to map it. No clue.

          1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Reminds me of the good old times where we did

            share virtual USB001 port as "printersharename"
            net use lpt1: \\computername\printersharename /persistent:yes
            COPY /B test.txt LPT1
            

            :)

            A Offline
            A Offline
            AleksM
            wrote on last edited by
            #5

            @mrjj Right, this works but it is not acceptable for the user to do net use when configuring the printer. Thanks.

            mrjjM 1 Reply Last reply
            0
            • A AleksM

              @mrjj Right, this works but it is not acceptable for the user to do net use when configuring the printer. Thanks.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @AleksM
              Well you could run it via QProcess and hook up from application but I agree
              its a bit hackish.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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-api

                Could be wrong though as i only dig around for some hours.

                A 1 Reply Last reply
                2
                • mrjjM mrjj

                  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-api

                  Could be wrong though as i only dig around for some hours.

                  A Offline
                  A Offline
                  AleksM
                  wrote on last edited by
                  #8

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

                  aha_1980A mrjjM 2 Replies Last reply
                  0
                  • A AleksM

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

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @AleksM Have you read this SO thread? https://stackoverflow.com/questions/4442122/send-raw-zpl-to-zebra-printer-via-usb

                    Qt has to stay free or it will die.

                    A 1 Reply Last reply
                    1
                    • A AleksM

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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @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";
                      }
                      
                      1 Reply Last reply
                      0
                      • aha_1980A aha_1980

                        @AleksM Have you read this SO thread? https://stackoverflow.com/questions/4442122/send-raw-zpl-to-zebra-printer-via-usb

                        A Offline
                        A Offline
                        AleksM
                        wrote on last edited by
                        #11

                        @aha_1980

                        Thanks 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 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved