none
serial port example code RRS feed

Answers

  • That code dates from before the serial port component became available in .Net.  It is not practical to convert old code - it is simpler to start from scratch.  You can use the modem manipulation part of the code, but ignore the serial port sending and receving.

    There is an example of simple serial port receiving here:
    http://www.vbdotnet.com.nu/simple_data_receiving.html

    There is an example of sending commands to a modem here:
    http://msdn.microsoft.com/en-us/library/7x7cdt5c.aspx

     

    Wednesday, October 26, 2011 11:36 AM
  • You can download the EnhancedSerialPort code from my website.  It illustrates the enhancement wrapper for the built-in SerialPort control in the toolbox.  You can either use the enhanced serial port control in the download, which is free, or simply substitute the control that is part of Visual Studio.   You also can download the tutorial from http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm  or you might want to get a copy of my book (see below).

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    Wednesday, October 26, 2011 5:20 PM

All replies

  • That code dates from before the serial port component became available in .Net.  It is not practical to convert old code - it is simpler to start from scratch.  You can use the modem manipulation part of the code, but ignore the serial port sending and receving.

    There is an example of simple serial port receiving here:
    http://www.vbdotnet.com.nu/simple_data_receiving.html

    There is an example of sending commands to a modem here:
    http://msdn.microsoft.com/en-us/library/7x7cdt5c.aspx

     

    Wednesday, October 26, 2011 11:36 AM
  • That code dates from before the serial port component became available in .Net.  It is not practical to convert old code - it is simpler to start from scratch.  You can use the modem manipulation part of the code, but ignore the serial port sending and receving.

    There is an example of simple serial port receiving here:
    http://www.vbdotnet.com.nu/simple_data_receiving.html

    There is an example of sending commands to a modem here:
    http://msdn.microsoft.com/en-us/library/7x7cdt5c.aspx

     


    so, i replace the code in the old code with the new code you provided and it will be ok??

     

    I assume I remove the unused code in the old code that is causing the issue??

    Wednesday, October 26, 2011 11:45 AM
  • That code dates from before the serial port component became available in .Net.  It is not practical to convert old code - it is simpler to start from scratch.  You can use the modem manipulation part of the code, but ignore the serial port sending and receving.

    There is an example of simple serial port receiving here:
    http://www.vbdotnet.com.nu/simple_data_receiving.html

    There is an example of sending commands to a modem here:
    http://msdn.microsoft.com/en-us/library/7x7cdt5c.aspx

     


    there is nothing there on how to close the port once it is opened.

     

    Wednesday, October 26, 2011 12:08 PM
  • That code dates from before the serial port component became available in .Net.  It is not practical to convert old code - it is simpler to start from scratch.  You can use the modem manipulation part of the code, but ignore the serial port sending and receving.

    There is an example of simple serial port receiving here:
    http://www.vbdotnet.com.nu/simple_data_receiving.html

    There is an example of sending commands to a modem here:
    http://msdn.microsoft.com/en-us/library/7x7cdt5c.aspx

     


    so, i replace the code in the old code with the new code you provided and it will be ok??

     

    I assume I remove the unused code in the old code that is causing the issue??


    is there example code elsewhere that is ready to use? it appears to be more to it than just

    changing the code you suggested.

     

     

     


    • Edited by RonR399 Wednesday, October 26, 2011 12:25 PM spelling
    Wednesday, October 26, 2011 12:24 PM
  • You can download the EnhancedSerialPort code from my website.  It illustrates the enhancement wrapper for the built-in SerialPort control in the toolbox.  You can either use the enhanced serial port control in the download, which is free, or simply substitute the control that is part of Visual Studio.   You also can download the tutorial from http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm  or you might want to get a copy of my book (see below).

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    Wednesday, October 26, 2011 5:20 PM
  • Hello,

    here is a code (german site) ready to use:

    9. Wie führt man Serial-COM Portkommunikation ein ?

    Very powerful basic sample using datareceived event.

    regards Ellen


    Ich benutze/ I'm using VB2008 & VB2010
    Wednesday, October 26, 2011 7:02 PM
  • so, i replace the code in the old code with the new code you provided and it will be ok??

     I assume I remove the unused code in the old code that is causing the issue??

    You can't do that.

    Use the examples provided to understand how the serial port component works and how it is typically used.  Then design your applciation around your specific reqwuirements, using the code from the examples for those parts of the application where it is relelevant, adapting it as required to allow for the differences in your design.

    Wednesday, October 26, 2011 8:52 PM
  • there is nothing there on how to close the port once it is opened.

     

    You may have accidentally overlooked this part of the example provided at the first link in my response:

    Finally, for safety, add a second button (btnStop) that will close the serial port and stop the timer before the form is closed.

    Private Sub btnStop_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnStop.Click
      SerialPort1.Close()
      Timer1.Stop
    End Sub


    • Edited by Acamar Wednesday, October 26, 2011 8:54 PM
    Wednesday, October 26, 2011 8:54 PM