CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2008
    Posts
    14

    Serial Communication

    Hi guys, I want to know how to use serial communication in VB. I saw a serial port icon in the component section. I want to know the api of the serial port. Hope anyone can teach me or any websites that teach this thx!

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Serial Communication

    Download the 101 Samples for your version of VB.Net
    Code:
        ' This function attempts to open the passed Comm Port. If it is
        '   available, it returns True, else it returns False. To determine
        '   availability a Try-Catch block is used.
        Private Function IsPortAvailable(ByVal ComPort As Integer) As Boolean
            Try
                CommPort.Open(ComPort, 115200, 8, RS232.DataParity.Parity_None, _
                    RS232.DataStopBit.StopBit_1, 4096)
                ' If it makes it to here, then the Comm Port is available.
                CommPort.Close()
                Return True
            Catch
                ' If it gets here, then the attempt to open the Comm Port
                '   was unsuccessful.
                Return False
            End Try
        End Function
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2008
    Posts
    14

    Re: Serial Communication

    what does it mean by download 101 sample? where to download?

  4. #4
    Join Date
    Dec 2008
    Posts
    14

    Re: Serial Communication

    Code:
     SerialPort1.BaudRate = 9600
            SerialPort1.DataBits = 8
            SerialPort1.PortName = "COM1"
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.Open()
    
            SerialPort1.RtsEnable = True
            i = SerialPort1.CtsHolding
    
            Label1.Text = "Successfully Connected!"
            If (SerialPort1.RtsEnable) Then
                SerialPort1.Write("1")
    
                Label3.Text = i
                SerialPort1.WriteLine("1")
            End If
           
            Label2.Text = SerialPort1.WriteBufferSize
    
    
    
    
            'Label2.Text = SerialPort1.ReadByte
    
    
    
            SerialPort1.Close()
    This is what i wrote. Because the VB studio component have serial port, so ?I use it to do the serial communication. Like this correct to open the serial and write to the serial thanks!

  5. #5
    Join Date
    Jan 2009
    Location
    AZ
    Posts
    18

    Re: Serial Communication

    Sure glad you asked this question I been goofing around with doing stuff like this too my question is how do you control the stream using a buffer?

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Serial Communication

    Quote Originally Posted by spiritgate View Post
    what does it mean by download 101 sample? where to download?
    Sample programs to help people understand how VS works.

    http://msdn.microsoft.com/en-us/bb330936.aspx
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Apr 2008
    Posts
    82

    Re: Serial Communication


  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Serial Communication

    Do you have the 2008 version?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Dec 2008
    Posts
    14

    Re: Serial Communication

    ya I have 2008 version, oblio, I tried the program but it still doesnt work

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Serial Communication

    Well, download the samples, and TRY some of them. Take our word for it that every one works.

    Step thru it line by line (pressing F10) to see HOW it works.

    The code that I posted was from the samples, and works.

    It checks the COM ports, and sends AT to each to test for modem.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured