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
  1. Home
  2. General Programming
  3. C#
  4. send byte array to a printer and reading back through a serial port

send byte array to a printer and reading back through a serial port

Scheduled Pinned Locked Moved C#
data-structuressalesperformancehelp
6 Posts 4 Posters 0 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.
  • B Offline
    B Offline
    bttds
    wrote on last edited by
    #1

    I need to print encrypted customer details as a barcode. then need to scan the data and read back the details. My approch is like this, I encrypted the string data using cryptoservices and get memory stream and sen the byte array data as unmanaged byte arra to the printer. Byte[] bytes = memoryStream.GetBuffer(); IntPtr pUnmanagedBytes = new IntPtr(0); int nLength; nLength = Convert.ToInt32(memoryStream.Length); pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength); Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength); PrintDirect.WritePrinter1(lhPrinter, pUnmanagedBytes, nLength, out pcWritten); When I try to read the barcode through a serial port my byte array size is smaller int bytes = comport.BytesToRead; byte[] buffer = new byte[bytes]; comport.Read(buffer, 0, bytes); I've send 184 bytes to the printer. but now my buffer size is 181 can anybody help me

    C 1 Reply Last reply
    0
    • B bttds

      I need to print encrypted customer details as a barcode. then need to scan the data and read back the details. My approch is like this, I encrypted the string data using cryptoservices and get memory stream and sen the byte array data as unmanaged byte arra to the printer. Byte[] bytes = memoryStream.GetBuffer(); IntPtr pUnmanagedBytes = new IntPtr(0); int nLength; nLength = Convert.ToInt32(memoryStream.Length); pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength); Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength); PrintDirect.WritePrinter1(lhPrinter, pUnmanagedBytes, nLength, out pcWritten); When I try to read the barcode through a serial port my byte array size is smaller int bytes = comport.BytesToRead; byte[] buffer = new byte[bytes]; comport.Read(buffer, 0, bytes); I've send 184 bytes to the printer. but now my buffer size is 181 can anybody help me

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I'm still trying to work out what you're using, that you can send bytes to a piece of paper, and get them back. Your interface is the key question here, and as I've told you, no-one can answer you without knowing what you're using. Are the 181 bytes the first 181 bytes that you wrote out ?

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      P B 2 Replies Last reply
      0
      • C Christian Graus

        I'm still trying to work out what you're using, that you can send bytes to a piece of paper, and get them back. Your interface is the key question here, and as I've told you, no-one can answer you without knowing what you're using. Are the 181 bytes the first 181 bytes that you wrote out ?

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Chris - Drop me a line. I've got Dimension Hatross.

        Deja View - the feeling that you've seen this post before.

        1 Reply Last reply
        0
        • C Christian Graus

          I'm still trying to work out what you're using, that you can send bytes to a piece of paper, and get them back. Your interface is the key question here, and as I've told you, no-one can answer you without knowing what you're using. Are the 181 bytes the first 181 bytes that you wrote out ?

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          B Offline
          B Offline
          bttds
          wrote on last edited by
          #4

          I'm using a windows application (c#.net 2005). My byte array values are like this, 164, 243, 37, 108, ... valeus in returned array are almost same order. but values 10 and 13 in original array are moved to the end. but still mising 3 bytes. when I try with different initial string sometimes i get the exact number of bytes, but still values 10 and 13 in original array are moved to the end. so the decrypted string is different than original string for that one also. eg. original - "1000172;1;PUAY KEE;ANBRTYUIJh JGFT;10041946;SG;M;S1254743J;SG;11091988;11092010;SG" result - "1000172;1;PUAY K|jj[8�C\b@\"|�2��DS�@\af#�ݧ`-�6�?�T����'k�\akE�;�W��A��1\b�+�`l�E���r"

          G 1 Reply Last reply
          0
          • B bttds

            I'm using a windows application (c#.net 2005). My byte array values are like this, 164, 243, 37, 108, ... valeus in returned array are almost same order. but values 10 and 13 in original array are moved to the end. but still mising 3 bytes. when I try with different initial string sometimes i get the exact number of bytes, but still values 10 and 13 in original array are moved to the end. so the decrypted string is different than original string for that one also. eg. original - "1000172;1;PUAY KEE;ANBRTYUIJh JGFT;10041946;SG;M;S1254743J;SG;11091988;11092010;SG" result - "1000172;1;PUAY K|jj[8�C\b@\"|�2��DS�@\af#�ݧ`-�6�?�T����'k�\akE�;�W��A��1\b�+�`l�E���r"

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            The values 13 and 10 are carriage return and line feed, which are used to make a line break in text. This suggests that the printer treats the data as text, not binary values, otherwise those values should not have any special meaning at all. Therefore you can not send binary data to the printer and expect to get it back unchanged. Why don't you just say what equiment you are using? Any help you get here is directly related to the information you give, so if you only share a minimal amount of information, you can only get a minimal amount of help.

            --- single minded; short sighted; long gone;

            B 1 Reply Last reply
            0
            • G Guffa

              The values 13 and 10 are carriage return and line feed, which are used to make a line break in text. This suggests that the printer treats the data as text, not binary values, otherwise those values should not have any special meaning at all. Therefore you can not send binary data to the printer and expect to get it back unchanged. Why don't you just say what equiment you are using? Any help you get here is directly related to the information you give, so if you only share a minimal amount of information, you can only get a minimal amount of help.

              --- single minded; short sighted; long gone;

              B Offline
              B Offline
              bttds
              wrote on last edited by
              #6

              I'm using a "metrologic" scaning device to scan and "SATO" printer to printing. I don't think my problem is related to the device. My barcode is a 2D barcode. When I pass the data as string everything works fine there, when I scan the data I removed those linefeeds and carriage returns. But with the array with the way I'm reading it cant remove those linefeeds and ciarrage returns.

              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