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)
Forum Updated to NodeBB v4.3 + New Features

Send string to USB virtual port USB001 (Windows)

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 5.4k Views 2 Watching
  • 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 8 Dec 2017, 12:37 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
    • V Offline
      V Offline
      VRonin
      wrote on 8 Dec 2017, 12:50 last edited by VRonin 12 Aug 2017, 12:54
      #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 8 Dec 2017, 14:34
      3
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 8 Dec 2017, 14:15 last edited by mrjj 12 Aug 2017, 15:42
        #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 8 Dec 2017, 14:58
        3
        • V VRonin
          8 Dec 2017, 12:50

          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 8 Dec 2017, 14:34 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
          • M mrjj
            8 Dec 2017, 14:15

            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 8 Dec 2017, 14:58 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.

            M 1 Reply Last reply 8 Dec 2017, 15:47
            0
            • A AleksM
              8 Dec 2017, 14:58

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 8 Dec 2017, 15:47 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
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 8 Dec 2017, 16:14 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 12 Dec 2017, 11:03
                2
                • M mrjj
                  8 Dec 2017, 16:14

                  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 12 Dec 2017, 11:03 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.

                  A M 2 Replies Last reply 12 Dec 2017, 11:38
                  0
                  • A AleksM
                    12 Dec 2017, 11:03

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

                    A Offline
                    A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 12 Dec 2017, 11:38 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 13 Dec 2017, 08:59
                    1
                    • A AleksM
                      12 Dec 2017, 11:03

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

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 12 Dec 2017, 13:59 last edited by mrjj 12 Dec 2017, 14:15
                      #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
                      • A aha_1980
                        12 Dec 2017, 11:38

                        @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 13 Dec 2017, 08:59 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

                        9/11

                        12 Dec 2017, 11:38

                        • Login

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