explanation on read method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stephaniee
    New Member
    • Dec 2009
    • 10

    explanation on read method

    Can anyone tell me why serialport.read (combuffer, 0, bytes)?

    whereby

    Code:
     void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
            {
                //retrieve number of bytes in the buffer
                int bytes = comPort.BytesToRead;
                //create a byte array to hold the awaiting data
                byte[] comBuffer = new byte[bytes];
                //read the data and store it
                comPort.Read(comBuffer, 0, bytes);
                //display the data to the user
                DisplayData(MessageType.Incoming, ByteToHex(comBuffer) + "\n");
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Tell you why it.... ?? What?

    The code sample you supplied is well commented. Are you receiving an error?

    Comment

    • stephaniee
      New Member
      • Dec 2009
      • 10

      #3
      comPort.Read(co mBuffer, 0, bytes);

      i dont really understand this type.
      tell me if im wrong..

      combuffer is a byte array and will be stored as bytes. what does '0' mean?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        It probably means start at the 0th element of comBuffer. You should use your IDE to read up on how the API works.

        If you are doing this in VB highlight the API you want to inspect and hit F1.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          If you don't understand something in the framework just go to the MSDN and read about it.


          Holds a complete explanation of the .Read() method and it's overloads.

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            Yea or search MSDN directly, which is what your F1 button does too.

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              I'm a big user of Google with "MSDN {what I am looking for}"
              such as MSDN SerialPort in this case.

              It just seems Google can index the MSDN better than MSDN's own search.

              Comment

              Working...