Serial port control

I want to be able to send and recieve data from a microcontroller to VB 2005 express. Does anyone have any suggestions on how to setup a comm port and link code from say a button Thanks

Answer this question

Serial port control

  • rbreidenstein

    As the functions that you are asking are not just for express... I would have a look at the other forums on this site and do a search. You might want to focus the search on the networking and communications groups, and the language specific groups.



  • GregCrossan

    Hey

    I have some code that might help you connect your micro to VB. I use the Basic Stamp2 to prototype with but the code for the VB program and how to setup the comm port might be usefull. My email adress is bennettdan@bellsouth.net email me and i will help you with what I know.


  • grover2

    I use an 8-bit Atmel AVR microcontroller to run a data acquisition system and the following code works for me. In my case, I only need to send a single byte to the microcontroller to get it to perform all the functions and I receive 512 bytes of data in return but sending a string shouldn't be much different.

    I use a timer to trigger the communications and I receive the return data with the DataReceivedHandler Sub triggered by the DataReceived event.

    Imports System.IO

    Public Event DataReceived As IO.Ports.SerialDataReceivedEventHandler

    AddHandler SerialPort1.DataReceived, AddressOf DataReceivedHandler

    [ Dim the MicroCommand and InputBuffer variables to your liking and of course, open the port ]

    SerialPort1.Open()

    [ I use the timer to trigger the following code and catch exceptions but you could also trigger this with a button ]

    If SerialPort1.IsOpen Then

    Try

    SerialPort1.Write(MicroCommand)

    Catch ex As InvalidOperationException

    [or whatever exceptions you choose to address]

    End Try

    End If

    [ Then, I use the following code to receive the incoming data and catch exceptions. ]

    Private Sub DataReceivedHandler(ByVal sender As Object, ByVal e As Ports.SerialDataReceivedEventArgs)

    Try

    InputBuffer += SerialPort1.ReadExisting

    Catch ex As InvalidOperationException

    [or whatever exceptions you choose to address]

    End Try

    End Sub

    Of course, you'd need to work out the code you'd need to handle any specific exceptions..


  • wishkah353

    I'm also having a problem reading from the serial port with a microcontroller. I have no problem opening the port it's just recieving data from it.I have seached all the forums and I have had no luck. I am new to VB2005, would C# be a better solution for recieving data from serial port

    thanks,

    tom


  • SSISNewUser

    Hey

    I have some code that might help you connect your micro to VB. I use the Basic Stamp2 to prototype with but the code for the VB program and how to setup the comm port might be usefull. My email adress is bennettdan2bellsouth.net email me and i will help you with what I know.


  • Serial port control