Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Sending and Receiving ASCII of USB ports [solved]

Sending and Receiving ASCII of USB ports [solved]

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpdotnethelptutorialquestion
15 Posts 2 Posters 2 Views 1 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.
  • F Offline
    F Offline
    Fabio Franco
    wrote on last edited by
    #1

    Hi, I've been trying to figure out how to send commands for a printer installed in a USB port. Previously I could do this with the LPT1 port by calling kernel32.dll CreateFile method (DLLImport) and sending the commands this way. But with USB ports this doesn't work. So does anybody know how to do that? Or at least have any article on that matter, I couldn't find anything (sorry if its easy to find, I just suck at finding stuff). So my requirement is, cycle through USB ports to check if there is any device attached. If there is a device attached, send a command to ask the device to identify itself. So basically I'll need two things, learn to dynamically cycle through USB port, send commands to it and read the responses. All of that using C# and .Net Framework 2.0. Any ideas? Thanks in advance for any help. Regards, Fábio

    modified on Saturday, April 24, 2010 9:44 AM

    D 1 Reply Last reply
    0
    • F Fabio Franco

      Hi, I've been trying to figure out how to send commands for a printer installed in a USB port. Previously I could do this with the LPT1 port by calling kernel32.dll CreateFile method (DLLImport) and sending the commands this way. But with USB ports this doesn't work. So does anybody know how to do that? Or at least have any article on that matter, I couldn't find anything (sorry if its easy to find, I just suck at finding stuff). So my requirement is, cycle through USB ports to check if there is any device attached. If there is a device attached, send a command to ask the device to identify itself. So basically I'll need two things, learn to dynamically cycle through USB port, send commands to it and read the responses. All of that using C# and .Net Framework 2.0. Any ideas? Thanks in advance for any help. Regards, Fábio

      modified on Saturday, April 24, 2010 9:44 AM

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      How to send raw data to a printer by using Visual C# .NET[^] By the way, USB is an expansion BUS, not unlike the slots inside your machine. It does not work like a port, like a Serial or Parallel port.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        How to send raw data to a printer by using Visual C# .NET[^] By the way, USB is an expansion BUS, not unlike the slots inside your machine. It does not work like a port, like a Serial or Parallel port.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        F Offline
        F Offline
        Fabio Franco
        wrote on last edited by
        #3

        That's great!!! For now you solved my needs. But soon I will also need to read from it. Hopefully I'll figure out on my own, studying the code and the spooler usage. Anyway, thanks a lot. And thank for clearing it about the fact that USB port is not really a port. 5!

        D 1 Reply Last reply
        0
        • F Fabio Franco

          That's great!!! For now you solved my needs. But soon I will also need to read from it. Hopefully I'll figure out on my own, studying the code and the spooler usage. Anyway, thanks a lot. And thank for clearing it about the fact that USB port is not really a port. 5!

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Reading from a printer? That's not going to happen by studying that code I kinked to. Then again, you haven't said WHAT you think your going to read or why you need it.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          F 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Reading from a printer? That's not going to happen by studying that code I kinked to. Then again, you haven't said WHAT you think your going to read or why you need it.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            F Offline
            F Offline
            Fabio Franco
            wrote on last edited by
            #5

            Sorry for that. Let me clear it out. I need to talk to the printer because it's a Zebra printer with RFID capability. What I will do is send ZPL commands to the port and read the response. Zebra receives ASCII commands and responds with ASCII too. There are several uses for the printer's responses, including telling the success of a RFID TAG write operation. Perhaps I will need another alternative to the spooler API to acomplish that. Thanks again for your help.

            D 1 Reply Last reply
            0
            • F Fabio Franco

              Sorry for that. Let me clear it out. I need to talk to the printer because it's a Zebra printer with RFID capability. What I will do is send ZPL commands to the port and read the response. Zebra receives ASCII commands and responds with ASCII too. There are several uses for the printer's responses, including telling the success of a RFID TAG write operation. Perhaps I will need another alternative to the spooler API to acomplish that. Thanks again for your help.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Yep. The spooler will not return anything to you. This kind of printer should have an SDK available from the manufacturer, making all of the code you just got moot.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              F 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Yep. The spooler will not return anything to you. This kind of printer should have an SDK available from the manufacturer, making all of the code you just got moot.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                F Offline
                F Offline
                Fabio Franco
                wrote on last edited by
                #7

                Yeah, I wish it did. I contacted Zebra and they don't have anything for .Net yet. They should have in the near future, but couldn't give any dates. And I need it now. That's why I was asking for a way to talk to the BUS, no matter the device. And if I get that, I'll also be able to use to talk to the fingerprint reader from Microsoft on another project of mine, which seems there is no SDK either, just the drivers. Thanks for your help

                D 1 Reply Last reply
                0
                • F Fabio Franco

                  Yeah, I wish it did. I contacted Zebra and they don't have anything for .Net yet. They should have in the near future, but couldn't give any dates. And I need it now. That's why I was asking for a way to talk to the BUS, no matter the device. And if I get that, I'll also be able to use to talk to the fingerprint reader from Microsoft on another project of mine, which seems there is no SDK either, just the drivers. Thanks for your help

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Fabio Franco wrote:

                  That's why I was asking for a way to talk to the BUS, no matter the device.

                  There's no such thing on USB. You have no choice but to talk to the DEVICE on the bus. You cannot treat the USB port like it was a serial or parallel port. That's like trying to communicate to a card inserted into an expansion slot on the motherboard by talking to the slot it's plugged into. You can't do it. If they don't have a .NET specific library, you've going to have to make do with either normal C-style library and P/Invoke the functions or, hopefully, they have a COM-based library that you can use. Just because they don't support .NET directly does not mean that your out of luck. It's just going to take more work.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008
                  But no longer in 2009...

                  F 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Fabio Franco wrote:

                    That's why I was asking for a way to talk to the BUS, no matter the device.

                    There's no such thing on USB. You have no choice but to talk to the DEVICE on the bus. You cannot treat the USB port like it was a serial or parallel port. That's like trying to communicate to a card inserted into an expansion slot on the motherboard by talking to the slot it's plugged into. You can't do it. If they don't have a .NET specific library, you've going to have to make do with either normal C-style library and P/Invoke the functions or, hopefully, they have a COM-based library that you can use. Just because they don't support .NET directly does not mean that your out of luck. It's just going to take more work.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007, 2008
                    But no longer in 2009...

                    F Offline
                    F Offline
                    Fabio Franco
                    wrote on last edited by
                    #9

                    I think I may have put the wrong words. What I really meant is talk to the device "through" the bus. There must be a way to choose a specific BUS to talk to a device. I mean, even if I develop something specific to the device, I need to know where it is connected to. I think about it in two ways: 1 - Make use of the device driver so it carries the messages for me. 2 - Find the device (in which "slot" its plugged in) and send the message myself. I will do the talking to the device myself, thats for sure. I just need to know how to FIND it! I know I don't talk to the USB, but I know I must use it to talk to the device, messages can't magically find it's way to the device. The USB must have an address I can find and talk through. That's where I'm stuck. How could I cycle through the USB slots on a computer, and send/receive messages through it? There must be a standard way to make use of the USB slots, how the device will understand my commands is not the problem, this I know how to do it already (as I said, done this in LPT1). Windows must have some Win32 APIs available to acomplish what I want. Or maybe the drivers of the USB to do it. This is where I'm lost. In your experience what do you think? Am I looking at it the wrong way? Thanks again

                    D 1 Reply Last reply
                    0
                    • F Fabio Franco

                      I think I may have put the wrong words. What I really meant is talk to the device "through" the bus. There must be a way to choose a specific BUS to talk to a device. I mean, even if I develop something specific to the device, I need to know where it is connected to. I think about it in two ways: 1 - Make use of the device driver so it carries the messages for me. 2 - Find the device (in which "slot" its plugged in) and send the message myself. I will do the talking to the device myself, thats for sure. I just need to know how to FIND it! I know I don't talk to the USB, but I know I must use it to talk to the device, messages can't magically find it's way to the device. The USB must have an address I can find and talk through. That's where I'm stuck. How could I cycle through the USB slots on a computer, and send/receive messages through it? There must be a standard way to make use of the USB slots, how the device will understand my commands is not the problem, this I know how to do it already (as I said, done this in LPT1). Windows must have some Win32 APIs available to acomplish what I want. Or maybe the drivers of the USB to do it. This is where I'm lost. In your experience what do you think? Am I looking at it the wrong way? Thanks again

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      Fabio Franco wrote:

                      I think I may have put the wrong words. What I really meant is talk to the device "through" the bus. There must be a way to choose a specific BUS to talk to a device. I mean, even if I develop something specific to the device, I need to know where it is connected to. I think about it in two ways: 1 - Make use of the device driver so it carries the messages for me. 2 - Find the device (in which "slot" its plugged in) and send the message myself. I will do the talking to the device myself, thats for sure. I just need to know how to FIND it!

                      That's what the SDK is for. Or, you can start with this article[^].

                      Fabio Franco wrote:

                      I know I don't talk to the USB, but I know I must use it to talk to the device, messages can't magically find it's way to the device. The USB must have an address I can find and talk through. That's where I'm stuck. How could I cycle through the USB slots on a computer, and send/receive messages through it?

                      Fabio Franco wrote:

                      how the device will understand my commands is not the problem, this I know how to do it already (as I said, done this in LPT1

                      Yeah, but do you know what you're "saying"?? What messages? How are they built? What is the structure for each command?? Without the SDK, you're talking complete gibberish. You're not sending the same messages you send over LPT1. These are Device commands, not escape codes your sending.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007, 2008
                      But no longer in 2009...

                      F 1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        Fabio Franco wrote:

                        I think I may have put the wrong words. What I really meant is talk to the device "through" the bus. There must be a way to choose a specific BUS to talk to a device. I mean, even if I develop something specific to the device, I need to know where it is connected to. I think about it in two ways: 1 - Make use of the device driver so it carries the messages for me. 2 - Find the device (in which "slot" its plugged in) and send the message myself. I will do the talking to the device myself, thats for sure. I just need to know how to FIND it!

                        That's what the SDK is for. Or, you can start with this article[^].

                        Fabio Franco wrote:

                        I know I don't talk to the USB, but I know I must use it to talk to the device, messages can't magically find it's way to the device. The USB must have an address I can find and talk through. That's where I'm stuck. How could I cycle through the USB slots on a computer, and send/receive messages through it?

                        Fabio Franco wrote:

                        how the device will understand my commands is not the problem, this I know how to do it already (as I said, done this in LPT1

                        Yeah, but do you know what you're "saying"?? What messages? How are they built? What is the structure for each command?? Without the SDK, you're talking complete gibberish. You're not sending the same messages you send over LPT1. These are Device commands, not escape codes your sending.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                             2006, 2007, 2008
                        But no longer in 2009...

                        F Offline
                        F Offline
                        Fabio Franco
                        wrote on last edited by
                        #11

                        Dave Kreskowiak wrote:

                        Yeah, but do you know what you're "saying"?? What messages? How are they built? What is the structure for each command?? Without the SDK, you're talking complete gibberish. You're not sending the same messages you send over LPT1. These are Device commands, not escape codes your sending.

                        I think you're not understanding what I'm saying. I'm completely aware of what to send the device. The printer understands ZPL Language[^]. In fact it understands it as plain text (8 byte character ASCII text) and it understands commands like *IDN? -> The standard for a device to identify itself, either sending it as plain text or bytecode. So no, I'm not talking gibberish, I'm talking the device's language. For the case of the fingerprint reader, I'll have to understand it's language and the way to communicate (text, byte, etc). But it will work the same way. I've programmed to several devices including, OTDRs through GPIB interface, printers through LPT1 port and other personal projects (my own designed circuit boards) through serial port. The only thing I couldn't do so far is talk to a device through USB. I don't need an SDK. It would make my life easier, but I don't need it. Thanks

                        D 2 Replies Last reply
                        0
                        • F Fabio Franco

                          Dave Kreskowiak wrote:

                          Yeah, but do you know what you're "saying"?? What messages? How are they built? What is the structure for each command?? Without the SDK, you're talking complete gibberish. You're not sending the same messages you send over LPT1. These are Device commands, not escape codes your sending.

                          I think you're not understanding what I'm saying. I'm completely aware of what to send the device. The printer understands ZPL Language[^]. In fact it understands it as plain text (8 byte character ASCII text) and it understands commands like *IDN? -> The standard for a device to identify itself, either sending it as plain text or bytecode. So no, I'm not talking gibberish, I'm talking the device's language. For the case of the fingerprint reader, I'll have to understand it's language and the way to communicate (text, byte, etc). But it will work the same way. I've programmed to several devices including, OTDRs through GPIB interface, printers through LPT1 port and other personal projects (my own designed circuit boards) through serial port. The only thing I couldn't do so far is talk to a device through USB. I don't need an SDK. It would make my life easier, but I don't need it. Thanks

                          D Offline
                          D Offline
                          Dave Kreskowiak
                          wrote on last edited by
                          #12

                          Fabio Franco wrote:

                          I think you're not understanding what I'm saying. I'm completely aware of what to send the device. The printer understands ZPL Language[^]. In fact it understands it as plain text (8 byte character ASCII text) and it understands commands like *IDN? -> The standard for a device to identify itself, either sending it as plain text or bytecode.

                          Trust me, it's the other way around. The language your send to the printer is ZPL. The message format you need to send using DeviceIo is not. It's a carrier of ZPL or whatever other data your sending to the printer. How about this. You're calling a friend oversees and want to have a conversion in Enlgish. You both know English, but do you know how to the sounds of English are transmitted over the wire? What "language" is being used for that? It isn't English...

                          A guide to posting questions on CodeProject[^]
                          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                               2006, 2007, 2008
                          But no longer in 2009...

                          F 1 Reply Last reply
                          0
                          • F Fabio Franco

                            Dave Kreskowiak wrote:

                            Yeah, but do you know what you're "saying"?? What messages? How are they built? What is the structure for each command?? Without the SDK, you're talking complete gibberish. You're not sending the same messages you send over LPT1. These are Device commands, not escape codes your sending.

                            I think you're not understanding what I'm saying. I'm completely aware of what to send the device. The printer understands ZPL Language[^]. In fact it understands it as plain text (8 byte character ASCII text) and it understands commands like *IDN? -> The standard for a device to identify itself, either sending it as plain text or bytecode. So no, I'm not talking gibberish, I'm talking the device's language. For the case of the fingerprint reader, I'll have to understand it's language and the way to communicate (text, byte, etc). But it will work the same way. I've programmed to several devices including, OTDRs through GPIB interface, printers through LPT1 port and other personal projects (my own designed circuit boards) through serial port. The only thing I couldn't do so far is talk to a device through USB. I don't need an SDK. It would make my life easier, but I don't need it. Thanks

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #13

                            Fabio Franco wrote:

                            I don't need an SDK. It would make my life easier, but I don't need it.

                            Good luck...

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                 2006, 2007, 2008
                            But no longer in 2009...

                            F 1 Reply Last reply
                            0
                            • D Dave Kreskowiak

                              Fabio Franco wrote:

                              I think you're not understanding what I'm saying. I'm completely aware of what to send the device. The printer understands ZPL Language[^]. In fact it understands it as plain text (8 byte character ASCII text) and it understands commands like *IDN? -> The standard for a device to identify itself, either sending it as plain text or bytecode.

                              Trust me, it's the other way around. The language your send to the printer is ZPL. The message format you need to send using DeviceIo is not. It's a carrier of ZPL or whatever other data your sending to the printer. How about this. You're calling a friend oversees and want to have a conversion in Enlgish. You both know English, but do you know how to the sounds of English are transmitted over the wire? What "language" is being used for that? It isn't English...

                              A guide to posting questions on CodeProject[^]
                              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                   2006, 2007, 2008
                              But no longer in 2009...

                              F Offline
                              F Offline
                              Fabio Franco
                              wrote on last edited by
                              #14

                              I understand what you say, but beeing this way it's probably the same for all devices using USB. So somebody should've done it already, there should be plenty of COM objects available if the carrier is the same.

                              1 Reply Last reply
                              0
                              • D Dave Kreskowiak

                                Fabio Franco wrote:

                                I don't need an SDK. It would make my life easier, but I don't need it.

                                Good luck...

                                A guide to posting questions on CodeProject[^]
                                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                     2006, 2007, 2008
                                But no longer in 2009...

                                F Offline
                                F Offline
                                Fabio Franco
                                wrote on last edited by
                                #15

                                Thank you, the SDK for the device I don't need really. I just need a boat to carry my letters to my friend in europe

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups