That, SerialPort stuff

The log files reveal that a lot of people are looking for help using the Serialport component of the .Net Framework. Once again, lets summarize:

  • There are two ways to access data from a serialport:
    1. Using the DataReceived event (non-blocking)
    2. Using (individual) ReadLine statements in your code (blocking)
    For a more detailed description, I mentioned the difference in a different posting. Which method you’re going to use depends on how or when data becomes available to you and where you want that data to appear in your application. If your GUI needs to be updated frequently, use non-blocking. Note that you can mix ReadLine statements in your DataReceived events, but most likely you will need to clear your serial port buffers before closing off the program.
  • Know the difference between the various way of reading data (Read, ReadLine and ReadExisting). Experiment with them.
  • If you need to read a certain amount of bytes, check into the BytesToRead property.
  • If you’re going to use blocking methods, make sure to adjust both read and write timeouts appropriately.
This entry was posted in Programming and tagged , . Bookmark the permalink.